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

rrudolph
Posts: 2
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!

desmith56
Posts: 1
Joined: Tue Jan 09, 2024 1:31 am

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

Postby desmith56 » Tue Jan 09, 2024 1:34 am

Hello.. also experiencing this issue.. any resolution?
Thanks
D

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

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

Postby lbernstone » Fri Jan 12, 2024 1:15 pm

Since the pins work, it seems a lot more likely you are starving the task of cpu time. Make sure you have delays in your tasks to hand off focus, and that all your functions are atomic.

Who is online

Users browsing this forum: No registered users and 115 guests