Hi, i am using:
-nRF 52 DK
-nRF 52832
-Sensor of Maxim Integrated
-SDK 17.0.2
I have some problems in handling the I2C through the nrfx module.
My I2C communication with the sensor is defined as a TX/RX.
I am using slightly different Read/Write function than the one used in the NRFX examples because i need some non-void function.
Here is my initialization,handler and read byte function:
static const nrfx_twim_t twim_instance = NRFX_TWIM_INSTANCE(0);
volatile bool twim_tx_done = false;
volatile bool twim_rx_done = false;
void twim_handler(nrfx_twim_evt_t const * p_event, void * p_context)
{
size_t primaryBufferSize = p_event->xfer_desc.primary_length;
uint8_t *bytesTransferred = p_event->xfer_desc.p_primary_buf;
size_t secondaryBufferSize = p_event->xfer_desc.secondary_length;
uint8_t *bytesRead = p_event->xfer_desc.p_secondary_buf;
switch (p_event->type)
{
case NRFX_TWIM_EVT_DONE:
NRF_LOG_INFO("STATE OF BUFFERS IN EVENT HANDLER:");
NRF_LOG_INFO("\t Size of primary buffer: %d", primaryBufferSize);
NRF_LOG_INFO("\t Size of secondary buffer: %d", secondaryBufferSize);
if (p_event->xfer_desc.type == NRFX_TWIM_XFER_TX)
{
twim_tx_done = true;
}
if (p_event->xfer_desc.type == NRFX_TWIM_XFER_RX)
{
twim_rx_done = true;
}
break;
case NRFX_TWIM_EVT_ADDRESS_NACK:
NRF_LOG_INFO("Received NACK after sending address!");
break;
case NRFX_TWIM_EVT_DATA_NACK:
NRF_LOG_INFO("Received NACK after sending data.");
break;
default:
break;
}
uint32_t nrf_drv_oxi_init(void)
{
uint32_t err_code;
const nrfx_twim_config_t twi_oxi_config = {
.scl = OXI_TWI_SCL_PIN,
.sda = OXI_TWI_SDA_PIN,
.frequency = NRF_TWIM_FREQ_400K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGHEST,
.hold_bus_uninit = true
};
err_code = nrfx_twim_init(&twim_instance, &twi_oxi_config, twim_handler, NULL);
APP_ERROR_CHECK(err_code);
nrfx_twim_enable(&twim_instance);
return NRF_SUCCESS;
}
// ------------------------------------------------------------------------------------------------
uint8_t readByte( uint8_t familyByte, uint8_t indexByte)
{
nrfx_err_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};
size_t tx_lenght = sizeof(familyByte) + sizeof(indexByte);
nrfx_twim_xfer_desc_t tx_xfer = NRFX_TWIM_XFER_DESC_TX(OXI_ADDRESS_W, tx_buffer, tx_lenght);
err_code = nrfx_twim_xfer(&twim_instance, &tx_xfer, 0);
APP_ERROR_CHECK(err_code);
while (!twim_tx_done)
{
__WFE();
}
twim_tx_done = false;
nrfx_twim_xfer_desc_t rx_xfer = NRFX_TWIM_XFER_DESC_RX(OXI_ADDRESS_R, rx_buffer, rx_lenght);
err_code = nrfx_twim_xfer(&twim_instance, &rx_xfer, 0);
APP_ERROR_CHECK(err_code);
while (!twim_rx_done )
{
__WFE();
}
twim_rx_done = false;
StatusByte = rx_buffer[0];
NRF_LOG_INFO("Status Byte: %lu \n",StatusByte);
ReturnByte = rx_buffer[1];
return ReturnByte;
}
I don't receive any error (err_code always 0 (NRF_SUCCESS)) but it seems that after the first transaction (TX) nothing happen as i can see from the TWIM0 window:

No task is started and no byte is transferred.
I am a newbie in embedded system, probably my functions are correct (thanks to the help of Nordic Support Team) but probably i am missing some basics of I2C configuratiion.
Do you have any idea why this could happen?
thanks,
polimarte

