Add simple SPI slave example
This commit is contained in:
parent
45b51dea12
commit
6e814ad5ca
|
@ -9,14 +9,11 @@
|
||||||
|
|
||||||
void setupSPI(void)
|
void setupSPI(void)
|
||||||
{
|
{
|
||||||
pinMode(PA7, INPUT); // MOSI1
|
// MOSI, MISO, SCK PINs are set by the library
|
||||||
pinMode(PA6, INPUT); // MISO1
|
|
||||||
pinMode(PA5, INPUT); // SCK
|
|
||||||
pinMode(BOARD_SPI_DEFAULT_SS, INPUT); // SS
|
pinMode(BOARD_SPI_DEFAULT_SS, INPUT); // SS
|
||||||
|
|
||||||
// Select SPI1
|
|
||||||
SPI.setModule(1);
|
|
||||||
// The clock value is not used
|
// The clock value is not used
|
||||||
|
// SPI1 is selected by default
|
||||||
SPI.beginTransactionSlave(SPISettings(18000000, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT));
|
SPI.beginTransactionSlave(SPISettings(18000000, MSBFIRST, SPI_MODE0, DATA_SIZE_8BIT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,9 +21,6 @@ void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
// Data that master will receive when transferring a data frame over SPI
|
|
||||||
SPI.dev()->regs->DR = 0;
|
|
||||||
setupSPI();
|
setupSPI();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,13 +28,12 @@ uint8_t count(0);
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// Blocking call to read SPI message
|
// Blocking call to read SPI message
|
||||||
uint8_t msg(SPI.read());
|
uint8_t msg = SPI.transfer(++count);
|
||||||
Serial.print("Received = 0b");
|
Serial.print("a Received = 0b");
|
||||||
Serial.print(msg, BIN);
|
Serial.print(msg, BIN);
|
||||||
Serial.print(", 0x");
|
Serial.print(", 0x");
|
||||||
Serial.print(msg, HEX);
|
Serial.print(msg, HEX);
|
||||||
Serial.print(", ");
|
Serial.print(", ");
|
||||||
Serial.println(msg);
|
Serial.println(msg);
|
||||||
// Next data frame that will be received by master
|
|
||||||
SPI.dev()->regs->DR = ++count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue