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

TWI incorrectly sends data

Hi

I am currently trying to connect the sht31 temperature / humidity sensor. First, I made an implementation based on the twi_sensor example. I did it all, the temperature and humidity read correctly.

When I decided to use the resulting code in my main program, where bluetooth transmission was implemented, I started having problems. When transmitting commands to the sensor (address, msb, lsb), the lsb command is not transmitted correctly, instead of the pledged command 0x06, it transmits a completely different value.
This situation occurs in the following cases:
1) if you call the nrf_drv_twi_tx function in a while (1) loop in the main function and the idle_state_handle function is also called there. If you comment out the idle_state_handle, then the commands normally transmit and read the values ​​of humidity and temperature.
2) if you call the function nrf_drv_twi_tx in a timer interrupt.

I assume there is a conflict causing one interruption in another? or some other reason?

correct transmission of commands (Address = 0x44 (offset right), MSB = 0x2C, LSB = 0x06)

LSB incorrect send

Chip: SKB501 (analog nRF52840);

SDK: nRF5_SDK_15.2.0;

Softdevice: s132_nrf52_6.1.0_softdevice;

Thanks in advance for your help.

Parents Reply
  • Hello, 

    The issue seems to be with the function sht3x_set_mode()

    When initializing this function, all variables are pushed to the stack. However, nrf_drv_twi_tx() pushes data to the DMA and a pointer to the stack address. When the whole function is done, the data will be popped from the stack and the DMA will have an issue trying to find the data in the stack.

    This is why you should declare your array uint8_t reg[2] as static instead, to ensure the correct address. Try something similar to this:

      static uint8_t reg[2];
      reg[0] = MSB;
      reg[1] = LSB;

    Let me know how that works for you!

    Kind regards,
    Øyvind

Children
Related