Contiki 2.5
Files | Macros | Functions | Variables
Master SPI Bus Driver (MSPI)

Files

file  mspi-drv.c
 
 MSPI driver implementation

 
file  mspi-drv.h
 
    MSPI driver definitions

 

Macros

#define MSPI_BUS_MANAGER   1
 
#define MSPI_MODE_0   (0x00)
 
#define MSPI_MODE_1   (0x02)
 
#define MSPI_MODE_2   (0x01)
 
#define MSPI_MODE_3   (0x03)
 
#define MSPI_BAUD_MAX   (0x00)
 
#define MSPI_BAUD_2MBPS   (0x01)
 
#define MSPI_BAUD_1MBPS   (0x03)
 

Functions

void mspi_init (uint8_t cs, uint8_t mode, uint16_t baud)
 Initialize the selected USART in the MSPI mode. More...
 
void mspi_chip_select (uint8_t cs)
 This function enables the chip select by setting the needed I/O pins (BCD-Code) More...
 
void mspi_chip_release (uint8_t cs)
 This function disables the chip select. More...
 
uint8_t mspi_transceive (uint8_t data)
 This function can be use either to transmit or receive data via spi. More...
 
void mspi_deinit (void)
 This function will set all MSPI registers to their default values.
 
void add_to_spi_mgr (uint8_t cs, uint8_t mode, uint16_t baud)
 This function add a device to the SPI device table and calculates the specific checksum. More...
 
void change_spi_mode (spi_dev new_config)
 This function changes the SPI configuration. More...
 

Variables

volatile uint16_t * usart_t::UBRRn
 
volatile uint8_t * usart_t::XCKn_DDR
 
volatile uint8_t usart_t::XCKn
 
volatile uint8_t * usart_t::UCSRnA
 
volatile uint8_t * usart_t::UCSRnB
 
volatile uint8_t * usart_t::UCSRnC
 
volatile uint8_t * usart_t::UDRn
 

Detailed Description

There are a lot of possibilities to realize a Serial Peripheral Interface (SPI) with the ATmega1284p, but the hardware SPI is used by the transceiver chip AT86rf230. In combination with contiki it is not possible to build up an SPI Bus with this hardware SPI. A software SPI would be a solution, but the ATmega1284p provides another opportunity. The MSPI (Maser SPI) is an alternative function of the USART. There are two independent hardware USART, so it is possible to use one for the default debug RS232 interface, while the other one is free to be used as an MSPI. The only difference between an normal SPI and the MSPI is, that MSPI only supports slaves on the bus.

Macro Definition Documentation

#define MSPI_BAUD_1MBPS   (0x03)

1Mbps MSPI Baud Rate

Note
Assumption: f_osc = 8 MHz

Definition at line 160 of file mspi-drv.h.

#define MSPI_BAUD_2MBPS   (0x01)

2Mbps MSPI Baud Rate

Note
Assumption: f_osc = 8 MHz

Definition at line 155 of file mspi-drv.h.

#define MSPI_BAUD_MAX   (0x00)

Maximum MSPI Baud Rate [bps]

Note
The maximum baud rate is f_osc/2

Definition at line 150 of file mspi-drv.h.

Referenced by adxl345_init(), at45db_init(), microSD_init(), and mpl115a_init().

#define MSPI_BUS_MANAGER   1

Enable or disable the MSPI-Bus Manager.

Note
The...

Definition at line 60 of file mspi-drv.h.

#define MSPI_MODE_0   (0x00)

MSPI Mode 0

Note
  • Leading Edge: Sample (Rising Edge)
  • Trailing Edge: Setup (Falling Edge)

Definition at line 116 of file mspi-drv.h.

Referenced by microSD_init(), and mpl115a_init().

#define MSPI_MODE_1   (0x02)

MSPI Mode 1

Note
  • Leading Edge: Setup (Rising Edge)
  • Trailing Edge: Sample (Falling Edge)

Definition at line 124 of file mspi-drv.h.

#define MSPI_MODE_2   (0x01)

MSPI Mode 2

Note
  • Leading Edge: Sample (Falling Edge)
  • Trailing Edge: Setup (Rising Edge)

Definition at line 132 of file mspi-drv.h.

#define MSPI_MODE_3   (0x03)

MSPI Mode 3

