Hi everyone,
I try to write using I2C but I fail and I cannot figure out the issue
This is my code snippet.
uint8_t my_data[2];
my_data[0] = 0x00;
my_data[0] = 0x01;
rslt = reg_write(reg_addr, my_data, 2, dev);
--------------------------------------------------------------------------------------------
uint8_t reg_write(uint8_t reg_addr, uint8_t *data, uint16_t len, struct BQ27421_dev *dev) {
/*Call the I2C write function*/
dev->write(dev->chip_id, reg_addr, data, len);
}
//write() is a function pointer to Acc_i2c_Write()
--------------------------------------------------------------------------------------------
int8_t Acc_i2c_Write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len) {
int8_t rslt = 0;
uint8_t data[len + 1];
data[0] = reg_addr;
for (uint16_t i = 0; i < len; i++) {
data[i + 1] = reg_data[i];
}
rslt = nrf_drv_twi_tx(&m_twi, dev_id, data, len + 1, false);
APP_ERROR_CHECK(rslt);
return rslt;
}
When I run it it returns the following error
00> <error> app: ERROR 2 [NRF_ERROR_SOFTDEVICE_NOT_ENABLED] at C:\Users\n.antoniou\Dropbox\IoT\Nordic\nRF52840\nRF5_SDK_16.0.0\Ingenious\BLE_Peripheral\BLE_IMU_v4\main.c:484 00> PC at: 0x00034529 00> <error> app: End of error report
It fails inside the nrf_drv_twi_tx() function.. When I set the len parameter to one then it runs normally but I want to write two bytes..
Any ideas?