How do you do i2c multiple byte read and multiple byte write using nrf_drv_twi ? Is it possible to help me with some code ? I am using s130 sdk 11.
How do you do i2c multiple byte read and multiple byte write using nrf_drv_twi ? Is it possible to help me with some code ? I am using s130 sdk 11.
Maybe something like this:
static void read_data(void)
{
nrf_drv_twi_config_t twi_config;
twi_config.sda = ARDUINO_SDA_PIN;
twi_config.scl = ARDUINO_SCL_PIN;
twi_config.frequency = NRF_TWI_FREQ_100K;
twi_config.interrupt_priority = APP_IRQ_PRIORITY_HIGH;
nrf_drv_twi_init(&twi_instance, &twi_config, NULL, NULL);
nrf_drv_twi_enable(&twi_instance);
//SEND COMMAND
uint8_t command[] = {0x24, 0x25};
nrf_drv_twi_tx(
&twi_instance,
0x20, //ADDRESS
command,
sizeof(command),
true
);
uint8_t some_data[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
nrf_drv_twi_rx(
&twi_instance,
0x20, //ADDRESS
some_data,
sizeof(some_data)
);
//Do something with some_data
nrf_drv_twi_disable(&twi_instance);
}
P.S. Im newbie in microcontroller programming(working around week with them) so maybe in code are some mistakes which can produce overflow or something similar...
If my answer fix your problem please accept it as solution/answer...
Hi, I also have similar confusion about Multi byte I2C write. It seems that TWI_HANDLER is triggered once only means only 1 byte (register address) is transferred and the actual register value which is the 2nd byte is not transferred.
Your help will be appreciated. Thanks
If you are using the TWI master driver (nrf_drv_twi), the available events that is passed to the TWI event handler is described here. NRF_DRV_TWI_EVT_DONE
event will be passed to the event handler when the entire transfer is completed, not for each byte transmitted/received. The legacy TWI (non-EasyDMA) peripheral can generate events for each byte transmitted/received (EVENTS_TXDSENT/EVENTS_RXDREADY), but this is not supported in the driver.