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);

  • Hello again,

    Kaveh.M said:
    I added DEBUG to the preprocessor definitions.

    Thank you for updating me. Could you also confirm that you added the APP_ERROR_CHECK wherever it is appropriate, such as following line 88 in the code you originally posted?
    If you did so, did you ever see anything different output to your log, or did you observe that your device reset at any time during the program?

    Best regards,
    Karl

  • I added APP_ERROR_CHECK() after nrf_drv_twi_tx() and placed breakpoint about it. Please see the results and let me know what could be wrong here. 

  • You do not need to set a breakpoint - if it fails the APP_ERROR_CHECK the debug session will halt the CPU before the reset.
    What does your logger output when this happens?

    Best regards,
    Karl

Reply Children
Related