Hi !
I am working with nRF52 DK to drive the nRF52832 and a sensor of Maxim Integrated.
I am using an older version of the SDK (14.2.0) because i need to modify an old project, so if possible i don't want to use the nrfx module of the newer version in order to do not integration.
My I2C communication is described as follow:

I am using the following read and write function.
I have already discuss these function in this post,where the suggestion was to use the new module nrfx. It is possible implement these function also with the Legacy?
I need to define a I2C communication as a TX of Family Byte,Index and (eventually) Write Byte and a RX of the Status (writing) or Response (reading) Byte. it is a modification of an arduino function that need to return the Status and Response byte depending on the case.
uint32_t nrf_drv_oxi_init(void)
{
uint32_t err_code;
const nrf_drv_twi_config_t twi_oxi_config = {
.scl = OXI_TWI_SCL_PIN,
.sda = OXI_TWI_SDA_PIN,
.frequency = NRF_TWI_FREQ_400K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGHEST,
.clear_bus_init = false
};
err_code = nrf_drv_twi_init(&m_twi_instance, &twi_oxi_config, nrf_drv_oxi_twi_event_handler, NULL);
if (err_code != NRF_SUCCESS)
{
return err_code;
}
nrf_drv_twi_enable(&m_twi_instance);
return NRF_SUCCESS;
}
uint8_t readByte(uint8_t familyByte, uint8_t indexByte, uint8_t writeByte)
{
uint32_t err_code;
uint8_t StatusByte;
uint8_t ReturnByte;
uint8_t rx_buffer[2];
size_t rx_lenght =2;
uint8_t tx_buffer[] = {familyByte, indexByte, writeByte};
size_t tx_lenght = sizeof(familyByte) + sizeof(indexByte) + sizeof(writeByte);
err_code = nrf_drv_twi_tx(&m_twi_instance, address, tx_buffer, tx_lenght, true);
APP_ERROR_CHECK(err_code);
nrf_delay_ms(6);
err_code = nrf_drv_twi_rx(&m_twi_instance, address, rx_buffer, rx_lenght);
APP_ERROR_CHECK(err_code);
StatusByte = rx_buffer[0];
NRF_LOG_INFO("Status Byte: %lu \n",StatusByte); //0x00 for SUCCESS
ReturnByte = rx_buffer[1];
return ReturnByte;
}
uint8_t writeByte( uint8_t familyByte, uint8_t indexByte, uint8_t writeByte)
{
uint32_t err_code;
uint8_t StatusByte;
uint8_t rx_buffer[1];
size_t rx_lenght =1;
uint8_t tx_buffer[] = {familyByte, indexByte, writeByte};
size_t tx_lenght = sizeof(familyByte) + sizeof(indexByte) + sizeof(writeByte);
err_code = nrf_drv_twi_tx(&m_twi_instance, address, tx_buffer, tx_lenght, true);
APP_ERROR_CHECK(err_code);
nrf_delay_ms(6);
err_code = nrf_drv_twi_rx(&m_twi_instance, address, rx_buffer, rx_lenght);
APP_ERROR_CHECK(err_code);
StatusByte = rx_buffer[0];
return StatusByte;
}
And i have this error both in reading and writing from the second time i use one of this function, so the first READ/WRITE seems to work correctly.

In my nrf_error.h file this error is described as:

Do you have any suggestion about what can cause this error?
Thanks in advance for the time spent on my issue.
polimarte