Note
  • Leading Edge: Setup (Falling Edge)
  • Trailing Edge: Sample (Rising Edge)

Definition at line 140 of file mspi-drv.h.

Referenced by adxl345_init(), and at45db_init().

Function Documentation

void add_to_spi_mgr ( uint8_t  cs,
uint8_t  mode,
uint16_t  baud 
)

This function add a device to the SPI device table and calculates the specific checksum.

Parameters
csChip Select: Device ID
modeSelect the (M)SPI mode (MSPI_MODE_0 ... MSPI_MODE_3)
baudThe MSPI BAUD rate. Sometimes it is necessary to reduce the SCK. Use MSPI_BAUD_MAX in common case.

Definition at line 106 of file mspi-drv.c.

Referenced by mspi_init().

void change_spi_mode ( spi_dev  new_config)

This function changes the SPI configuration.

Parameters
spi_devThe specified entry of the SPI Device Table

Definition at line 112 of file mspi-drv.c.

Referenced by mspi_chip_select().

void mspi_chip_release ( uint8_t  cs)
void mspi_chip_select ( uint8_t  cs)

This function enables the chip select by setting the needed I/O pins (BCD-Code)

Parameters
csChip Select: Device ID

Definition at line 67 of file mspi-drv.c.

References change_spi_mode().

Referenced by adxl345_read(), adxl345_write(), at45db_busy_wait(), at45db_erase_block(), at45db_erase_chip(), at45db_erase_page(), at45db_init(), at45db_write_cmd(), microSD_init(), microSD_write_cmd(), and mpl115a_cmd().

void mspi_init ( uint8_t  cs,
uint8_t  mode,
uint16_t  baud 
)

Initialize the selected USART in the MSPI mode.

Parameters
modeSelect the (M)SPI mode (MSPI_MODE_0 ... MSPI_MODE_3)
baudThe MSPI BAUD rate. Sometimes it is necessary to reduce the SCK. Use MSPI_BAUD_MAX in common case.

Definition at line 46 of file mspi-drv.c.

References add_to_spi_mgr().

Referenced by adxl345_init(), at45db_init(), microSD_init(), and mpl115a_init().

uint8_t mspi_transceive ( uint8_t  data)

This function can be use either to transmit or receive data via spi.

Parameters
data
  • When use this function to transmit: Data byte, which has to be transmit.
  • When use this function to receive: Data value don't care. (Dummy Byte, e.g. 0xFF)
Returns
When use this function to transmit: The return value doesn't care When use this function to receive: Received data from the spi slave
Note
The various devices along the SPI Bus are separated by the Chip Select (cs). The assignment of the SPI-devices depends on the hardware wiring. The correct chip select an spi configuration will be done by the spi-bus.manager. Otherwise please ensure, which Chip Select and spi bus configuration belong to which SPI device.

Definition at line 85 of file mspi-drv.c.

Referenced by adxl345_read(), adxl345_write(), at45db_busy_wait(), at45db_init(), at45db_read_buffer(), at45db_read_page_bypassed(), at45db_write_buffer(), at45db_write_cmd(), at45db_write_page(), microSD_init(), microSD_read_block(), microSD_write_block(), microSD_write_cmd(), and mpl115a_cmd().

Variable Documentation

volatile uint16_t* usart_t::UBRRn

MSPI Baud Rate Register (USART0/USART1)

Definition at line 167 of file mspi-drv.h.

volatile uint8_t* usart_t::UCSRnA

MSPIM Control and Status Register A (USART0/USART1)

Definition at line 179 of file mspi-drv.h.

volatile uint8_t* usart_t::UCSRnB

MSPIM Control and Status Register B (USART0/USART1)

Definition at line 183 of file mspi-drv.h.

volatile uint8_t* usart_t::UCSRnC

MSPIM Control and Status Register C (USART0/USART1)

Definition at line 187 of file mspi-drv.h.

volatile uint8_t* usart_t::UDRn

MSPI I/O Data Register (USART0/USART1)

Definition at line 191 of file mspi-drv.h.

volatile uint8_t usart_t::XCKn

MSPI Serial Clock Pin (USART0/USART1)

Definition at line 175 of file mspi-drv.h.

volatile uint8_t* usart_t::XCKn_DDR

MSPI Serial Clock Pin Data Direction Register (USART0/USART1)

Definition at line 171 of file mspi-drv.h.