Question.5
What number will be printed on Arduino2’s serial monitor? (after executing the following code)
Arduino1 (master) code:
#include <SPI.h>
void setup() {
SPI.begin();
delay(2000);
}
void loop() {
for(uint32_t i = 0; i < 10; i++) {
digitalWrite(SS, LOW);
delay(10);
digitalWrite(SS, HIGH);
}
while (1);
}
Arduino2 (slave) code:
#include <SPI.h>
uint32_t count = 0;
uint32_t start_ms = 0;
void setup() {
Serial.begin(115200);
pinMode(MISO, OUTPUT);
SPCR |= _BV(SPE);
pinMode(SS, INPUT_PULLUP);
SPI.attachInterrupt();
start_ms = millis();
}
void loop() {
if (millis() - start_ms > 10000) {
Serial.println(count);
while (1);
}
}
ISR(SPI_STC_vect) {
count++;
}