This module provides a basic interface to the microcontroller SPI in master mode. It utilizes an interrupt service routine to clock out the SPI data asynchronously.
To use the SPI module, place the following in your source files:
#include <spi2.h>
This function places the SPI into “master” mode, enables the SPI, and enables the SPI interrupt. The library provides the required interrupt service routine.
This function returns true if the SPI module is busy clocking SPI data. While the SPI module is busy, spi2_send_byte() and spi2_send_data() will do nothing and will return false.
This function begins an asynchronous SPI exchange of one byte. The data to transmit is the byte pointed to by b. If done_flag is not NULL, when the exchange is complete, the interrupt service routine sets this flag to true. After the exchange, the byte pointed to by b will contain the received byte.
While the module is busy exchanging the byte, it is important that the location pointed to by b remain valid. For example, it would be an error if b points to a location on the stack that goes out of scope while the exchange is taking place.
This function begins an asynchronous SPI exchange of s bytes of the data pointed to by d. If done_flag is not NULL, when the exchange is complete, the interrupt service routine sets this flag to true. After the exchange, the data pointed to by d will contain the received data.
While the module is busy exchanging the byte, it is important that the location pointed to by d remain valid. For example, it would be an error if d points location on the stack that goes out of scope while the exchange is taking place.