Hallo,
I request for your time and effort to solve the issue that I am facing at the moment. Any suggestions and solutions are highly appreciated.
Hardware: NRF52840DK , SPI sensor (MAX86141)
SDK: 17.02
SoftDevice : S140
I have successfully written code to communicate with one of the SPI sensor (MAX86141) that I have with me using nrfx_spim driver. I am using SPIM instance 3. Please find the details below:
Driver: NRFX_SPIM
Instance: 3
Priority: 6
SPI PINS: CS-> 31 , MOSI-> 29 , MISO-> 30 , SCLK-> 28
I can properly read and write to the sensor without any issues.
But now when I tried to add the BLE functionality to the project, I faces problem. I started with the ble_app_template program and then added my spi files for the sensor. I have also enabled NRFX_SPIM_ENABLE and NRFX_SPIM3_ENABLED in the SDK_config file. After adding all related headers and files, the program compile successfully.
Here is my main function,
int main(void)
{
uint8_t value;
log_init();
timers_init();
NRF_LOG_INFO("Timer initialized \n");
MAX86141_init();
power_management_init();
BleInit();
NRF_LOG_INFO("Template example started.");
application_timers_start();
MAX86141_reg_read(REG_PART_ID, &value);
NRF_LOG_INFO("Part ID &d \n",value);
for (;;)
{
idle_state_handle();
}
}
When I run the program, the application get stuck in the while loop inside the read function as shown in the screenshot below.
MAX86141_reg_read function:
void MAX86141_reg_read (uint8_t addr, uint8_t *data_out)
{
memset(m_tx_buf, 0, 3);
m_tx_buf[0] = addr;
m_tx_buf[1] = READ;
m_tx_buf[2] = 0x00;
memset(m_rx_buf, 0, 3);
spi_transfer_done = false;
//APP_ERROR_CHECK(nrfx_spim_transfer(&spi, m_tx_buf, 3, m_rx_buf, 3));
nrfx_spim_xfer_desc_t xfer_desc2 = NRFX_SPIM_XFER_TRX(m_tx_buf, 3, m_rx_buf, 3);
APP_ERROR_CHECK( nrfx_spim_xfer(&spi, &xfer_desc2,0));
while(spi_transfer_done == false){};
*data_out = m_rx_buf[2];
//NRF_LOG_INFO("Inside the read function. Value is :%d", m_rx_buf[2] );
}
As you can see from the debug information, the sensor is not responding. But when I use the same code without BLE, the sensor works fine.
Are there any configuration that I am missing out? I would really appreciate your help.
Update:
I checked with a scope. There are no activity in the spi lines. No clock, cs, miso and mosi. So i guess the driver is not working.
Thank you for your time.
best regards