- Tue Jun 28, 2016 5:24 pm
#49933
Hi, all,
I now have a sketch working perfectly on Arduino Uno but I'm still not sure how to port it to ESP8266.
I see two ways, but I would like to hear your opinions or tips on the subject :
1) using hardware SPI:
I see source files (e.g. hardware\esp8266\2.2.0\cores\esp8266\esp8266_peri.h ) reference both SPI0 registers (with the comment "SPI0 is used for the flash") and SPI1 registers (without any comment). Does the ESP8266 have a second SPI bus available ? Is it what is called HSPI in other documents ? Can I use it along with SPI0 ? Can it work in slave mode ? What are the pins associated to it ?
2) using software SPI:
I am thinking of using two interrupts, one on the Chip Select pin and one on the CLK pin, but timing will be key. The signal I have to read is clocked at 250kbps, so as the ESP8266 runs at 80MHz (or respectively 160MHz in hi-speed), I should process 1 interrupt every 320 (resp 640) CPUclock cycles. The handler would just sample the MOSI input, shift it in a byte, and push that byte in a queue every 8 clock cycles, so this is probably doable pretty quickly (in assembly if needed), but as the CLK edge occurs right at the middle of the bit, I cannot afford a delay of more than 160 (resp 320) CPU clock cycles between the CLK edge and the sampling of the value (if it's too tight, I could almost double that by triggering on the opposite edge, letting a few cycles go, and then sampling to target the "beginning" of the bit, even before the "official edge" occurs, leaving more margin for the edge-handler delay).
Do you think it is realistic to have such short notices for interrupt handling ?
Note: data on the SPI bus is repeated regularly and I can check its format for validity, so I could afford to miss one bit every now and then, but not more than, say, 1-2%
Any comment would be greatly appreciated.
Kind regards,
Vicne