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...
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...