Using native USB to communicate with GPS board with UART bridge

GuilleZGZ
Posts: 3
Joined: Fri Sep 08, 2023 9:19 pm

Using native USB to communicate with GPS board with UART bridge

Postby GuilleZGZ » Fri Sep 08, 2023 10:00 pm

Hi all,

I've been trying to connect a GPS receiver (Navspark NS-RAW for the matter) with both an ESP32-S3-DevkitC-1 v1.0 board using the native USB port. I have to do so because, although the GPS microcontrollar has a serial interface, the board only directly exposes the TXD on the available pins. The RXD is only available on a micro-usb through a UART bridge.

The GPS board can be interfaced with the PC by means of a software provided by the provider or by directly sending commands in binary form with a software like Realterm. Both work fine, so the GPS board is ok and I understand the communication protocol.

According to the manufacturer of the GPS board, if connected with a device functioning as an ESP host (the ESP in this case) it should behave in the same way it does when connected to the PC. This might sound pretty obvious, but it's the first time I try this. I connect the ESP32 with the PC using the UART micro USB connector and the GPS board through pins 19 and 20 on the ESP32. I listen to the TXD pin of the GPS board with a logic analyzer. The board sends its position with 1Hz, as it should do unless told otherwise, so it's powered on and working.

Image

I'm using this example program in the Arduino IDE for my tests:
https://github.com/espressif/arduino-es ... Serial.ino

This program should redirect any data going into the UART port to the native USB. So, theoretically, the GPS board should be receiving any commands I send from the PC. Unfortunaly the GPS board doesn't react to them. This commands are correct, as the GPS reacts to them as expected when directly connected to the PC, but not when interfacing with the ESP. Swapping D+ and D- doesn't change anything.

When I reset the ESP32 I get this per the UART port:

Code: Select all

ESP-ROM:esp32s3-20210327                                                      
Build:Mar 27 2021                                                             
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)                              
SPIWP:0xee                                                                    
mode:DIO, clock div:1                                                         
load:0x3fce3808,len:0x44c                                                     
load:0x403c9700,len:0xbe4                                                     
load:0x403cc700,len:0x2a68                                                    
entry 0x403c98d4                                                              
USB UNPLUGGED
Is there anything I'm missing here? Do I have to use any particular sort of cable like an OTG cable at the ESP32 or GPS board ends? Any help will be appreciated!

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: Using native USB to communicate with GPS board with UART bridge

Postby lbernstone » Sat Sep 09, 2023 11:43 pm

If I understand the issue, you don't need to use USBSerial at all. Arduino will just do the right thing if you set it up right. Under the tools menu, make sure you set USB CDC On Boot to enabled, and JTAG adapter to disabled. This will make Serial the USB connection to the PC, and you can use Serial1 for the GPS. The example at https://github.com/espressif/arduino-es ... t_Demo.ino will echo data from Serial1 to Serial, or you can use one of the more standard GPS libraries to process the location data.

GuilleZGZ
Posts: 3
Joined: Fri Sep 08, 2023 9:19 pm

Re: Using native USB to communicate with GPS board with UART bridge

Postby GuilleZGZ » Sun Sep 10, 2023 9:27 pm

lbernstone wrote:
Sat Sep 09, 2023 11:43 pm
If I understand the issue, you don't need to use USBSerial at all. Arduino will just do the right thing if you set it up right. Under the tools menu, make sure you set USB CDC On Boot to enabled, and JTAG adapter to disabled. This will make Serial the USB connection to the PC, and you can use Serial1 for the GPS. The example at https://github.com/espressif/arduino-es ... t_Demo.ino will echo data from Serial1 to Serial, or you can use one of the more standard GPS libraries to process the location data.

Are you sure Serial should be the UART and Serial1 the native USB? I might be missing something here, but I've done a few more tests connecting both ports of the ESP32 to the PC (without the GPS board), with these results:

- Including USB.h seems to have no effect
- Serial0 seems to me to be the UART
- Serial seems to me to be the native USB
- Nothing seems to go out through any of the two ports when using Serial1

I've reduced the test code to this:

Code: Select all

#include "USB.h"

#define UART_USB Serial0 
#define Native_USB Serial // Only Serial seems to send something through the native USB. With Serial1 I get no readings

void setup() {
  UART_USB.begin(115200);
  Native_USB.begin(115200);
}

void loop() {

  UART_USB.println("Per UART");
  UART_USB.println(Native_USB.available());
  Native_USB.println("Per native USB");
  
  while(Native_USB.available()) {
    size_t l = Native_USB.available();
    uint8_t b[l];
    l = Native_USB.read(b, l);
    UART_USB.write(b, l);
  }

  delay(1000);

}
With this code I see the "Per UART" and "Per native USB" messages on two Realterm sessions listening to one of the ports each on the PC. But when disconnect the native USB port from the PC and connect the GPS board instead Native_USB.available() remains 0 and nothing new appears on the UART USB.

I've attached the configuration I'm using in the Arduino IDE.

Any other ideas? Or did I get your first reply wrong? Thanks a lot!
Attachments
ESP32_USB_Arduino_config.png
ESP32_USB_Arduino_config.png (107.78 KiB) Viewed 2346 times

lbernstone
Posts: 826
Joined: Mon Jul 22, 2019 3:20 pm

Re: Using native USB to communicate with GPS board with UART bridge

Postby lbernstone » Mon Sep 11, 2023 6:06 pm

You need to set the pins when you call a HardwareSerial.begin. Note that TX and RX are from the ESP's perspective. You can use either Serial0 or Serial1- they can be assigned to any gpio pins.
https://github.com/espressif/arduino-es ... ial.h#L109

GuilleZGZ
Posts: 3
Joined: Fri Sep 08, 2023 9:19 pm

Re: Using native USB to communicate with GPS board with UART bridge

Postby GuilleZGZ » Mon Sep 11, 2023 7:42 pm

I appreciate your help but I'm not getting it, sorry. Please don't give up :D

I'm familiar with serial communication and I understand how to initialize a serial port defining the RX and TX pins on the ESP32. But there are no RX/TX pins on the side of the GPS, only the D+/D- pins on its micro USB port. How should the RX/RX pins on the ESP32 correlate to the D+/D- pins on the GPS board? Plus I read everywhere that the pins 19 and 20 on the ESP32S3-DevkitM are hardwired to the D+/D- of the native USB in the microcontroller. I'm definitely still missing something here.

Who is online

Users browsing this forum: No registered users and 80 guests