My goal is to transmit information between sketches I have runing concurrently on the U Blox ESP32 and main SMAD21 mcu.
I noted from the MKR WiFI 1010 schematics that the TX pin of the SAMD21 Serial1 connection is wired to the RX pin of the U Blox and the RX pin of the SAMD21 Serial1 connection is wired the TX on the U Blox module.
When I try and read from Serial1 on the SAMD21 I receive the bootstrap startup messages from the ESP32. So at some level I do have avalid connection, however none of my own code sending on the SAMD21 Serial1 or receiving in ESP32 code (using HardwareSerial and pins 1 and 3 for RX and TX respectively) seems to work.
Can anyone tell me if the SAMD Serial11 connection to the ESP32 is available for my sketches or is it reserved for the bootloader? If available, is there anything I need to do to free it from the bootloader once my sketch has started?
Is there another intended channel for passing information between the ESP32 and SAMD21 modules rather than this serial connection?
Not sure if you are interested in my code or the libraries / environment so hopefully this answers your question
I am using the Arduino IDE ver 1.8.13 and the ESP32 V 1.0.4 Boards
I first upload the SerialNinaPassthrough.ino sketch when the IDE is configured for a MKR WiFi 1010 board, after that I select u-blox NINAW-10 series (ESP32) board from the ESP32 board list and upload the following test sketch. It basically allows a classic bluetooth connection and then sends updates every few seconds showing counts of chars received / sent - basically a heartbest so I know the sketch is running. Anything received over Bluettoth it attempts to send to the SAMD21 using a HardwareSerial connection and anything received over that connection is echoed to the Bluetooth connection.
#include "BluetoothSerial.h"
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
#define SAMD21_UART MySerial
HardwareSerial MySerial (0);
#define RX2 1
#define TX2 3
void setup()
{
SAMD21_UART.end();
SAMD21_UART.begin ( 115200, SERIAL_8N1, RX2, TX2 );
SerialBT.begin ( "My MKR WiFi 1010" ); //Bluetooth device name
SerialBT.println ( "MKR Connected" );
}
void loop()
{
static unsigned long ulTime =0UL;
static unsigned long ulBTReceivedCharCount = 0UL;
static unsigned long ulSAMD21SentCharCount = 0UL;
static unsigned long ulSAMD21RecvdCharCount = 0UL;
unsigned long ulNow = millis();
if ( ulNow - ulTime > 5000 )
{
SerialBT.print ( "ESP32 here, SAMD Serial port is " );
SAMD21_UART ? SerialBT.print ( " Ready, Received " ) : SerialBT.print ( " Not ready, Received " );
SerialBT.print ( ulBTReceivedCharCount );
SerialBT.print ( " chars over BT connection, Received " );
SerialBT.print ( ulSAMD21RecvdCharCount );
SerialBT.println ( " chars over SAMD connection" );
if ( SAMD21_UART )
{
SAMD21_UART.println ( "ESP Here" );
}
ulTime = ulNow;
}
while ( SAMD21_UART.available() )
{
ulSAMD21RecvdCharCount += SerialBT.write ( SAMD21_UART.read() );
}
while ( SerialBT.available() )
{
ulBTReceivedCharCount += SAMD21_UART.write ( SerialBT.read() );
}
delay(20);
}
If you are receiving bootstrap messages of the ESP32 then you are using the wrong serial port to send messages from on the ESP32.
The ESP32 has 4 hardware serial ports, you can easily use 2. 1 of the 4 is used for serial monitor, one for programming, and the other 2 are for you to use.
When I originally saw the thread that Juraj listed above, I make some progress but was getting what I now know is the ESP32 bootloader startup messages appearing when reading the SAMD21 Serial2 port. This made be think I could not use this serial port and I needed to find another Serial port to use, this sent me down a rabbit hole. After Juraj said above that the example usually worked, I went back to it and decided to ignore the initial bootloader messages (which I also now think can be supressed based on the Esperrif Boot mode documentation using GPIO15).
This appears to work and I can either ignore the loadloader messages or look to surpress them.