I know this protocol already. but in Arduino I need some clarification. I read a lot about SPI library in arduino site and follow the wikipedia link.
I can understand only 30% or less than 30% (when I write my lib for SPI devices That time only I can say I know SPI).
on that wikipedia linkk I got this and get confusion.
on that link have "data capture and data is output on rising edge" capture means what ?( capture means MISO data from slave and capture by master ?.)
I totally confusing now.
I am beginner in arduino SPI. So which slave device I need to choose(DS3234 RTC SPI, digital pot, IO expander, SD card, SPI EEPROM) ?.
and finally how to find the slave working modes. where it tells in slave data sheets ?. This slave device working under SPI_MODE_0 where it is in that slave data sheet.
Finally I want to write my own lib for nRF24L01. after that only I went to go for an interview. I set this goal.
I was attached the image timing diagram. Please explain step by step.
"capture means what ?( capture means MISO data from slave and capture by master ?.)"
Yes, capture by the master, MISO is clocked into a shift register by the SCK line going from Low to High (rising edge) or from High to Low (falling edge).
These are all different devices:
DS3234 RTC SPI,
digital pot,
IO expander,
SD card,
SPI EEPROM
Each will need a unique pin for a Slave Select.
Typically:
digitalWrite (slaveSelectPin1, LOW); // start talking to the selected slave
// and perform one or more SPI transfers,
// send data out to the slave:
SPI.transfer(dataByte);
// read data back
readDataIn = SPI.transfer(dummyByte); // dummyByte ignored by the slave for example, can be 0
// send a byte out on MOSI and read a byte in MISO at the same time
readSlaveData = SPI.transfer(masterDataOut);
// end the transfer
digitalWrite (slavSelectPin1, HIGH);
// go on to the next device
Slave devices may need the clock to sit Low normally, and receive data on a SCK rising edge (SPI Mode 0),
or sit Low and receive data on SCK falling edge (SPI Mode 2?)
or sit High and receive data on SCK rising edge (SPI Mode 1?)
or sit HIGH and receive data on SCK falling edge (SPI Mode 3?)
(check the Mode #s, I am not all sure I have them correct)
Many device use Mode 0, some devices use a different mode, and some are flexible about the mode being used.
Read each devices data sheet to be sure.
You can use the SPI Mode command to change as needed before sending data to a device. Just change it before you make the device's slave select active.
and finally how to find the slave working modes. where it tells in slave data sheets ?. This slave device working under SPI_MODE_0 where it is in that slave data sheet.
The data sheet for the slave device should have a timing diagram for communication with the device.
• Bit 3 – CPOL: Clock Polarity
When this bit is written to one, SCK is high when idle. When CPOL is written to zero, SCK is low
when idle. Refer to Figure 16-3 and Figure 16-4 for an example. The CPOL functionality is summarized
below:
• Bit 2 – CPHA: Clock Phase
The settings of the Clock Phase bit (CPHA) determine if data is sampled on the leading (first) or
trailing (last) edge of SCK. Refer to Figure 16-3 and Figure 16-4 for an example.
Here I am clarifying my doubts. if it ok then I will move to study the Arduino syntax.
DS3234 Dallas semiconductor. at page no 6. SPI timing Diagram.
What I understood from that diagram.
The clock is default high. so this is CPOL=1,
Data capture or transfer when the clock low to high so this is CPHA=1.
So this is Mode 3.
I am wright ?. I am understood ok. this is ok.
Second question
on this timing diagram left side master and right side slave I am wright ?.
Because I got confusing DIN and DOUT words.
Here DIN means MOSI here ?. and DOUT means MISO ?. as that diagram said like that.
the 4th line DOUT line D0-D7 comes from slave ?. Because the first timing diagram tells SPI-Read Transfer. So which means 4th line is MISO ?. D0-D7 bytes comes from slave. I am wright ?.
Third Question SPI read timing diagram.
Why the data not comes at the same time from slave to master ?.
This SPI is full duplex. But DIN A0-A6,W/R bit and then at this time DOUT is high impedance.
(my think. the DIN send the commands to slave. and the after getting the commands the slave respond so that is the reason for that high impedance).
So this is Mode 3. I am wright ?. I am understood ok. this is ok.
Yes, you have correctly identified mode 3.
Here DIN means MOSI here ?. and DOUT means MISO
Yes.
the 4th line DOUT line D0-D7 comes from slave ?. Because the first timing diagram tells SPI-Read Transfer. So which means 4th line is MISO ?. D0-D7 bytes comes from slave. I am wright ?.
Yes
Third Question SPI read timing diagram.
Why the data not comes at the same time from slave to master ?.
This SPI is full duplex. But DIN A0-A6,W/R bit and then at this time DOUT is high impedance.
(my think. the DIN send the commands to slave. and the after getting the commands the slave respond so that is the reason for that high impedance).
Yes. The ds3432 is a duplex device in that there is a MOSI and MISO line, but it is not implementing the simultaneous transfer. This slave read then send protocol is also used in spi eeproms.