Wiblocks --- SPI Class

SPI Library

The SPI port is a full duplex three wire interface primarily used to communicate between embedded peripherals. The ATmega168, ATmega328 and ATmega644 support speeds up to half of the clock frequency. The port is single buffered in the transmit direction and double buffered in the receive direction.

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 Class Reference

#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)

Detailed Description

Serial Peripheral Interface (SPI) Class

Definition at line 27 of file SPI.h.

Constructor & Destructor Documentation

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.
Add circular buffers for interrupt driven IO

Definition at line 33 of file SPI.cpp.

Member Function Documentation

void SPI::init ( unsigned char  spcr,
unsigned char  spsr 

Initialize the SPI control register and SPI status register.

[in] spcr SPI control register
[in] spsr SPI status register

Definition at line 51 of file SPI.cpp.

char SPI::read ( unsigned char *  data,
unsigned char  max_num_chars 

Read characters from the SPI port

[in] *data pointer to an array of characters that will receive the characters that are read.
[in] max_num_chars number of characters to read.
Write it ;)

Definition at line 96 of file SPI.cpp.

char SPI::write ( unsigned char *  data,
unsigned char  num_chars 

Write characters to the SPI port.

[in] *data pointer to an array of characters to be transmitted
[in] num_chars number of characters to be transmitted.

Definition at line 69 of file SPI.cpp.

The documentation for this class was generated from the following files: