Contiki-Inga 3.x
Macros | Functions
Master SPI Bus Driver (MSPI)

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 mspi_mgr_add (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 mspi_mgr_change_mode (spi_dev new_config)
 This function changes the SPI configuration. More...
 

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 144 of file mspi.h.

#define MSPI_BAUD_2MBPS   (0x01)

2Mbps MSPI Baud Rate

Note
Assumption: f_osc = 8 MHz

Definition at line 139 of file mspi.h.

Referenced by sdcard_init().

#define MSPI_BAUD_MAX   (0x00)

Maximum MSPI Baud Rate [bps]

Note
The maximum baud rate is f_osc/2

Definition at line 134 of file mspi.h.

Referenced by adxl345_available(), at45db_init(), and mpl115a_init().

#define MSPI_BUS_MANAGER   1

Enable or disable the MSPI-Bus Manager.

Note
The...

Definition at line 66 of file mspi.h.

#define MSPI_MODE_0   (0x00)

MSPI Mode 0

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

Definition at line 100 of file mspi.h.

Referenced by mpl115a_init(), and sdcard_init().

#define MSPI_MODE_1   (0x02)

MSPI Mode 1

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

Definition at line 108 of file mspi.h.

#define MSPI_MODE_2   (0x01)

MSPI Mode 2

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

Definition at line 116 of file mspi.h.

#define MSPI_MODE_3   (0x03)

MSPI Mode 3

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

Definition at line 124 of file mspi.h.

Referenced by adxl345_available(), and at45db_init().

Function Documentation

void mspi_chip_release ( uint8_t  cs)
void mspi_chip_select ( uint8_t  cs)
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 109 of file mspi.c.

References mspi_mgr_add().

Referenced by adxl345_available(), at45db_init(), mpl115a_init(), and sdcard_init().

void mspi_mgr_add ( 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 187 of file mspi.c.

Referenced by mspi_init().

void mspi_mgr_change_mode ( spi_dev  new_config)

This function changes the SPI configuration.

Parameters
spi_devThe specified entry of the SPI Device Table

Definition at line 195 of file mspi.c.

Referenced by mspi_chip_select().

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 152 of file mspi.c.

Referenced by adxl345_get(), 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(), mpl115a_cmd(), sdcard_init(), sdcard_read_block(), sdcard_read_csd(), sdcard_write_block(), sdcard_write_cmd(), sdcard_write_multi_block_next(), and sdcard_write_multi_block_stop().