I am using nrf51822, sdk version 11.0, sofdevice 130, i2c initialized in non-blocking mode. The read seems ok. The write is problematic for me.
I am using nrf51822, sdk version 11.0, sofdevice 130, i2c initialized in non-blocking mode. The read seems ok. The write is problematic for me.
I think Jorgen points to the best answer. For completeness below are some helper functions I have used to do write/read operations for the nrf twi interface.
//write byte to register
void write_byte(const nrf_drv_twi_t *twi_handle, uint8_t address, uint8_t sub_address, uint8_t *data, bool stop)
{
ret_code_t err_code;
uint8_t data_write[2];
data_write[0] = sub_address;
data_write[1] = *data;
err_code = nrf_drv_twi_tx(twi_handle, address, data_write, sizeof(data_write), stop);
APP_ERROR_CHECK(err_code);
}
//reading byte or bytes from register
void write_forread_byte(const nrf_drv_twi_t *twi_handle, uint8_t address, uint8_t sub_address)
{
ret_code_t err_code;
err_code = nrf_drv_twi_tx(twi_handle, address, &sub_address, sizeof(sub_address), true);
APP_ERROR_CHECK(err_code);
}
char read_byte(const nrf_drv_twi_t *twi_handle, uint8_t address, uint8_t sub_address)
{
ret_code_t err_code;
uint8_t data; // `data` will store the register data
write_forread_byte(twi_handle, address, sub_address);
err_code = nrf_drv_twi_rx(twi_handle, address, &data, sizeof(data));
APP_ERROR_CHECK(err_code);
return data;
}
void read_bytes(const nrf_drv_twi_t *twi_handle, uint8_t address, uint8_t sub_address, uint8_t * dest, uint8_t dest_count)
{
ret_code_t err_code;
write_forread_byte(twi_handle, address, sub_address);
err_code = nrf_drv_twi_rx(twi_handle, address, dest, dest_count);
APP_ERROR_CHECK(err_code);
}
Hello Josh ! The error_code was NRF_SUCCESS so it made me wonder a little bit. I made it work ! :D The problem was that I didn't wake the MPU6050 up. Thank you very much for your help, Josh ! You saved me a lot of hours :)
Hello Josh ! The error_code was NRF_SUCCESS so it made me wonder a little bit. I made it work ! :D The problem was that I didn't wake the MPU6050 up. Thank you very much for your help, Josh ! You saved me a lot of hours :)