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

continuous data about example twi_master_using_app_twi

hello. I want use I2C program. so, I used twi_master_using_app_twi example. SDA is output only 1byte(0x21). I need to output a continuous 5byte. Where do I need to modify the part. thank you.

Parents
  • You have a function to send data. Second parameter in this function is 0x40 (it is address of my sensor). Third parameter is a pointer to data array which you want to send, fourth parameter is the length in bytes how much bytes you want to send.

    ret_code = nrf_drv_twi_tx(&p_twi_instance, 0x40, &dr, 1, false);
    APP_ERROR_CHECK(ret_code); // Check for errors in return value
    

    So to send 5 data bytes to the sensor, you cand have something like this

    #define DATA_ARRAY_LEN 5
    uint8_t data[DATA_ARRAY_LEN] = {0x22, 0x33, 0xFF, 0x10, 0x3A};
    uint8_t dev_address = 0x40;
    

    Then in the main program

    int main(void)
    {
      // ..... 
          ret_code = nrf_drv_twi_tx(&p_twi_instance, dev_address, data, DATA_ARRAY_LEN, false);
          APP_ERROR_CHECK(ret_code); // Check for errors in return value
    }
    

    Not sure this will compile because it is blind written, but you should get the idea.

Reply Children
No Data
Related