-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Initial SPI Slave implementation and examples #2234
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
Conversation
Current coverage is 27.86%@@ master #2234 diff @@
==========================================
Files 20 20
Lines 3653 3653
Methods 335 335
Messages 0 0
Branches 675 675
==========================================
Hits 1018 1018
Misses 2457 2457
Partials 178 178
|
Hi, This library is exactly what i'm looking for. I want to use my ESP12 (mounted on a wemos D1 board) as a SPI slave. I implemented both the master and slave examples (SPISlave_Master.ino and SPISlave_Test.ino) on two different wemos boards. The master is sending "Are you alive?" -> the slave responds with "Alive for x seconds!" The master reads the data from the slave, but something strange is happening, I have to shift the byte 1 position to the right. Like this:
Is it me, or is this a little bug in the library? |
there isn't much that can be bug :) the lib reads from the hardware directly. I had it running for a couple of days here, no miss. What speeds are you using for SPI? Did you try the SafeMaster sketch? |
BTW I tested with Arduino UNO and ESP. Will try with two ESPs later (expecting a module in the mail today) |
I did also try it with an Arduino UNO and and an ESP. That works well.... (master = arduino, slave = ESP). Is it possible that it has to do with the CPU frequency? Maybe I did setup one EPS with 80Mhz and one with 160Mhz. But I think this is not the problem. |
yes default speed is 1MHz, so that is way lower than the 8MHz that I usually run the sketches at... |
any news? |
I can confirm that you need to shift the bits by 1 in the example code when using two ESPs. //Bump |
if((status & SPISWBIS) != 0 && (_hspi_slave_rx_data_cb)) { | ||
uint8_t i; | ||
uint32_t data; | ||
uint8_t buffer[33]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like this buffer is not used at all.
Could you switch to another SPI mode on the ESP8266 (only) ? Others have observed weird (reversed) behaviours. See #2416 |
@vdeconinck there is no possibility to change the SPI mode in the ESP8266 slave. Only public functions are public:
SPISlaveClass()
: _data_cb(NULL)
, _status_cb(NULL)
, _data_sent_cb(NULL)
, _status_sent_cb(NULL)
{}
~SPISlaveClass() {}
void begin();
void setData(uint8_t * data, size_t len);
void setData(const char * data)
{
setData((uint8_t *)data, strlen(data));
}
void setStatus(uint32_t status);
void onData(SpiSlaveDataHandler cb);
void onDataSent(SpiSlaveSentHandler cb);
void onStatus(SpiSlaveStatusHandler cb);
void onStatusSent(SpiSlaveSentHandler cb);
}; and in hspi_slave.h: //Start SPI SLave
void hspi_slave_begin(uint8_t status_len, void * arg);
//set the status register so the master can read it
void hspi_slave_setStatus(uint32_t status);
//set the data registers (max 32 bytes at a time)
void hspi_slave_setData(uint8_t *data, uint8_t len);
//set the callbacks
void hspi_slave_onData(void (*rxd_cb)(void *, uint8_t *, uint8_t));
void hspi_slave_onDataSent(void (*txd_cb)(void *));
void hspi_slave_onStatus(void (*rxs_cb)(void *, uint32_t));
void hspi_slave_onStatusSent(void (*txs_cb)(void *)); The rest is hidden in the non-public code of Espressif. I guess @me-no-dev has to work on this, but he is now fully involved in the ESP32 stuff. I don't think anything will change here. Too bad 👎 |
Mmmh, I once used SPI slave code by @me-no-dev that included the possibility to select the mode, but it didn't seem to make it to the "official" SPI slave lib. |
I tried all four modes, only mode1 works, but with this strange bit shift. |
Ok did a ESP8266 SPI Master to ESP8266 SPI Slave test. Getting the same result. And same picture on the oscilloscope: Wondering how this ever was tagged as working. I have no level shifters laying around so I cannot test against an Arduino Uno as SPI Master, but I doubt that there is any difference. Maybe between writing the SPI Slave library and today was some changes in the SDK, but I am not sure how to check this. Giving up on the idea to connect ESP8266 and ESP32 by SPI for now. Too bad that the SPI slave lib is not working. Maybe I try to get an I2C connection to work between the two boards. |
Code I used was from http://www.esp8266.com/viewtopic.php?f=32&t=10579&hilit=Spi+slave#p50011 but it predates "official" spi slave lib in the core. I think that thread is worth a read. |
In the [ESP8266 Technical Reference]((https://espressif.com/sites/default/files/documentation/esp8266-technical_reference_en.pdf) I found the following:
But the waveform shown in the same documents shows that the data starts after the 8th bit of command: I could not find anything to change the slave command length, so I am wondering what is correct. Guess I have to check now how to set the ESP32's SPI master command length to 7 bits. |
No description provided.