Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP32 Inconsistent Connection #33

Open
hickmanz opened this issue Jun 2, 2024 · 0 comments
Open

ESP32 Inconsistent Connection #33

hickmanz opened this issue Jun 2, 2024 · 0 comments

Comments

@hickmanz
Copy link

hickmanz commented Jun 2, 2024

Im trying to get this code to work on an ESP32 and have frustrating results. Occasionally it connects and works exactly as intended. But most of the time, it seems to crash the wheel base (CSL DD) and I need to power cycle the wheelbase.

I also have experienced it working fine, temporarily the computer losing site of the wheel base and then it returning again.

Below is the code I am using to get basic functionality going. I have stripped out almost everything except the emulation of the wheel while I try and solve this problem:

#include <SPI.h>

#define CS_PIN 5
#define DATA_LENGTH 33

uint8_t returnData[DATA_LENGTH] = {
  0xA5, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x83, 0x87, 0x47, 0x7B, 0x9A,
  0x79, 0xA0, 0xC9, 0xB5, 0xD8, 0x1D, 0x72, 0x20, 0x2C, 0xFA, 0x62, 0xFF, 0x93, 0x04,
  0xCB, 0x98, 0xD0, 0x12, 0xAF
};
volatile uint32_t sequence = 0;

void cableSelect() {
  if (digitalRead(CS_PIN) == LOW) {  // Check if CS is low
      SPI.transfer(returnData, DATA_LENGTH);  // Send data back to master
  }
}
void setup() {
  pinMode(CS_PIN, INPUT_PULLUP);
  SPI.begin();  // Initialize SPI port
  SPI.setDataMode(SPI_MODE1);  // Set the SPI mode to mode 0
  SPI.setBitOrder(MSBFIRST);  // Set MSB first for data order
  attachInterrupt(digitalPinToInterrupt(CS_PIN), cableSelect, FALLING);  // Attach interrupt for CS pin
}

void loop() {
  // Since the SPI transactions are handled in the ISR, the loop can remain empty
}

I am running out of things to try next and the inconsistency of working vs not working is making it hard to troubleshoot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant