Hi there, I am trying to implement a UART handler on my nRF9151 that can Tx GNSS updates to my nRF52833. I am adapting this into the cellular/gnss sample, which is working completely fine on its own. However, when I try to run uart_callback_set(), I am getting -88 in return.
I have followed the Async UART on Nordic Academy to the best of my abilities.
Here is my UART handler. Right now, I am just trying to set up something basic to echo back when it receives an ECHO message from my nRF52833.
// nRF52833 UART Handler
#define NRF_UART_BUF_SIZE 128
#define RECEIVE_TIMEOUT 100
static char uart_rx_buffer[NRF_UART_BUF_SIZE];
static size_t uart_rx_index = 0;
static uint8_t rx_buf[NRF_UART_BUF_SIZE] = {0};
static void nrf52833uart_cb(const struct device *dev, struct uart_event *evt, void *user_data)
{
switch (evt->type) {
case UART_RX_RDY: {
const uint8_t *data = &evt->data.rx.buf[evt->data.rx.offset];
size_t len = evt->data.rx.len;
for (size_t i = 0; i < len; i++) {
if (uart_rx_index < NRF_UART_BUF_SIZE - 1) {
uart_rx_buffer[uart_rx_index++] = data[i];
}
// Check for newline or carriage return to end message
if (data[i] == '\n' || data[i] == '\r') {
uart_rx_buffer[uart_rx_index] = '\0'; // Null terminate string
// Print the full received message
LOG_INF("UART RX message: %s", uart_rx_buffer);
if (strcmp((char *)rx_buf, "ECHO") == 0) {
uart_send_async("nRF9151 ECHO!\n");
}
// Reset index for next message
uart_rx_index = 0;
}
}
break;
}
case UART_RX_DISABLED:
// Restart RX (adjust rx_buf and timeout as per your code)
uart_rx_enable(dev, rx_buf, sizeof(rx_buf), RECEIVE_TIMEOUT);
break;
case UART_TX_DONE:
uart_tx_busy = false;
break;
default:
break;
}
}
This is how it is called in main.
int main(void)
{
int err;
uint8_t cnt = 0;
struct nrf_modem_gnss_nmea_data_frame *nmea_data;
LOG_INF("Checking nRF52833 UART connection");
k_sleep(K_MSEC(10));
if (device_is_ready(nrf52833uart_dev)) {
LOG_INF("nRF9151 UART connection is ready. Setting up UART callback protocol.");
int ret = 0;
ret = uart_callback_set(nrf52833uart_dev, nrf52833uart_cb, NULL);
if (ret) {
LOG_ERR("Failed to set up UART callback protocol: %d", ret);
} else {
ret = uart_rx_enable(nrf52833uart_dev ,rx_buf,sizeof rx_buf,RECEIVE_TIMEOUT);
if (ret) {
LOG_ERR("Failed to enable UART RX: %d", ret);
}
}
} else {
LOG_ERR("nRF9151 UART connection is not ready");
}
I have set:
CONFIG_UART_ASYNC_API=y
CONFIG_NRFX_UARTE0=y.
#define NRF52833UART_NODE DT_NODELABEL(uart0)
const struct device *nrf52833uart_dev = DEVICE_DT_GET(NRF52833UART_NODE);
I've also tried CONFIG_TFM_LOG_LEVEL_SILENCE=y to try and release uart0.
Thank you!
I've also tried CONFIG_TFM_LOG_LEVEL_SILENCE=y to try and release uart0.
Thank you!