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

  • Thanks Karl. I modified the code as you mentioned and added twi_handler to the nrf_drv_twi_init. Now I can see the while loops are passed properly in the STS30_read_command() and STS30_write_command() by the debugger and temperature is measured properly. Please see below is the modified code: 

    The only remaining issue is that the temperature is now measured properly 1 time. As you can see in the code, there is a while(true) and nrf_delay_ms(1000) in the main function, that repeats this measurement every 1 second. The first time debugger enters the loop, it executes STS30_detect() fine and STS30_read_temp(temperature) fine with correct measurement. But after 1s in the second round of measurement, it it executes STS30_detect() fine and sets (STS30_detected = true) but then during execution of STS30_read_temp(temperature) debugger transition to line 100 in app_error_weak.c snd stuck there. Please see below.

  • I am happy to hear that the suggested change resolved your initial issue!

    Kaveh.M said:
    The first time debugger enters the loop, it executes STS30_detect() fine and STS30_read_temp(temperature) fine with correct measurement. But after 1s in the second round of measurement, it it executes STS30_detect() fine and sets (STS30_detected = true) but then during execution of STS30_read_temp(temperature) debugger transition to line 100 in app_error_weak.c snd stuck there. Please see below.

    What does your logger output when this happens? Could you confirm that you have DEBUG defined in your preprocessor defines, like I mentioned in my initial comment?

    Best regards,
    Karl

  • Yes, DEBUG is defined in the preprocessor defines as before. 

    How can I see the logger output? I have only have JLINK connected to my board. 

  • Thank you for confirming this.

    Are you working with a custom board, and an external JLink debugger? Which backend are you using for the logger?
    You can check this in the sdk_config.h file in the nrf logger's backend configuration option.
    If you are using the RTT backend you will need to use an RTT terminal, such as Seggers RTT Viewer application or the Segger Embedded Studios debug terminal.

    Best regards,
    Karl

  • Yes I am working with a custom board, and an external JLink debugger.

    I set NRF_LOG_BACKEND_RTT_ENABLED to 1 in sdk_config.h file. A new window called "Debug Terminal" is opened now. And after the debugger transition to line 100 in app_error_weak.c and stuck there this message appears.

    <info> app: Successfully detected STS30 at address: 0x4A
    <error> app: ERROR 17 [NRF_ERROR_BUSY] at C:\nRF5_SDK_17.0.2_d674dde\examples\My Projects\twi_SHT30_Read_1\main.c:121
    PC at: 0x00005CC5
    <error> app: End of error report

Related