Not recieving data via SPI on ESP-wroom-32 from Teensy 4.1

themagicm
Posts: 10
Joined: Tue Mar 28, 2023 2:27 am

Not recieving data via SPI on ESP-wroom-32 from Teensy 4.1

Postby themagicm » Sun Jun 23, 2024 3:28 am

At the very least I am sending the letter "C" from the Teensy to the ESP-wroom-32.
ESP says its receiving a null. I'm stumped. The reason for the 2 sec delay on the esp32, I was just trying to see if it recognized the pin being flipped from low to high on each side (it does).

Teensy code:

Code: Select all

#include <Arduino.h>
#include <SPI.h>

const int slaveSelectPin = 40; // CS pin
const int readyPin = 9; // Ready pin

void setup() {
  Serial.begin(115200);
  SPI.begin(); // Initialize SPI
  pinMode(slaveSelectPin, OUTPUT);
  pinMode(readyPin, INPUT); // Set ready pin as input
  digitalWrite(slaveSelectPin, HIGH);

  Serial.println("Teensy 4.1: SPI communication test started");
}

void loop() {
  // Wait until the ready pin is HIGH
  if (digitalRead(readyPin) == HIGH) {
    Serial.println("ESP32 is ready to receive data.");
    
    char data = 'C'; // Data to send to ESP32

    Serial.println("Sending: " + String(data));
    SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
    digitalWrite(slaveSelectPin, LOW); // Select the slave
    SPI.transfer(data); // Send data
    digitalWrite(slaveSelectPin, HIGH); // Deselect the slave
    SPI.endTransaction();
  } else {
    Serial.println("ESP32 is not ready.");
  }

  delay(1000); // Wait for a second before checking again
}

ESP code:

Code: Select all

#include <Arduino.h>
#include <SPI.h>

const int slaveSelectPin = 5; // CS pin
const int readyPin = 33; // Ready pin
volatile bool dataReceived = false;
volatile char receivedData = 0;

void IRAM_ATTR onSPI() {
  dataReceived = true;
}

void setup() {
  Serial.begin(115200);
  pinMode(slaveSelectPin, INPUT_PULLUP);
  pinMode(readyPin, OUTPUT); // Set ready pin as output
  digitalWrite(readyPin, LOW); // Initially set ready pin to LOW

  SPI.begin(18, 23, 19, slaveSelectPin); // Initialize SPI with SCK, MISO, MOSI, and SS
  attachInterrupt(digitalPinToInterrupt(slaveSelectPin), onSPI, FALLING);

  Serial.println("ESP32: SPI communication test started");
}

void loop() {
  if (dataReceived) {
    SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
    receivedData = SPI.transfer(0x00); // Read data from master
    SPI.endTransaction();

    Serial.print("Received from Teensy: ");
    Serial.println(receivedData, DEC); // Print the received data as a number
    Serial.print("Character: ");
    Serial.println(receivedData); // Print the received data as a character

    dataReceived = false;
    digitalWrite(readyPin, LOW); // Set ready pin to LOW after receiving data
    delay(2000);
  } else {
    digitalWrite(readyPin, HIGH); // Set ready pin to HIGH when ready to receive data
  }
}

aliarifat794
Posts: 200
Joined: Sun Jun 23, 2024 6:18 pm

Re: Not recieving data via SPI on ESP-wroom-32 from Teensy 4.1

Postby aliarifat794 » Sun Jun 23, 2024 6:28 pm

It will be better to test the Teensy and the ESP32-WROOM independently. Since you are using SPI communication, you must check if all the SPI-related pins of both modules are working well. All the cables are also worth checking.
https://forum.pjrc.com/index.php?thread ... p32.62906/

Who is online

Users browsing this forum: No registered users and 67 guests