Hi,
I am trying to use UART in a blocking mode for nrf52840. I am able to transmit the bytes, but not receiving the bytes. While debugging, figured out that RXDRDY event is not being detected.
Here is the code block:
void uart_tx(uint8_t* data_tx)
{
//clear the TXDRDY event
UART0_REG->EVENTS_TXDRDY=~UART_EVENT_TXDRDY;
//trigger the start task
UART0_REG->TASKS_STARTTX=1;//UART_TASK_START_TX;
UART0_REG->TXD=data_tx;//0x32;//
//EDIT: Doing in blocking mode
while(!UART0_REG->EVENTS_TXDRDY)
{
//do nothing
}
UART0_REG->TASKS_STOPTX=UART_TASK_STOP_TX;
}
uint8_t* uart_rx()
{
uint8_t* ret=0x00;
//TODO:clear error reg also
// UART0_REG->EVENTS_RXDRDY=~UART_EVENT_RXDRDY;
event_clear(UART0_REG->EVENTS_RXDRDY, UART_EVENT_RXDRDY);
// UART0_REG->TASKS_STARTRX=UART_TASK_START_RX;
task_trigger(UART0_REG->TASKS_STARTRX,UART_TASK_START_RX);
// Edit: doing in blocking mode
//clear RTO event
//check events - error, rxdrdy, rto - keep doing them until either one is received
//if error or rto -- stop rx, break and return error
//else return UART0_REG->RXD
//stop rx task
event_clear(UART0_REG->EVENTS_RXTO,UART_EVENT_RXTO);
uint32_t error_evt, rxdrdy_evt,rxto_evt;
do
{
error_evt=event_check(UART0_REG->EVENTS_ERROR,UART_EVENT_ERROR);
rxdrdy_evt=event_check(UART0_REG->EVENTS_RXDRDY, UART_EVENT_RXDRDY);
rxto_evt=event_check(UART0_REG->EVENTS_RXTO,UART_EVENT_RXTO);
}while(!(error_evt && rxdrdy_evt && rxto_evt));// wait till an event arrives
if(rxdrdy_evt)
{
event_clear(UART0_REG->EVENTS_RXDRDY, UART_EVENT_RXDRDY);
ret = UART0_REG->RXD;
}
return ret;
}
in main.c
uint8_t* tx_data="12345";
uint8_t* rx_data;
while(1)
{
for(int i=0; i<=sizeof(tx_data);i++)
{
uart_tx(tx_data[i]);
rx_data[i]=uart_rx();
}
}
Can you please help me figure out where the mistake is.
Regards,
Ramya