UART-1 conflict with SD card on SPI? mux mapping issue?

rrudolph
Posts: 1
Joined: Tue Dec 10, 2019 12:30 am

UART-1 conflict with SD card on SPI? mux mapping issue?

Postby rrudolph » Tue Dec 10, 2019 12:56 am

Hello,
I am running into an issue using HardwareSerial(1) while I also have an SD card mounted.
I am using the builtin HardwareSerial library to map uart1 to pins 32 & 33, and the following works fine:

Code: Select all

HardwareSerial surveillance_serial(1);
HardwareSerial scanner_serial(2);
...
surveillance_serial.begin( 9600, SERIAL_7N1, 32, 33, false, 50);

scanner_serial.begin( 9600, SERIAL_7E1, 16, 17, false, 50);
...
surveillance_serial.read() called in a FreeRTOS task at intervals
scanner_serial.read() also called in a FreeRTOS task at intervals
I have separate FreeRTOS tasks reading the two serial ports, and everything is happy and good, no issues, I receive serial data on uart1 and uart2 with no problems.

Now I've added an SD card into the mix, using the builtin SD library:

Code: Select all

#include "FS.h"
#include "SD.h"
#include "SPI.h"
...
if (!SD.begin(5)) {
  Serial.println("ERROR: SD card mount failed");
  return;
}
Serial.println("SD card mounted.");
...and again, on it's own this works fine, the SD card mounts successfully, and file reads/writes from separate FreeRTOS tasks work great!

However (!!) mounting the SD card causes surveillance_serial on UART1 to stop receiving data. I have removed all other SD card functions from my code and determined that the line above, SD.begin(5), definitively triggers the problem . If I comment out SD.begin(5) with no other changes, UART1 works great again.

TL;DR: Using the SD card over SPI works. Using hardwareserial UART1 on GPIO 32/33 works. When I try to do both, uart1 stops receiving data.

Debugging so far:
I know that under the hood, my call to .begin() on hardwareserial(1) is remapping the GPIO functions internally to GPIO 32/33.
I see that the "default" pins for u1RXD and u1TXD are GPIO9 and GPIO10, which also share the pin with "spiHD" and "spiWP". However, my SD card is wired (and working) on the standard SPI pins (vspi?) GPIO's 5, 18, 19, 23.
I see there are separate <SD.h> libraries for arduino and esp32. I am compiling and uploading from the Arduino IDE. Is it possible it's pulling in the wrong library?

Any ideas would be appreciated - thanks!

Who is online

Users browsing this forum: Majestic-12 [Bot], ThomasK and 13 guests