This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SPI Consumption problem

I'm testing SPIM of nRF52 on PCA10040 using S132 and SDK11.

Its base on the app_peripheral_uart example, so I already have BLE communication.

When SPI is not initiated, current consuption is arround 370 uA, but when adding SPI it goes to 800uA. no matters if its transmitting or not, and theres is no way to came back to previous consuption.

I've been working hard to find a cause, but I really dont see why this is happening. I've debugged and checked SPI is coreclty stopped after TX/RX ends. I'm already using NRF52_PAN_23 define. I've even add uninit function after TX/RX ends, but its still the same.

This is the code I made to handle SPI, based on SPI example from SDK: ( acc_handler() function is called every 3 seconds from a timer based function)

define SPI_INSTANCE  0 

static const nrf_drv_spi_t spi = NRF_DRV_SPI_INSTANCE(SPI_INSTANCE);

static volatile uint8_t spi_xfer_done; 


void spi_event_handler(nrf_drv_spi_evt_t const * p_event)

{

    spi_xfer_done = 1;
    nrf_spim_event_clear(spi.p_registers, NRF_SPIM_EVENT_END);
    nrf_spim_event_clear(spi.p_registers, NRF_SPIM_EVENT_STARTED);
    nrf_drv_spi_uninit(&spi);
}

void init_spi(void)

{

    nrf_drv_spi_config_t spi_config = NRF_DRV_SPI_DEFAULT_CONFIG(SPI_INSTANCE);
    spi_config.mosi_pin = 25;
    spi_config.miso_pin = 24,//26;
    spi_config.sck_pin = 23,//20;
    spi_config.ss_pin = NRF_DRV_SPI_PIN_NOT_USED;//SPI_CS_PIN;
    spi_config.frequency = NRF_DRV_SPI_FREQ_500K;
    APP_ERROR_CHECK(nrf_drv_spi_init(&spi, &spi_config, spi_event_handler));
    spi_xfer_done   = 1;
}

uint8_t send_spi(uint8_t *txdata, uint8_t *rxdata, uint8_t len)

{

    if(!spi_xfer_done)
      return(1);
    
    spi_xfer_done   = 0;
    APP_ERROR_CHECK(nrf_drv_spi_transfer(&spi, txdata, len, rxdata, len));

    return(0);
}

void acc_handler(void)

{

uint16_t tx, rx;

  tx = 0x55AA;

  init_spi();

  send_spi((uint8_t *)&tx, (uint8_t *)&rx, 2);

}

Is there anything wrong ? Did I miss anything ?

Thanks in advance.

Related