-
Notifications
You must be signed in to change notification settings - Fork 15
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
Time-out crashes #26
Comments
Could you try v0.4.0 release? Also notice Notes for Communication Errors |
I switched to v0.4.1 (running in Arduino 2.3.0) This is my slave code #include <ESP32SPISlave.h>
#define SPIIN_SCLK 18
#define SPIIN_MISO 19
#define SPIIN_MOSI 23
#define SPIIN_SSEL 5
#define SPIIN_BUS VSPI // HSPI
ESP32SPISlave spiin;
#define BUF_SIZE 32
uint8_t spiin_buf_tx[BUF_SIZE];
uint8_t spiin_buf_rx[BUF_SIZE];
void setup() {
// Serial
Serial.begin(115200);
delay(2000);
Serial.printf("\n\nspi2x - rx\n");
// SPI
spiin.setDataMode(SPI_MODE0);
spiin.begin(/*bus*/SPIIN_BUS, /*sck*/SPIIN_SCLK, /*miso*/SPIIN_MISO, /*mosi*/SPIIN_MOSI, /*ss*/SPIIN_SSEL);
Serial.printf("waiting for spi message...\n" );
}
void loop() {
uint32_t t0=millis();
const size_t num = spiin.transfer(spiin_buf_tx, spiin_buf_rx, BUF_SIZE,1000);
uint32_t t1=millis();
if( num==0 ) {
Serial.printf("time=%d num=%d (timeout)\n", t1-t0, num );
} else {
Serial.printf("time=%d num=%d << ", t1-t0, num );
for( int i=0; i<num; i++ ) Serial.printf("%c",spiin_buf_rx[i]);
Serial.printf("\n");
}
}
Note that this is more or less your "Blocking big transfer() one by one" example. Some differences: I have explicit bus and pins, I did not override QueueSize, I set a timeout of 1000ms, and I measure the blocking time of the I have another ESP32 connected to it, which acts as a master. This is the output of the slave program.
If I change the timeout to 10 000 ms (
Conclusion: the timeout I specify only works for the first 2 calls, then the library seems to revert to 5000ms. When I remove the timeout (i.e. it gets the default value of 0, I guess "no-timeout"), the call blocks for ever. That seems correct. But, I have a second observation, first messages are missed. On my master, every string I enter over serial is send over SPI. There is one special string "*". When I enter that, the master will send 1, 222, 333, 4444, 55555, 666666, 7777777, 88888888, 999999999 with a delay of 500ms in between. Here is what the slave shows, when I enter * twice.
Here is what the slave shows when I enter * once and then later another *.
Conclusion: the first 2 or 3 messages after a timeout are not received by the slave. Any suggestions? Thanks. |
Fixed by #29 Please try v0.4.2 |
Thanks for the fast response!
I'm on trip this week - without hardware - so I'll check next week.
… Message ID: ***@***.***>
|
Sorry, lot's of wokr just after my trip. I use timeout of 1000, that seems now stable - thanks! When I enter a * on the master, it sends and the slave receives the * and all 10 digit sequences - thanks! When I enter two *s, I get all 22 sequences - thanks.
This release seems to fix all my problems. Tomorrow I have time for a more thorough test but wanted to let you know your work is appreciated. |
All looking good. I'm now also using I was wondering, if |
It’s a strange behavior. Could you enable the debug log by setting the log level to “debug” from Tool > Core Debug Level in Arduino IDE? Then, please let me know the log when it occurs. |
I think we have a misunderstanding. I did't have a problem. I had I question. The scenario
|
All transactions that were queued at the time of triggering are executed. Therefore, there is no concept of unqueue. If a transaction fails, the received bytes is currently set to zero. However, it might be a good idea to set the error code to received bytes with a negative value in case of failure. |
#30 added the feature to return an error code if the transaction failed. Please try v0.5.0. |
I saw int64_t instead of size_t. I must say that that doesn't feel good for embedded software. How big are SPI tranfers? 8 bytes, 1k byte? Why isn't an int enough for the sizes? |
error code is 32bit, so it should be 64bit. But certainly it should be improved so I will try it in another issue. If you have solved the original issue (timeout crash), please close this issue. |
Thanks for the support. |
Hi Hideaki Tai,
Thanks for the lib.
I have an a-typical setup. My ESP is connected to a sensor, the sensor is the SPI master and the ESP is the SPI slave. The ESP triggers the sensor (via non-SPI lines), and then the sensor is supposed to use SPI to send the sensor result to the SPI.
There might be a problem with the sensor, in which case it will not send an SPI message. So I want to do a wait-with-timeout (the
waitticks
).ESP code
ino
file:Yes, sorry, I made
waitticks
myself. I added the following function just blowwait
inESP32SPISlave.h
:As long as there is no timeout, the ESP can receive SPI message after message.
Once there is one timeout (or more), the ESP can receive only one more SPI message.
If, after that first message (there are some timeouts and then) there is a second message, the ESP crashes.
My conclusion is that I do not understand well enough the execution architecture of the SPI stack.
Would you be able to give me help on how to add timeout?
Kind regards,
Maarten
Here is an example run (the message from the sensor is
msg#
)The text was updated successfully, but these errors were encountered: