The article directories

    • preface
    • 1. Function introduction of UartLogger
    • Two, complete source code
    • 3. Experimental results
    • More variety

preface

The library functions of the shineBlink Core development board (core for short) support the Uart function, so you only need to call two apis to achieve Uart communication.

PS: Core in only five or six lines of code can be realized Wifi/Ble/NB/Lora ThreadMesh/RFID/Eth/Usb/RS485 / RS232 communication, and more than 30 sensors/more than 10 kinds of hardware peripherals/more than 10 kinds of Mcu functions inside, And these functions can run in up to five random combinations simultaneously. Learn more about Core at shineblink.com.

1. Function introduction of UartLogger

In the development process, we sometimes need a third-party hardware tool (UartLogger) to monitor the specific communication content of serial Tx and Rx. At this time, we can easily achieve this purpose with Core. In addition, Core can output the monitored Tx and Rx communication content in various forms or store it on the TF card of Core.

Here is a typical example of what UartLogger does:

Using UartLogger, we can capture the specific content of communication between MCU and ESP8266 when developing ESP8266 serial WIFI module. Other similar scenarios can be used as long as the Uart interface is used.

Two, complete source code

Note: In this example, it is assumed that the baud rate of the monitored Uart port is 115200. You need to adjust the actual baud rate.

-- Configure the USB interface of the Core as a virtual serial port to connect to the computer and print out the content captured by the UartLogger
-- Of course, you can also configure bluetooth output, WIFI output, depending on your mood
LIB_UsbConfig("CDC_PD")
LIB_GpioOutputConfig("D8"."STANDARD")
LIB_GpioOutputConfig("D9"."STANDARD")
LIB_Uart0Config("BAUDRATE_115200")
LIB_Uart1Config("BAUDRATE_115200")
prefix0 = {13.10.82.88.48.58.13.10} --"\r\nRX0:\r\n"
prefix1 = {13.10.82.88.49.58.13.10} --"\r\nRX1:\r\n"
-- Start the big cycle
while(GC(1) = =true)
do
	recv_flag0,recv_tab0 = LIB_Uart0Recv()
	if recv_flag0 == 1 then
		LIB_GpioToggle("D8") --LED1 Toggle
		LIB_UsbCdcSend(prefix0)
		LIB_UsbCdcSend(recv_tab0)-- Displays the content captured by the RX0 pin on the serial terminal
	end
	
	recv_flag1,recv_tab1 = LIB_Uart1Recv()
	if recv_flag1 == 1 then
		LIB_GpioToggle("D9") --LED2 toggle
		LIB_UsbCdcSend(prefix1)
		LIB_UsbCdcSend(recv_tab1)-- Displays the contents captured by the RX1 pin on the serial terminal
	end
end
Copy the code

3. Experimental results

In this experiment, we captured the communication content with ESP8266 serial port WIFI module and printed it to the terminal software. The following figure shows the captured content:

More variety

The function of storing monitored Tx and Rx communication contents in the TF card is very convenient for finding problems. Instead of watching the device all the time, we can take out the TF card to check the contents at a certain time.

The implementation is simple. Replace the LIB_UsbCdcSend() function with LIB_Fwrite(), for example:

The original code

LIB_UsbCdcSend(prefix0)
LIB_UsbCdcSend(recv_tab0)-- Displays the content captured by the RX0 pin on the serial terminal

LIB_UsbCdcSend(prefix1)
LIB_UsbCdcSend(recv_tab1)-- Displays the contents captured by the RX1 pin on the serial terminal
Copy the code

The replaced code:

LIB_Fwrite("abc.txt", prefix0)
LIB_Fwrite("abc.txt", recv_tab0)Save the contents captured by the RX0 pin to the FILE abc.txt on the TF card

LIB_Fwrite("abc.txt", prefix1)
LIB_Fwrite("abc.txt", recv_tab1)-- Save the contents captured by the RX1 pin to a file abc.txt on the TF card
Copy the code