I am working through the Nordic Developer Academy and got stuck at lesson 4 (UART receive)
In particular, I am confused about this part:
I have created a sample project and connected external CP2102 USB->Serial adapter to P0.06 and P0.08 pins.
The code that I use:
Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/*
* Copyright (c) 2012-2014 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include "stdio.h"
#include "zephyr/drivers/uart.h"
const struct device *uart = DEVICE_DT_GET(DT_NODELABEL(uart0));
static uint8_t tx_buf[] = {"nRF Connect SDK Fundamentals Course \n\r"};
static uint8_t rx_buf[10] = {0}; //A buffer to store incoming UART data
const struct uart_config uart_cfg = {
.baudrate = 115200,
.parity = UART_CFG_PARITY_NONE,
.stop_bits = UART_CFG_STOP_BITS_1,
.data_bits = UART_CFG_DATA_BITS_8,
I am having issues understanding how to properly print out all the received data:
I tried to do:
Fullscreen
1
2
3
4
5
6
7
case UART_RX_RDY:
printf("rx rdy \n");
if((evt->data.rx.len) != 0){
printf("data received = %s \n", evt->data.rx.buf[evt->data.rx.offset]);
}
break;
but when I send the data via UART (using Termite) , the following is printed:
I would appreciate if someone could clarify how to correctly print out all the received data. Thanks in advance
Just for testing, I have also tried to print:
Fullscreen
1
2
3
4
case UART_RX_RDY:
printf("rx rdy \n");
printf("data: %s \n", rx_buf);
break;
and the logs are as following: (captured using Termite):

As you can see, it receives the first message (ping) correctly, but after that, the buffer overflows (rx_buf is 10 bytes size) and then it cannot print out the data correctly)