There are 2 serial ports on the nRF52840 with naming Serial1 and Serial. Serial1 is the actual UART which can be used for UART connectivity. There is another serial port which only works through USB port. this cannot be used as hardware UART. So, when you connect USB to Arduino Nano 33 BLE board, we are actually using the Serial and this is used for debugging purposes.
Here is a connectivity between the Arduino Nano 33 BLE and external USB to TTL converter.
TX and RX pins of Arduino Nano 33 BLE are connected to the RXD and TXD pins of CP2102 USB to TTL converter. Arduino Nano 33 BLE is connected to laptop via USB.
When we connect to the 2 USB ports on our laptop, we can see the 2 COM ports detected.
Here is the simple code, to exchange data between the 2 interfaces.
We can see the data on the Tera Term and Arduino IDE.
void setup() {
// initialize both serial ports:
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
}
}
0 Comments