readSPI()
[Serial Peripheral Interface]
unsigned char readSPI();Description
Reads data from the follower chip contained in the buffer.
Parameters
None.
Returns
The next byte from the buffer.
Example Code
The code initializes the SPI communication with the clock pin connected to pin 13, the data in pin connected to pin 12, the data out pin connected to pin 11, the chip select pin connected to pin 10, and the polarity of the chip select line set to LOW.
Continuously checks if the chip is selected, and if it is, checks if the SPI bus buffer contains any data, and if it does, reads the data from the SPI bus buffer and save it into the EEPROM.
void setup() {
beginEEPROM(32); // initializes the EEPROM
beginSPI(13, 12, 11, 10, LOW); // initializes the SPI communication with the clock pin connected to pin 13, the data in pin connected to pin 12, the data out pin connected to pin 11, the chip select pin connected to pin 10, and the polarity of the chip select line set to LOW
}
void loop() {
if (selectedSPI()) { // checks if the chip is selected
if (availableSPI()) { // checks if the SPI bus buffer contains any data
writeEEPROM(1, readSPI()); // reads the data from the SPI bus buffer and save it into the EEPROM
}
}
}Notes and Warnings
- If the function
readSPI()is called when no data is available, the function will return 0. - The function
readSPI()will delete the data from the buffer after reading it, if you want to keep the data, you should store it in a variable, or call the functionpeekSPI()instead. - The return value of the function
readSPI()is an integer between 0 and 255 or anunsigned char.
