peekSPI()
[Serial Peripheral Interface]
unsigned char peekSPI();Description
Peeks at the data from the follower chip contained in the buffer.
Parameters
None.
Returns
The next byte received from the follower chip without removing it 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, peek the data and check if it is different from 0, finally 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() && peekSPI()) { // 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
peekSPI()is called when no data is available, the function will return 0. - The return value of the function
peekSPI()is an integer between 0 and 255 or anunsigned char.
