It is my first time to use 3 wire - serial communication and I intend to learn. So far I understand how to write but I am not 100 percent sure about reading the serial data from the device. Thus Do you have C code example that read the data in serial transfer?
Serial data transfer , can be done synchronous or asynchronous . On asynchronous .You only need 2 wires + (soft or hardware protocol).On synchronous .there are several formats
two wires + protocol = I2C or 4 wires without protocol = SPI .As well as others
Which one is the one you are talking about ??
If you just want to read a databyte from an SPI device you must write one (dummy) databyte for every databyte you want to read.
SPI reads and writes at the same time as there are seperate datalines for IN and OUT.
See my small C example (for Microchip PIC) below.
Code:
do
{
SSPBUF=0x00; // write dummy value to start register shift
while(!STAT_BF)
WATCHDOG(); // wait until data has been received via SPI
*buffer_adresse=SSPBUF; // store data
buffer_adresse++;
}
while(--buffer_counter); // until a complete block has been read