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.
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).
The code makes more sense for me now :)