- Fri Jul 15, 2016 2:19 pm
#50815
Hi, Me-no-dev, hi all,
Me-no-dev wrote:The command bytes can be changed to something else through the registers, but the general protocol must stay the same. SPI1S3 is the register in question.
One thing I don't understand is that your slave code leaves the the SPI1S3 register to 00000000, but still, the correct interrupt is raised when the master sends commands 01, 02, 03 or 04.
How can it be ? Are they the "default" commands and is there a bit I must set to enable overriding of default values by the ones in SPI1S3 ?
Edit: I tried SPI1S.SPISCD (Command Define), to no avail.
In the end however, I could wrap a code that seems to achieve my "spying" goal.
Indeed, I noticed that the SPI1A (address) register always contains the first bytes of the messages I'm spying on.
Reminder: observed messages I need to decode have one of the 3 following formats:
08 FF FF (heartbeat)
A4 aa bb (update leds)
54 cc dd 0 0 (update display)By regularly dumping SPI1A, I observed that it contains, respectively:
08FFFF00
A4aabb00
54ccdd00
Unfortunately, as these messages are neither "status read/write" nor "data read/write", I wasn't notified in any callbacks... until I saw that you handled those 4 interrupts but a fifth is present, simply called "trans".
So I added a hspi_slave_onTrans() similar to hspi_slave_onStatus() all the way up to the calling code and now it seems I can reliably be notified when *any* message comes in.
Generally speaking, there are drawbacks of course, the most obvious being that I'm limited to 4-byte messages (fortunately, the only 5-byte message in my protocol always seems to end with a 0), and I really believe that it's a non-orthodox way of getting data, but it seems to work.
By the way, I first tried to redefine commands to receive status and data as SPI1S3 as A4 and 54, respectively (SPI1S3 = 0xA4005400), hoping to get the two interesting messages as status and data, but that didn't trigger any interrupt.
(in fact, only the "Send status" interrupt is regularly triggered, so it seems some messages are recognized as a request from the master to send the status...)
I had also defined the status length to 2 bytes, the address length to 1 byte and the data length to 3 bytes (SPI1S1 = 0xF << SPIS1LSTA | 0x17 << SPIS1LBUF | 0x7 << SPIS1LRBA;) but now that I observed that the address register is filled with up to 4 bytes, I believe even more that these for these settings to be used, an "enable" field of some sort must be set...
I will go on using the address field as observed above because that will allow me to complete my project, but feel free to shed some light on this if you have more information.
By the way, I worked along the way on a "properly formatted" documentation of the SPI registers in the form of a spreadsheet (it's mainly grouping in a single place the two .h files and their comments, the findings by metalphreak and the ones from this topic.
I'm attaching here a PDF version for ease of reading, but I can share the source if anyone is interested. Hope it helps...
ESP8266 SPI register description 20160715.pdf
Kind regards,
Vicne
You do not have the required permissions to view the files attached to this post.
Last edited by Vicne on Wed Feb 22, 2017 2:22 pm, edited 1 time in total.