I am trying to use nrf_serial with IRQ. Tx operations just fine but, i can not get any interrupt when a data comes from uart. I am using sdk 14.2 and not using ble.
static void sleep_handler(void);
static void serial_event_handler(struct nrf_serial_s const *p_serial, nrf_serial_event_t event);
NRF_SERIAL_DRV_UART_CONFIG_DEF(m_uart0_drv_config,
8, 15,
RTS_PIN_NUMBER, CTS_PIN_NUMBER,
NRF_UART_HWFC_DISABLED, NRF_UART_PARITY_EXCLUDED,
NRF_UART_BAUDRATE_115200,
UART_DEFAULT_CONFIG_IRQ_PRIORITY);
#define SERIAL_FIFO_TX_SIZE 32
#define SERIAL_FIFO_RX_SIZE 32
NRF_SERIAL_QUEUES_DEF(serial_queues, SERIAL_FIFO_TX_SIZE, SERIAL_FIFO_RX_SIZE);
#define SERIAL_BUFF_TX_SIZE 1
#define SERIAL_BUFF_RX_SIZE 1
#define MAX_RX_BUFFER_SIZE 100
NRF_SERIAL_BUFFERS_DEF(serial_buffs, SERIAL_BUFF_TX_SIZE, SERIAL_BUFF_RX_SIZE);
NRF_SERIAL_CONFIG_DEF(serial_config, NRF_SERIAL_MODE_IRQ, &serial_queues, &serial_buffs, serial_event_handler, sleep_handler);
NRF_SERIAL_UART_DEF(serial_uart, 0);
uint32_t uart_init(void)
{
return nrf_serial_init(&serial_uart, &m_uart0_drv_config, &serial_config);
}
uint32_t send_uart(uint8_t *tx_message)
{
uint32_t error_code;
error_code = nrf_serial_write(&serial_uart, tx_message, strlen(tx_message), NULL, 0);
nrf_serial_flush(&serial_uart, 0);
return error_code;
}
static void serial_event_handler(struct nrf_serial_s const *p_serial, nrf_serial_event_t event)
{
static uint8_t buffer[MAX_RX_BUFFER_SIZE] = {0};
static uint8_t length = 0;
switch (event)
{
case NRF_SERIAL_EVENT_TX_DONE:
break;
case NRF_SERIAL_EVENT_RX_DATA:
{
nrf_queue_read(p_serial->p_ctx->p_config->p_queues->p_rxq, &buffer[length], 1);
if (buffer[length] == '\n')
{
uart_callback(buffer, length);
memset(buffer, 0, MAX_RX_BUFFER_SIZE);
length = 0;
nrf_serial_flush(&serial_uart, 0);
}
else
{
length++;
}
}
break;
case NRF_SERIAL_EVENT_DRV_ERR:
break;
case NRF_SERIAL_EVENT_FIFO_ERR:
break;
default:
break;
}
}