I actually use both the Serial and Serial1, but I would need an other one, it can be software serial (even better since it's an inverted signal). Is it possible ?
I heard of this, but I think it's just changing the pin for Serial1, right ?
Thanks, that's where I took the information, BUT what's not clear is : does it change the pin for Serial1, meaning by creating mySerial with the previous command, does it change the Serial1 pin or those it create a new third serial (so can I have Serial, Serial1 and mySerial all 3 at once)?
(but I will try it and post my result here)
Did you try the procedure given on the GitHub link.
Try add as a header above setup
UART mySerial(digitalPinToPinName(4), digitalPinToPinName(3), NC, NC); //4 is tx, 3 is rx
//(change 4 and 3 as you prefer, the processor can mux any functionality on any pin)
Then in setup mySerial.begin( ); //Add baud rate
You should be able to have Serial, Serial1 and mySerial on the Nano33BLE.
Thanks a lot, Cattledog, now my board seems read something.
Before I followed this example:
that defines RX/TX inverted in comparison your suggestion:
UART mySerial(digitalPinToPinName(4), digitalPinToPinName(3), NC, NC); //4 is tx, 3 is rx that runs fine.
I still have some issue in my code, but I'll update the result
Yes, the signature of the UART constructor used in the Arduino core for the Nano33BLE is unlike everything else Serial related in the Arduino code base.
As you noted, the typical serial/software serial constructor is indeed RX,TX, but for the Nano33 BLE, the order of the pin parameters in the UART constructor is TX, RX.
I noted that with UART mySerial is not possible to set the baudrate at 10400. The Nano 33 sends to the closest 9600 speed. Do you have a software serial to suggest to use as third Uart able to work at 10400 Baud?
Thanks again cattledog. I modified the prescaler register as in your suggested tread:
so now I have three serial communication lines in Nano 33 BLE with one with no standard baud too.
Example:
// PINS FOR Nextion display comm
const unsigned int NEXTIONRX_PIN = D3; // connect to NEXTION RX
const unsigned int NEXTIONTX_PIN = D4; // connect to NEXTION TX
// PINS FOR A SECOND COMM LINE, E.G. OBD ISO9141 LINE
const unsigned int RX_PIN = D1; // connect to ISO9141 OBD transceiver Rx
const unsigned int TX_PIN = D0; // connect to ISO9141 OBD transceiver Tx
// Definitions for a no standard baudrate at 10400
#define UARTE0_BASE_ADDR 0x40002000 // As per nRF52840 Product spec - UARTE
#define UART_BAUDRATE_REG_OFFSET 0x524 // As per nRF52840 Product spec - UARTE
#define UART0_BAUDRATE_REGISTER (*(( unsigned int *)(UARTE0_BASE_ADDR + UART_BAUDRATE_REG_OFFSET)))
#define BAUD10400 0x2A9930 // Value theoretical but trimmed at 0x2A1E00 for my specific HW
UART Serial2(NEXTIONTX_PIN, NEXTIONRX_PIN); // TX, RX set the second UART pins
void setup()
{
Serial.begin(115200,SERIAL_8N1); // Start serial comm at baud=115200 to USB Serial Monitor
Serial1.begin(10400,SERIAL_8N1); // Start serial comm at no std baud=10400 to OBD interface for example
Serial2.begin(115200,SERIAL_8N1); // Start serial comm at baud=115200 for display Nextion, remember to modify the Nexconfig.h in Nextion library setting "Serial2"
UART0_BAUDRATE_REGISTER = BAUD10400; // set the baudrate register of micro to have 10400 baud accurate in Serial 1
}
void loop()
{
Serial.print(" This is the USB monitor: "); // Text on IDE monitor
Serial1.write( 0x55); //data sent at 10400 precise baud
Serial2.print("message.txt=\""); // a message to display Nextion
Serial2.print("NEXTION TEXT");
Serial2.print("\"");
Serial2.write(0xff);
Serial2.write(0xff);
Serial2.write(0xff);
delay(200);
}