Moderator: igrr
Me-no-dev wrote:I think that SPI1U1 register is for the master works and not for the slave, so changing things there might not influence the result at all.
Mmmh. Not so cool

Well I might try to make it consider that the first byte received is a command... I will check that.
Thanks.
In the meantime, I performed more tests on AVR vs ESP, and here are the first results.
I first tried your "SafeMaster" sample with an added SPI.beginTransaction() call to make sure we use SPI Mode 0, and flashed it on both an AVR and an ESP, just to compare the MOSI signal wrt CS and CLK.
This part is reassuring:
AVR MOSI:
ESP8266 MOSI:
There are differences (shorter CS pulse on ESP, MOSI is idle low on ESP, MOSI staying high for some time after the last bit on AVR), but all in all, they are both clear "MODE0" signals, with clock low in idle and MOSI changing on falling edge to be sampled on rising edge.
Very good.
Both of these signals are received without any problem by the unmodified (except for a serial dump of the answer) SPISlave sample you provided, as expected.
Things get a bit more complex on for the "answer" part using the MISO line.
I confirm your observation that the answer sent by your SPISlave sample is indeed received and understood correctly by the AVR :
Now looking at the scope, here's what we get:
Zooming on the end of question (ch4, left) and start of answer (ch3, right):
Zooming more on MOSI, edges are OK, as above:
But on MISO, edges are not OK, because bits change on rising clock edge to be sampled on falling:
Zooming more on the edge of MISO, we can see that the delay after the clock edge is really small (about 50ns):
So my interpretateion of this is that the MISO signal is wrongly aligned, but as the slave ESP takes much less time to change the MISO after the clock edge than the AVR takes time to sample the MOSI after the edge. Consequently, I would think the AVR handles the MISO correctly by pure luck.
What do you think ?
Going on with the tests...
Kind regards,
Vicne

Hi,
The next tests I performed are much more worrying and leave me puzzled...
I wanted to make sure that adding my "fix" that made inter-ESP communication work was harmless for AVR-ESP communication... but it's not.
I really don't understand why, but it seems that once I add the "SPI1C2 |= 1 << SPIC2MISODM_S;" line to the code, the slave ESP cannot emit correct replies anymore. They sometimes start with one character ("A") or two ("Al") OK, but the rest is garbage:
You can also see that most replies are randomly aborted, leading to a stream of 0xFF (ÿ) characters
And the more I dig, the less I understand, because the scope clearly show that it's not an AVR decoding issue, it's the MISO signal that's corrupt:
(0x41 58 87 49 should really be 0x41 6C 69 76 for "Aliv")
I first checked the edges but they are OK:
Here's the end of command and start of answer:
With a zoom on end of command, switching on falling and stable on rising clk edge:
and a zoom on start of answer, with the same convention:
Then I proceeded to decode the 3 first bytes of the answer by hand:
The first is OK:
But then:
And then:
As one can see, the MISO is not just shifted by one bit, or jittery or noisy. It's a perfectly clean corrupt signal


That leaves me speechless because that's the part where the AVR doesn't do anything except drive the clock !
So how on earth can the same slave code reply differently if the clock is driven by an AVR vs an ESP ???
Clock timing, or amplitude, or noise could explain it, but they all look pretty OK to me. Moreover the slave ESP is able to read that AVR clock to decode the MOSI, but would be unable to use the same sync signal to drive the MISO ? That makes no sense...
And also, why does it work when the setting is left to transitions on the reverse edge ?
OK, I am going to let the slave untouched and flash an ESP with the exact same master code as the AVR and rewire it as the master to check that I can reproduce the good behaviour I had yesterday.
Vicne