mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-07-30 02:01:58 +08:00

* Update WebSocket library * Update SSDP library * Update TFT_eSPI library * Update EspLuaEngine library * Update SDFat library * Change to pioarduino * Make ESP3DMessageFIFO and ESP3DMessage more thread safe * Fix sanity checks for BT * Add some C6 support * Refactor ethernet code * Split Ethernet Sta / WiFi sta ESP Commands and settings * Simplify wait and wdtFeed code * Set C3 with 4MB by default in platformio.ini * Apply Disable brown out only on ESP32 to avoid crash e.g:ESP32S3 * Add missing entries in platformio.ini
66 lines
1.7 KiB
C++
66 lines
1.7 KiB
C++
// This is a simple SPI loop-back test.
|
|
//
|
|
// Connect SD_MISO to SD_MOSI
|
|
//
|
|
// Modify these defines for your configuration.
|
|
#define SD_SPI SPI
|
|
#define SD_MISO MISO
|
|
#define SD_MOSI MOSI
|
|
|
|
#include "SPI.h"
|
|
void setup() {
|
|
uint8_t rx, tx;
|
|
Serial.begin(9600);
|
|
while (!Serial) {
|
|
yield();
|
|
}
|
|
Serial.println(F("\nType any character to start"));
|
|
while (!Serial.available()) {
|
|
yield();
|
|
}
|
|
Serial.print("Begin, SD_MISO: ");
|
|
Serial.print(SD_MISO), Serial.print(", SD_MOSI: ");
|
|
Serial.println(SD_MOSI);
|
|
pinMode(SD_MISO, INPUT_PULLUP);
|
|
pinMode(SD_MOSI, OUTPUT);
|
|
digitalWrite(SD_MOSI, HIGH);
|
|
if (!digitalRead(SD_MISO)) {
|
|
Serial.println("Error: SD_MISO not HIGH");
|
|
goto fail;
|
|
}
|
|
digitalWrite(SD_MOSI, LOW);
|
|
if (digitalRead(SD_MISO)) {
|
|
Serial.println("Error: SD_MISO not LOW");
|
|
goto fail;
|
|
}
|
|
pinMode(SD_MISO, INPUT);
|
|
pinMode(SD_MOSI, INPUT);
|
|
|
|
// Modify if SD_SPI.begin has arguments and use this style SdFat begin call:
|
|
// sd.begin(SdSpiConfig(CS_PIN, USER_SPI_BEGIN | <other options>, &SD_SPI));
|
|
SD_SPI.begin();
|
|
|
|
// Start with a 400 kHz clock. Try full speed if success for 400 kHz.
|
|
SD_SPI.beginTransaction(SPISettings(400000, MSBFIRST, SPI_MODE0));
|
|
tx = 0;
|
|
do {
|
|
rx = SD_SPI.transfer(tx);
|
|
if (tx != rx) {
|
|
Serial.print("Error rx: 0x");
|
|
Serial.print(rx, HEX);
|
|
Serial.print(" != tx: 0x");
|
|
Serial.println(tx, HEX);
|
|
SD_SPI.endTransaction();
|
|
goto fail;
|
|
}
|
|
} while (tx++ < 255);
|
|
SD_SPI.endTransaction();
|
|
Serial.println("Success!");
|
|
return;
|
|
|
|
fail:
|
|
SD_SPI.endTransaction();
|
|
Serial.println("Is SD_MISO connected to SD_MOSI?");
|
|
Serial.println("Are SD_MISO and SD_MOSI correct?");
|
|
}
|
|
void loop() {} |