This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Add UART1 to bluetoothds example on nrf52840

Hi, I need some guidance or an more in-depth example on adding the necessary code to read/write on the UART1 using the serial module or something else. Everything I've tried so far causes a fatal crash when attempt to write on UART1.

I've started with the experimental bluetoothds_template. Then I used BDS to create my GATT service and imported the code. Everything works and I am able to r/w my characteristic values.

I need to communicate with an external sensor using the UART1. UART0 is already enabled by default for logging. I tried to follow the example from this question and some others.

Some items I've done are set in sdk_config.h

#define NRF_QUEUE_ENABLED 1
#define NRF_SERIAL_ENABLED 1
#define UART1_ENABLED 1
#define UART1_CONFIG_USE_EASY_DMA 1

set this in my header

NRF_SERIAL_DRV_UART_CONFIG_DEF(m_uart1_drv_config,
					ARDUINO_0_PIN, ARDUINO_1_PIN,
					ARDUINO_2_PIN, ARDUINO_3_PIN,
					NRF_UART_HWFC_ENABLED, NRF_UART_PARITY_INCLUDED,
					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(serial1_queues, SERIAL_FIFO_TX_SIZE, SERIAL_FIFO_RX_SIZE);
#define SERIAL_BUFF_TX_SIZE 1
#define SERIAL_BUFF_RX_SIZE 1
NRF_SERIAL_BUFFERS_DEF(serial1_buffs, SERIAL_BUFF_TX_SIZE, SERIAL_BUFF_RX_SIZE);
NRF_SERIAL_CONFIG_DEF(serial1_config, NRF_SERIAL_MODE_DMA,
                      &serial1_queues, &serial1_buffs, NULL, NULL);
NRF_SERIAL_UART_DEF(serial1_uart, 1);

called this in the init area of main

ret = nrf_serial_init(&serial1_uart, &m_uart1_drv_config, &serial1_config);

and the sending of data in a timer

ret = nrf_serial_write(&serial1_uart, tx_message, strlen(tx_message), NULL, 0);

The first time data is written, no data is seen on the tx/rx lines on the sensor. The second time the chip faults.

Anyone have a good example? Thanks

Parents
  • Jørgen, I think we figured this out. It seems the next call to nrf_serial_write() would return the timeout error if the TX queue was still filled with data and the call would overflow the TX queue. With flow ctrl in place, the sensor was having a problem reading the data fast enough. We fixed that and data is being sent OK now. Question, is there a way to check the amount of used bytes in the TX queue on Serial before calling nrf_serial_write() to prevent overflow?

Reply
  • Jørgen, I think we figured this out. It seems the next call to nrf_serial_write() would return the timeout error if the TX queue was still filled with data and the call would overflow the TX queue. With flow ctrl in place, the sensor was having a problem reading the data fast enough. We fixed that and data is being sent OK now. Question, is there a way to check the amount of used bytes in the TX queue on Serial before calling nrf_serial_write() to prevent overflow?

Children
No Data
Related