- My goal is: read and print data form uart2
- My actions are: I am using example code uart-js
load('api_timer.js');
load('api_uart.js');
load('api_sys.js');
let uartNo = 2; // Uart number used for this example
let rxAcc = ''; // Accumulated Rx data, will be echoed back to Tx
let value = false;
// Configure UART at 115200 baud
UART.setConfig(uartNo, {
baudRate: 100,
rxLingerMicros: 200,
esp32: {
gpio: {
rx: 16,
tx: 17,
},
},
});
// Set dispatcher callback, it will be called whenver new Rx data or space in
// the Tx buffer becomes available
UART.setDispatcher(uartNo, function(uartNo) {
let ra = UART.readAvail(uartNo);
if (ra > 0) {
// Received new data: print it immediately to the console, and also
// accumulate in the "rxAcc" variable which will be echoed back to UART later
let data = UART.read(uartNo);
print('Received UART data:', data);
rxAcc += data;
}
}, null);
// Enable Rx
UART.setRxEnabled(uartNo, true);
- The result I see is: I get rubbish like:
[Oct 23 16:55:51.729] Received UART data: \x80(\x00\x00\x00
[Oct 23 16:55:52.739] Received UART data: \x00\x1e!\x00\x00\x00\x00\xde
[Oct 23 16:55:53.748] Received UART data: \x80(
[Oct 23 16:55:54.749] Received UART data: \x00\x00\x00\x00\x1e!\x00\x00\x00\x00
[Oct 23 16:55:55.554] Received UART data: \xde
[Oct 23 16:55:56.559] Received UART data: \x80(\x00\x00\x00\x00\x1e
[Oct 23 16:55:57.568] Received UART data: !\x00\x00\x00\x00\xde
[Oct 23 16:55:58.578] Received UART data: \x80(\x00\x00
[Oct 23 16:55:59.579] Received UART data: \x00\x00\x1e!\x00\x00\x00\x00\xde
[Oct 23 16:56:00.588] Received UART data: \x80
[Oct 23 16:56:01.589] Received UART data: (\x00\x00\x00\x00\x1e!\x00\x00\x00
- My expectation & question is: I am sending to ESP32 13 bytes like 80,40,0,0,0,0,28,27,0,0,0,0,123 from another ESP and I get 9, 8, 3 bytes of data like above. It looks the same in mjs and c. When I use Arduino or ESP-IDF the result is as I excepted, nice 13 bytes of data.
This is a real issue. Anyone can help?