Hardware Reference
In-Depth Information
The test in Listing 13-13 is a testing condition for when the clock divider is set to twice the speed of the slave
device. This type of test is expected to fail. The code is written to discover the failure and report a completed test. A true
result is reported as a pass. The parentheses are used to indicate that the test is OK even though failure was expected.
setDataMode() Test
The data mode configures the clock phase and the polarity. For this to be tested, each mode must be set, and the slave
Arduino must send a piece of data that shows that it was received and returned properly, as shown in Listing 13-14.
Listing 13-14. SetDataMode Test for SPI_MODE0
void testDataMode()
{
boolean result = false;
byte spireturn;
//SPI_MODE0 test 3
setSlaveDataMode(SPI_MODE0);
SPI.setDataMode(SPI_MODE0);
spireturn = SPI.transfer(0x02);
if (spireturn > 0)
{
result = true;
}
ATS_PrintTestStatus("3. setDataMode: SPI_MODE0", result);
}
The test in Listing 13-14 will return a TRUE result if you can communicate with the slave device in that mode.
If a configuration or communication error occurs, it will fail.
SPI Test Results
In conclusion, the complete set of test runs shows that the expected configuration of the master and slave match.
The commands that are issued must be valid configurations of SPI in order to work correctly. If we change the
slave configuration, we have to change the master test, or else we will see expected failures due to mismatched
configurations.
There are many test cases within each of these variations. The full source for this on the Pro Arduino SPGitHub
repository, http://github.com/proardwebsite goes through many more test cases, each with a single change from
the last one. Another good challenge for SPI testing would be to reconfigure the slave device to iterate through each of
its configurations. Creating these tests proves that SPI is working and simultaneously gives you a chance to learn how
SPI works.
Summary
This chapter describes the features and benefits of the Arduino Test Suite. The goal is to show how to move from
creating examples that demonstrate your code to creating a test that verifies it. Not only is this good for code quality,
but it allows you to make custom circuits, shields, and your own verified Arduino-inspired device. As you share your
code and hardware with others, testing provides usage examples and behavior confirmation.
The challenge of creating testable conditions is not simple. The environment of the project must be included,
and users are encouraged to submit their tests to the Arduino testing project on GitHub. This ensures that the entire
platform is well tested and documented, and provides a high-quality user experience.
 
Search WWH ::




Custom Search