Hello DevZone,
I am trying to build a NFC driver but I am getting issues with it reinitializing every time I detect a field.
I am unable to use the T2T and T4T libraries as they do not give me the functionality I need.
In short I have a T2T poller which is sending commands to my nRF but the T2T library is not able to write back.
I want to use the nrfx_nfct library to build my own NFC driver but I cannot understand why I am getting reinitialization when a field is detected.
My goal is to set data ready based on the type of command I receive but unfortunately I'm not even able to receive anything due to the reinitialization.
uint8_t rxBlaBla[100];
uint8_t txBlaBla[100];
nrfx_nfct_data_desc_t rxBla, txBla;
void nfc_caaallback(nrfx_nfct_evt_t const * p_event)
{
switch (p_event->evt_id)
{
case NRFX_NFCT_EVT_FIELD_DETECTED:
NRF_LOG_DEBUG("Field On");
break;
case NRFX_NFCT_EVT_FIELD_LOST:
NRF_LOG_DEBUG("Field Off");
nrfx_nfct_autocolres_disable();
break;
case NRFX_NFCT_EVT_SELECTED:
NRF_LOG_DEBUG("Selected");
break;
case NRFX_NFCT_EVT_TX_FRAMESTART:
NRF_LOG_DEBUG("Started TX frame");
break;
case NRFX_NFCT_EVT_TX_FRAMEEND:
NRF_LOG_DEBUG("Ended TX frame");
break;
case NRFX_NFCT_EVT_RX_FRAMESTART:
NRF_LOG_DEBUG("Started RX frame");
break;
case NRFX_NFCT_EVT_RX_FRAMEEND:
{
NRF_LOG_DEBUG("Ended RX frame status = %d", p_event->params.rx_frameend.rx_status);
NRF_LOG_DEBUG("Data len in received frame is %d", p_event->params.rx_frameend.rx_data.data_size);
uint16_t command = uint16_big_decode(p_event->params.rx_frameend.rx_data.p_data);
NRF_LOG_DEBUG("Data is 0x%04x", command);
} break;
case NRFX_NFCT_EVT_ERROR:
{ NRF_LOG_DEBUG("Error occured. Error is %d", p_event->params.error.reason);
nrfx_nfct_data_desc_t rx;
rx.data_size = sizeof(m_ndef_msg_buf);
rx.p_data = m_ndef_msg_buf;
nrfx_nfct_rx(&rx);
} break;
default:
/* No implementation required */
break;
}
}
int main(void)
{
log_init();
rxBla.data_size = sizeof(rxBlaBla);
rxBla.p_data = rxBlaBla;
txBla.data_size = sizeof(txBlaBla);
txBla.p_data = txBlaBla;
nrfx_nfct_config_t config =
{
.rxtx_int_mask = (NRF_NFCT_INT_RXFRAMEEND_MASK |
NRF_NFCT_INT_RXERROR_MASK |
NRF_NFCT_INT_TXFRAMESTART_MASK |
NRF_NFCT_INT_TXFRAMEEND_MASK),
.cb = nfc_caaallback
};
uint32_t u32ErrCode;
u32ErrCode = nrf_drv_clock_init();
APP_ERROR_CHECK(u32ErrCode);
nrf_drv_clock_lfclk_request(NULL);
nrf_drv_clock_hfclk_request(NULL);
u32ErrCode = nrfx_nfct_init(&config);
APP_ERROR_CHECK(u32ErrCode);
nrfx_nfct_rx(&rxBla);
u32ErrCode = nrfx_nfct_tx(&txBla, NRF_NFCT_FRAME_DELAY_MODE_EXACTVAL);
APP_ERROR_CHECK(u32ErrCode);
nrfx_nfct_enable();
while(1)
{
while(NRF_LOG_PROCESS());
}
}
The RTT output I get is:
<info> NFCT: Reinitialize <info> NFCT: Initialized <info> NFCT: Tx start <info> NFCT: Start <debug> app: Field On <info> NFCT: Reinitialize <debug> app: Field Off <debug> app: Field On <info> NFCT: Reinitialize <debug> app: Field Off <debug> app: Field On <info> NFCT: Reinitialize <info> NFCT: Reinitialize <debug> app: Field Off <debug> app: Field On <info> NFCT: Reinitialize <debug> app: Field Off