Open hpssjellis opened 2 weeks ago
I found the esp32spiSlave library, which makes sense that the slave is not configured to send, but presently dont have it running.
The idea of pin expansion via spi in series with multiple xiao is quite interesting. Maybe we'll verify it for you and export it as a wiki.
The idea of pin expansion via spi in series with multiple xiao is quite interesting. Maybe we'll verify it for you and export it as a wiki.
@limengdu
On MBED an entire library is used for the SpiSlave https://os.mbed.com/docs/mbed-os/v6.16/apis/spislave.html It makes sense that MISO, MOSI, SCK will need to be set differently for the slave, and perhaps the spi.transfer function needs to work differently. I will continue to work on it, but if you can give me some suggestions that would be great.
I think Eric Pan knows that you are welcome to use any of my open source XIAO-ESP32S3-sense maker100-eco code on your wiki. Just credit both Jeremy Ellis and the TinyML4D community.
@limengdu The following SPI slave code is different than my original and compiled and sent some data but still is not working. It is based on the idea that the SPIClass has functionality to work as a slave device, but it really needs to be an easier, better system.
I did find out that I need to plug the main usb device into the usb plug a few times before both XIAO's start properly. Kind of strange but might explain some earlier frustrations.
#define SS_PIN D0 // Slave Select pin
#define MOSI_PIN D10 // Master Out Slave In
#define MISO_PIN D9 // Master In Slave Out
#define SCK_PIN D8 // Serial Clock
//volatile byte myReceivedData;
volatile byte mySendingData;
void setup() {
pinMode(SS_PIN, INPUT_PULLUP); // Set SS pin as input with pull-up resistor
SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN); // Initialize as SPI slave
// Attach interrupt to the SPI slave select pin
attachInterrupt(digitalPinToInterrupt(SS_PIN), onReceive, FALLING);
Serial.begin(115200); // Initialize serial communication for debugging
}
void loop() {
Serial.print("Slave Sent: ");
Serial.println(mySendingData, HEX);
delay(1000);
}
void onReceive() {
SPIClass *spi = &SPI;
mySendingData = 3
spi->transfer(mySendingData);
}
Unless I learn something new, I am stuck. Nothing is consistent, even the library esp32spiSlave does not seem to work with the XIAO boards. Most Arduino systems only work for an old AVR method, the new MBED boards also don't seem to work. As far as I can tell putting the SPIClass into slave mode is the only issue, but I can't seem to get it working. Hopefully someone can have a look at this and make some suggestions.
Thanks for the detailed description, I'll come back and look into your scenario after I've been busy with my latest business. We can discuss and study the details of it together.
Found this repository that looks promising. I will try to test it later.
Any XIAO SPI to any other XIAO
Presently data is not moving between the boards.
@LynnL4
Background: The XIAO only has 10 pins most other boards have 20-40 pins. Many large projects need more pins, and a multiplexer is just another layer of confusion. Solution: Connect 2 or more XIAO together.
I have I2C and UART XIAO to XIAO communication working here
XIAO SPI works fine with other boards that need SPI like a XIAO to OLED etc, so the issue should not be with the receiver (Master) the issue is probably with the Transmitter (Slave).
Here is my semi-working code: I typically make code as simple as possible but have tried several ideas here to make things work. It is likely that I have missed some simple thing.
Slave (transmitter)
and the much longer Master (receiver) code: