void loop() { // create a buffer and intialize each element unsigned char buf[2]; buf[0] = 0xFF; buf[1] = 0x00; // write the two bytes in the buffer to the SPI port spi.write(buf,2); }
#include <SPI.h>
Public Member Functions | |
SPI (unsigned char timeout=SPI_TIMEOUT, unsigned char mosi_pin=NB1A_MOSI_PIN, unsigned char miso_pin=NB1A_MISO_PIN, unsigned char sck_pin=NB1A_SCK_PIN) | |
void | init (unsigned char spcr, unsigned char spsr) |
char | write (unsigned char *data, unsigned char num_chars) |
char | read (unsigned char *data, unsigned char max_num_chars) |
Serial Peripheral Interface (SPI) Class
Definition at line 27 of file SPI.h.
SPI::SPI | ( | unsigned char | timeout = SPI_TIMEOUT , |
|
unsigned char | mosi_pin = NB1A_MOSI_PIN , |
|||
unsigned char | miso_pin = NB1A_MISO_PIN , |
|||
unsigned char | sck_pin = NB1A_SCK_PIN | |||
) |
Constructor for the SPI Class.
The pin assignments for the SPI port need to be passed to the constructor. The pin numbers need to be Arduino (or Sanguino) pin numbers since initialization is performed using pinMode and digitalWrite commands. The default values are for the wiblocks NB1A board. Constants for the NB2A board (which is Sanguino compatible) are defined in the header file.
No hardware is initialized by the constructor. A call to Init is required to initialize the pins and setup the control register (SPCR) and the status register (SPSR).
[in] | timeout | number of milliseconds to wait for the SPI port to complete transmission. the default value is 10mS. |
[in] | mosi_pin | the pin number of the MOSI pin. |
[in] | miso_pin | the pin number of the MISO pin. |
[in] | sck_pin | the pin number of the SCK pin. |
void SPI::init | ( | unsigned char | spcr, | |
unsigned char | spsr | |||
) |
char SPI::read | ( | unsigned char * | data, | |
unsigned char | max_num_chars | |||
) |
char SPI::write | ( | unsigned char * | data, | |
unsigned char | num_chars | |||
) |