Skip to main content

UART Communication Anomaly Between WisNode-LoRa and Arduino Uno

Technical
Author
Kuan-Yi Li
Table of Contents
TL;DR It is caused by Arduino Uno’s high baud error at 115200 baud. Just change baud setting of both sides to one of 9600, 19200 or 38400.

Introduction
#

WisNode-LoRa is a RAK811-based development board with Arduino Uno Rev3 connectors. For Arduino extension board development, RAKWireless provided library. However, the code examples do NOT work out of the box.

Symptom
#

The communication from WisNode-LoRa to Arduino Uno worked out OK, Arduino Uno properly received power on message Welcome to RAK811 from WisNode-LoRa, but not the other way around. Whenever Arduino Uno issue command to WisNode-LoRa, it’s going to be either no response or ERROR-1.

Debugging
#

The board works fine when operated through on board USB-to-UART (CH340G), ruling out RAK811 module defect.

Given this document, I initially thought there was something wrong with the built-in level shifting circuit, yet if I connect the level shifting output 5_3T to FT2232H and Bus Pirate, both receive commands correctly.

Tried voltage divider, just to be sure, but no luck.

Furthermore, according to RAK811 schematic and STM32L151CB datasheet, RAK811’s UART should be 5V tolerant—all those level shifting should not be necessary.

So I tried to connect them without level shifting, still no luck.

Out of despair, I then tried one last thing, lower the baud of both sides to 9600. And guess what? It worked! Doesn’t even need level shifting!

Root Cause
#

As it turns out, the anomaly is cause by UART baud mismatch. Equipped with a 16MHz crystal oscillator, the closest baud to 115200 that Arduino Uno (ATmega328P) can generate is 117647, which is 2.1% faster than desired, and it seems to have exceeded STM32’s receiver tolerance to clock deviation. (Already knew about this, surprised by the amount of error, though.)

For 9600, 19200 and 38400 bauds, Arduino Uno is able to generate signal with baud error around 0.2%. Thus have no problem communicating with RAK811.

Fix
#

Change RAK811 UART configuration from 115200 baud to a lower baud supported. (9600, 19200 or 38400)

at+uart=9600,8,0,0,0

Well, we will have to do this through something other than Arduino Uno, like USB-to-UART, of course. 😅

And do not forget to reset WisNode-LoRa for this configuration to take effect.

Change Arduino Uno UART configuration in sketch

Serial.begin(9600)

Appendix
#

Actually, you CAN work at 57600 baud, with some workaround.

In most cases, Arduino Uno hardware serial operate in double speed mode (U2X = 1), with one hardcoded exception for 57600 baud. As hardware serial operate in normal mode (U2X = 0), you get 2.1% baud error instead of -0.8% baud error. (See Table 3-5 of this application note.)

To workaround such exception you can initialize your serial interface with something like Serial.begin(57601). This will give you 57600 baud with -0.8% baud error which is compatible with RAK811.

References
#