Hello,
I have a setup containing an NRF9160 communicating with another chip over UART at a 1M baudrate.
The following code is currently used:
#include "../../include/status_leds.h" #include <logging/log.h> #include <nrfx.h> #include <nrfx_uarte.h> LOG_MODULE_REGISTER(my_uart_module, CONFIG_LOG_DEFAULT_LEVEL); #if defined(CONFIG_NRFX_UARTE1) #define UART_INSTANCE 1 #define UART_NAME DT_ALIAS_UART_1_IRQ_0 #elif defined(CONFIG_NRFX_UARTE2) #define UART_INSTANCE 2 #define UART_NAME DT_ALIAS_UART_2_IRQ_0 #elif defined(CONFIG_NRFX_UARTE3) #define UART_INSTANCE 3 #define UART_NAME DT_ALIAS_UART_3_IRQ_0 #else #error "No suitable UARTE device specified." #endif K_THREAD_STACK_DEFINE(thread_stack, THREAD_STACK); struct { nrfx_uarte_t uart; struct k_fifo fifo; struct k_thread messenger; k_tid_t tid; u32_t pos; u8_t buf[UART_BUFSZ]; // ... } _mod = { .uart = NRFX_UARTE_INSTANCE(UART_INSTANCE), .pos = 0, .buf = {0} }; static char test[] = "Hey, there. This is a test.\n"; static inline void rx_next_byte(void); int uart_init(void); static void uarte_event_handler(nrfx_uarte_event_t const* evt, void* ctx); ISR_DIRECT_DECLARE(uarte_isr_handler) { #if defined(CONFIG_NRFX_UARTE1) nrfx_uarte_1_irq_handler(); #elif defined(CONFIG_NRFX_UARTE2) nrfx_uarte_2_irq_handler(); #elif defined(CONFIG_NRFX_UARTE3) nrfx_uarte_3_irq_handler(); #else #error "No suitable UARTE device specified." #endif ISR_DIRECT_PM(); return 1; } int uart_init(void) { k_fifo_init(&_mod.fifo); _mod.tid = k_thread_create( &_mod.messenger, thread_stack, K_THREAD_STACK_SIZEOF(thread_stack), message_passer, NULL, NULL, NULL, THREAD_PRIO, 0, K_NO_WAIT); nrfx_uarte_config_t uarte_config = NRFX_UARTE_DEFAULT_CONFIG( 16, 31 ); uarte_config.baudrate = NRF_UARTE_BAUDRATE_1000000; IRQ_DIRECT_CONNECT(UART_NAME, 0, uarte_isr_handler, 0); REQUIRE(NRFX_SUCCESS == nrfx_uarte_init( &_mod.uart, &uarte_config, uarte_event_handler), -ECANCELED); rx_next_byte(); nrfx_uarte_tx(&_mod.uart, test, sizeof(test)); return 0; } static void uarte_event_handler(nrfx_uarte_event_t const* evt, void* ctx) { switch (evt->type) { case NRFX_UARTE_EVT_ERROR: rx_next_byte(); status_leds_signal_once(STATUS_LEDS_ERROR, K_SECONDS(1)); break; case NRFX_UARTE_EVT_RX_DONE: rx_next_byte(); status_leds_signal_once(STATUS_LEDS_SUCCESS, K_SECONDS(1)); break; default: status_leds_signal_once(STATUS_LEDS_PENDING, K_SECONDS(1)); nrfx_uarte_tx(&nrf52.uart, test, sizeof(test)); break; } } static inline void rx_next_byte(void) { nrfx_uarte_rx(&_mod.uart, _mod.buf + _mod.pos, 1); _mod.pos = (_mod.pos + 1) % UART_BUFSZ; }
I have configured the TX pin on pin 16 and the RX pin on pin 31 of the NRF91.
My problem is that although the initialization of the UART instance seems to work fine it can neither receive nor transmit data.
The TX pin (16) is constantly high which is to be expected but using an oscilloscope I cannot measure any signals being sent down the wire despite the fact that the
NRFX_UARTE_TX_DONE event is fired properly every time. There is no device connected to pin 16 at the moment it is just used for testing purposes.
Similar issues exist with the RX pin (31). The other chip constantly sends data to the NRF91 however, I only get two framing errors after I started the application. After that
there is no RX related event or error fired.
Am I missing something (maybe in my configuration)?
Kind regards
Nils