Go Down

Topic: SPI.transfer(-1) behavior (Read 898 times) previous topic - next topic


Aug 06, 2012, 10:41 am Last Edit: Aug 06, 2012, 11:06 am by nemalk Reason: 1
Hi all,

I started playing around with a SPI real time clock board a (DS3234 from Sparkfun) and downloaded some libraries.

I am trying to figure out how the functions implemented actually works so I can customize/tweak them for my own need.

Can somebody explain to me what the instrution SPI.transfer(-1) is doing? Is it some kind of shift in the byte to read/write.


Tom Carpenter

It sends the value 255 over the SPI, and returns a byte from the selected slave.

When you want to read something from a slave device, the master has to put 8 clock cycles onto the SCLK line to time the date coming from the device. To do this you send a dummy byte and read in the response. Usually the dummy byte is either 255 (-1) or 0.

Some devices use full duplex, so every byte you send, you recieve a valid byte at the same time, but in this case, I think it is half duplex (master sends dummy bytes to read in from the slave).


Thanks Tom.

The code makes more sense for me now  :)

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131