STS30 temperature sensor I2C code

I am trying to read temperature value from STS30 temperature sensor using this simple code snippet: 

During debugging, my debugger stuck at line "if (STS30_read_temp(temperature)==true)". When I step into this line, I can see debugger is stuck at line "return result" of function "nrf_drv_twi_tx" in nrf_drv_twi.h file. 

Can you check the code and advise what am I doing wrong here. 

I have attached the command sequence for reading temperature from STS30 sensor. 

  

Thanks

Parents
  • Hello,

    Please make sure to check the error code returned by nrf_drv_twi_rx - if you do not check the error code you will not have any way of knowing if the function call unexpectedly failed, and so you will be stuck in the while loop forever waiting for the transfer to complete, without the transfer ever having started.

    Please also make sure to have DEBUG defined in your preprocessor defines, like shown in the included image:

    This will make your logger output a detailed error message whenever a non-NRF_SUCCESS error code is passed to an APP_ERROR_CHECK.
    Use this error message to find the function that returned the error code, and look at the function's API reference to see why it returned this particular error code.

    Best regards,
    Karl

  • Thank you. I added DEBUG to the preprocessor definitions. It seems like the code is stuck in the while loop. I dont see an error code anywhere. Please see attachments are screenshot 1 just before getting stuck and screenshot 2 where debugger stuck in while loop. 

    To me it seems like nrf_drv_twi_tx does the job, but instead of sending Address/w/Ack/0x2C/Ack/0x10/Ack/Stop, it is just sending Address/w/Ack/0x2C/Ack/Stop and that is why STS30 sensor never send a response on the bus. 

    Is this code below sending the Address/w/Ack/0x2C/Ack/0x10/Ack/Stop sequence as sensor expects? 

    tx_buf[0] = 0x2C;
    tx_buf[1] = 0x10;

    err_code = nrf_drv_twi_tx(&m_twi, STS30_Address, tx_buf, 2, false);

Reply
  • Thank you. I added DEBUG to the preprocessor definitions. It seems like the code is stuck in the while loop. I dont see an error code anywhere. Please see attachments are screenshot 1 just before getting stuck and screenshot 2 where debugger stuck in while loop. 

    To me it seems like nrf_drv_twi_tx does the job, but instead of sending Address/w/Ack/0x2C/Ack/0x10/Ack/Stop, it is just sending Address/w/Ack/0x2C/Ack/Stop and that is why STS30 sensor never send a response on the bus. 

    Is this code below sending the Address/w/Ack/0x2C/Ack/0x10/Ack/Stop sequence as sensor expects? 

    tx_buf[0] = 0x2C;
    tx_buf[1] = 0x10;

    err_code = nrf_drv_twi_tx(&m_twi, STS30_Address, tx_buf, 2, false);

Children
Related