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

Receiving 16 bits from TWI

Hello,

I'm trying to receive a 2-byte data from a sensor from Maxim Integrated MAX31875 but the nrf_drv_twi_rx function only receive 8 bits data. Does this function to receive a 16 bits data exists or how can I change this function to receive a 16 bits data ? 

Parents Reply
  • Hello, I actually used type uint8_t to avoid confusion, this will specify the length of the variable to one byte exactly. Your variable should be an array of size 2.

    uint8_t rx_buffer[2];
    
    nrfx_twi_rx(&adc_twi,ADC_ADDR,&rx_buffer[0],sizeof(rx_buffer));

    Hence, once read, your data will be stored like this :

    rx_buffer[0] = first byte of data

    rx_buffer[1] = second byte of data

    Then you should be able to concatenate both 8 bits data into one 16 bits data like so :

    uint16_t complete_data = ((uint16_t)rx_bufer[0] << 8) | rx_buffer[1];

    I hope this better explains how I did it.

Children
Related