Hardware Reference
In-Depth Information
Listing 13-9. SPI.h attachInterrupt Code
void SPIClass::attachInterrupt() {
SPCR |= _BV(SPIE);
}
Once the interruptions are turned on, you must write the callback function that will run once the SPI interrupt is
triggered. This function is
ISR (SPI_STC_vect) {}
Each function of the SPI library, as well as part of the master Arduino sketch, will need to be tested. The SPI
library has defined the following functions:
begin()
end()
setBitOrder()
setClockDivider()
setDataMode()
transfer()
The begin() function instantiates the SPI object. This test will instantiate SPI and determine if the SPI object was
created by setting the pin modes for the SPI lines and configuring the hardware SPI feature in master mode.
The end() function disables the SPI configuration using the following AVR code:
SPCR &= ~_BV(SPE);
This leaves the pin modes as they were: INPUT and OUTPUT .
Given the functions in the SPI library, we can now test them in use. Listing 13-10 is the SPI master test code. The
online version provides the full test, https://github.com/ProArd/SPI_Master_test . We will look at a few of the key
test cases and examine how they work.
Listing 13-10. SPI_Master_test.ino
#include <ArduinoTestSuite.h>
#include <SPI.h>
void setup ()
{
// Serial.begin(9600);
ATS_begin("Arduino", "SPI Tests");
SPI.begin();
//Run tests
refConfig();
testTransfer();
refConfig();
testBitOrderMSB();
refConfig();
 
Search WWH ::




Custom Search