When is SPI MISO sampled?

jfollas
Posts: 9
Joined: Sun Oct 18, 2015 1:23 pm

When is SPI MISO sampled?

Postby jfollas » Sun Mar 20, 2016 11:02 am

SPI bits are supposed to be set on one clock edge and then read on the next.

https://en.wikipedia.org/wiki/Serial_Pe ... _and_phase

For example:

Mode 0 (CPOL=0, CPHA=0) sets the bit on the falling edge, and then samples on the next rising edge.
Mode 1 (CPOL=0, CPHA=1) set the bit on the rising edge, and then samples on the next falling edge.
Mode 2 (CPOL=1, CPHA=0) sets the bit on the rising edge, and then samples on the next falling edge.
Mode 3 (CPOL=1, CPHA=1) sets the bit on the falling edge, and then samples on the next rising edge.

I'm looking for clarification as to how to properly use SPI_CK_I_EDGE and SPI_CK_OUT_EDGE to control the behavior of when MISO is sampled.

Setting SPI_CK_OUT_EDGE to 1=rising edge and 0=falling edge per the above description correctly transitions the MOSI bit at the right time.

However, my guess that SPI_CK_I_EDGE controlled MISO was not accurate - the value here does not seem to have any effect of when the ESP8266 reads the MISO bit. In fact, testing shows that the ESP8266 is reading the MISO bit on the same clock edge that it uses to set MOSI.

Is there an undocumented bit that I am missing?

User avatar
rudi
Posts: 197
Joined: Fri Oct 24, 2014 7:55 pm

Re: When is SPI MISO sampled?

Postby rudi » Fri May 06, 2016 10:33 pm

jfollas wrote:SPI bits are supposed to be set on one clock edge and then read on the next.

https://en.wikipedia.org/wiki/Serial_Pe ... _and_phase

For example:

Mode 0 (CPOL=0, CPHA=0) sets the bit on the falling edge, and then samples on the next rising edge.
Mode 1 (CPOL=0, CPHA=1) set the bit on the rising edge, and then samples on the next falling edge.
Mode 2 (CPOL=1, CPHA=0) sets the bit on the rising edge, and then samples on the next falling edge.
Mode 3 (CPOL=1, CPHA=1) sets the bit on the falling edge, and then samples on the next rising edge.

I'm looking for clarification as to how to properly use SPI_CK_I_EDGE and SPI_CK_OUT_EDGE to control the behavior of when MISO is sampled.

Setting SPI_CK_OUT_EDGE to 1=rising edge and 0=falling edge per the above description correctly transitions the MOSI bit at the right time.

However, my guess that SPI_CK_I_EDGE controlled MISO was not accurate - the value here does not seem to have any effect of when the ESP8266 reads the MISO bit. In fact, testing shows that the ESP8266 is reading the MISO bit on the same clock edge that it uses to set MOSI.

Is there an undocumented bit that I am missing?


hi

in which mode you work, master or slave?
what you need, when do you read valid data?

you wrote MoSi, that is Master Out, Serial in, in the past that was SDI named too.
so you akt as Master to a Slave, right?

SPI_CK_I_EDGE (rising edge) and SPI_CK_OUT_EDGE (falling edge) are for your sampling the time position.
example put Data on MOSI pin if CK low, the slave read at in next comming CK high wave then ( this is a half wave after CK was low.


on rising edge:
CK low____ rising edge_/----CKhigh-----\_falling edge_______

on falling edge
CK high----falling edge-\___CKlow_____/-rising edge----------

hope this helps a little




best wishes
rudi ;-)

-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

jfollas
Posts: 9
Joined: Sun Oct 18, 2015 1:23 pm

Re: When is SPI MISO sampled?

Postby jfollas » Tue Jun 07, 2016 1:03 am

For the purpose of this post, I was referring to using the ESP as a master.

In a recent enhancement to the NodeMCU firmware, we added support for Mode 2 and Mode 3. The MOSI edge (master out, or when the ESP sets the bit from the master) is successfully set using the SPI_CK_OUT_EDGE. However, the MISO (master in, or when the ESP reads the bit from the slave) does not occur on the next clock edge as it is supposed to - instead, it seems to be happening at the same time/same edge as MOSI.

The test to illustrate the behavior had the slave set 0xAA on the SPI so that the data was valid for the MOSI clock edge, but cleared for the MISO clock edge. The ESP should have read in 0x00 based on the defined behavior for SPI (since the bit was 0 for MISO's edge), but instead, it read in 0xAA (because it was sampling on MOSI's edge).

https://github.com/nodemcu/nodemcu-firmware/pull/1162

User avatar
rudi
Posts: 197
Joined: Fri Oct 24, 2014 7:55 pm

Re: When is SPI MISO sampled?

Postby rudi » Mon Jul 04, 2016 12:25 am

jfollas wrote:For the purpose of this post, I was referring to using the ESP as a master.

In a recent enhancement to the NodeMCU firmware, we added support for Mode 2 and Mode 3. The MOSI edge (master out, or when the ESP sets the bit from the master) is successfully set using the SPI_CK_OUT_EDGE. However, the MISO (master in, or when the ESP reads the bit from the slave) does not occur on the next clock edge as it is supposed to - instead, it seems to be happening at the same time/same edge as MOSI.

The test to illustrate the behavior had the slave set 0xAA on the SPI so that the data was valid for the MOSI clock edge, but cleared for the MISO clock edge. The ESP should have read in 0x00 based on the defined behavior for SPI (since the bit was 0 for MISO's edge), but instead, it read in 0xAA (because it was sampling on MOSI's edge).

https://github.com/nodemcu/nodemcu-firmware/pull/1162



does you have the same problem ( CPOL: 0 CPHA: 1 ) with the sampled MOSI on trailing edge?
viewtopic.php?f=7&p=7691#p7691

-------------------------------------
love it, change it or leave it.
-------------------------------------
問候飛出去的朋友遍全球魯迪

Garrettet
Posts: 1
Joined: Sat Aug 13, 2016 9:04 am

When is SPI MISO sampled

Postby Garrettet » Sun Sep 18, 2016 10:30 am

One addition,

what value do you get to data_tmp? Does the value change if you connect SPI0_MISO to GND or IOVDD?

Can you provide your complete, corrected code?

Kind regards,
- Henrik

Kallapser
Posts: 1
Joined: Sun May 07, 2017 2:10 am

When is SPI MISO sampled

Postby Kallapser » Thu May 18, 2017 1:55 pm

Wow, Im back again already, and again with my MICRO board

During an SPI conversation. I need to pause code execution after I send out a byte until the Pics MISO pin goes HIGH.

I have tried all manner of read syntax and can not seem to prove or disprove that I can read the value of this SPI data line while the SPI is active.

Can anyone tell me if this is possible and what code does this.

In an attempt to create a loop that will work without answering that question, I tried turning off the SPI, reassign pin 37 as input, loop until it goes HIGH and then turn SPI back on.

I can not even get this loop to work, any ideas?

Here is the code that should work:Code:

Who is online

Users browsing this forum: No registered users and 2 guests