Sample SPI drivers for a number of the Adesto Technologies flash devices.
Functions
spi_driver.c File Reference

Detailed Description

Definitions of spi_driver functions.

Definition in file spi_driver.c.

#include "spi_driver.h"

Go to the source code of this file.

Functions

void SPI_PinInit (uint32_t port, uint32_t pin, enum directionIO direction)
 Initializes a given pin as either an input or output. More...
 
void SPI_PinClear (uint32_t port, uint32_t pin)
 Clears a given pin on a port to LOW. More...
 
void SPI_PinSet (uint32_t port, uint32_t pin)
 Sets a given pin on a port to HIGH. More...
 
uint32_t SPI_PinRead (uint32_t port, uint32_t pin)
 Reads the voltage on a given pin. More...
 
void SPI_ConfigureSingleSPIIOs ()
 Configure the IOs for SPI bit banging usage. 4 pins are needed: CSb, SCK, MOSI, MISO. More...
 
void SPI_ReturnToSingleSPIIOs ()
 Returns MISO and MOSI pins to their standard SPI state as an input and output. More...
 
void SPI_ConfigureDualSPIIOsInput ()
 Configures SPIO IOs for dual input. This changes the MOSI pin from an output to an input so that the slave can drive both SI and SO. More...
 
void SPI_ConfigureQuadSPIIOsInput ()
 Configures SPIO IOs for quad input. This changes the MOSI, WPb, and HOLDb pins to inputs so that the slave can drive all 4 IOs. More...
 
void SPI_ConfigureDualSPIIOsOutput ()
 Configures SPIO IOs for dual output. This changes the MISO pin from an input to an output so that the master can drive both SI and SO. More...
 
void SPI_ConfigureQuadSPIIOsOutput ()
 Configures SPIO IOs for quad output. This changes the MISO pin to an output so that the master can drive all 4 IOs. More...
 
void SPI_Delay (uint32_t delayTime)
 Performs a delayTime number of NOPs. More...
 
void SPI_ClockTick ()
 Toggles the clock: current_state->high->low. More...
 
void SPI_SendBit (uint8_t transmittedBit)
 Sends a single bit along MOSI while toggling the clock. More...
 
void SPI_SendByte (uint8_t transmittedByte)
 Sends a byte along MOSI. More...
 
void SPI_DualSendByte (uint8_t transmittedByte)
 Sends a byte along both MOSI and MISO. More...
 
void SPI_QuadSendByte (uint8_t transmittedByte)
 Sends a byte along MISO, MOSI, WPb, and HOLDb. More...
 
uint8_t SPI_ReceiveByte ()
 Receives a byte along MISO and returns the value received. More...
 
uint8_t SPI_DualReceiveByte ()
 Receives a byte along both MOSI and MISO and returns the value received. More...
 
uint8_t SPI_QuadReceiveByte ()
 Receives a byte along MOSI, MISO, HOLDb, and WPb and returns the value received. More...
 
void SPI_Exchange (uint8_t *txBuffer, uint32_t txNumBytes, uint8_t *rxBuffer, uint32_t rxNumBytes, uint32_t dummyNumBytes)
 Sends and receives bytes based on the function parameters. MISO and MOSI fill their standard SPI roles. More...
 
void SPI_DualExchange (uint8_t standardSPINumBytes, uint8_t *txBuffer, uint32_t txNumBytes, uint8_t *rxBuffer, uint32_t rxNumBytes, uint32_t dummyNumBytes)
 Sends and receives bytes based on the function parameters. MOSI is used for the opcode and address, then MISO or MOSI are switched for transmission and receiving such that data is transmitted from/to the flash device along both lines. Their state will then be reverted to original SPI functionality. More...
 
void SPI_QuadExchange (uint8_t standardSPINumBytes, uint8_t *txBuffer, uint32_t txNumBytes, uint8_t *rxBuffer, uint32_t rxNumBytes, uint32_t dummyNumBytes)
 Sends and receives bytes based on the function parameters. MOSI can used for the opcode and address, then MISO, MOSI, HOLDb, WPb are switched for transmission and receiving such that data is transmitted from/to the flash device along all 4 lines. Their state will then be reverted to original SPI functionality. More...
 
void SPI_Trigger ()
 Triggers a falling edge on the SPI_TRIGGER_PORT/PIN output. More...
 
void SPI_JEDECReset ()
 Performs a JEDEC reset on the SPI device. More...
 

Function Documentation

◆ SPI_ClockTick()

void SPI_ClockTick ( )

Toggles the clock: current_state->high->low.

Return values
void

Definition at line 149 of file spi_driver.c.

◆ SPI_ConfigureDualSPIIOsInput()

void SPI_ConfigureDualSPIIOsInput ( )

Configures SPIO IOs for dual input. This changes the MOSI pin from an output to an input so that the slave can drive both SI and SO.

Return values
void
Warning
Make sure to reconfigure the SPIIOs using SPI_ReturnToSingleSPIIOs() when this is no longer needed.

Definition at line 101 of file spi_driver.c.

◆ SPI_ConfigureDualSPIIOsOutput()

void SPI_ConfigureDualSPIIOsOutput ( )

Configures SPIO IOs for dual output. This changes the MISO pin from an input to an output so that the master can drive both SI and SO.

Return values
void
Warning
Make sure to reconfigure the SPIIOs using SPI_ReturnToSingleSPIIOs() when this is no longer needed.

Definition at line 121 of file spi_driver.c.

◆ SPI_ConfigureQuadSPIIOsInput()

void SPI_ConfigureQuadSPIIOsInput ( )

Configures SPIO IOs for quad input. This changes the MOSI, WPb, and HOLDb pins to inputs so that the slave can drive all 4 IOs.

Return values
void
Warning
Make sure to reconfigure the SPIIOs using SPI_ReturnToSingleSPIIOs() when this is no longer needed.

Definition at line 108 of file spi_driver.c.

◆ SPI_ConfigureQuadSPIIOsOutput()

void SPI_ConfigureQuadSPIIOsOutput ( )

Configures SPIO IOs for quad output. This changes the MISO pin to an output so that the master can drive all 4 IOs.

Return values
void
Warning
Make sure to reconfigure the SPIIOs using SPI_ReturnToSingleSPIIOs() when this is no longer needed.

Definition at line 128 of file spi_driver.c.

◆ SPI_ConfigureSingleSPIIOs()

void SPI_ConfigureSingleSPIIOs ( )

Configure the IOs for SPI bit banging usage. 4 pins are needed: CSb, SCK, MOSI, MISO.

Return values
void
Warning
Moneta and Dataflash shields differ. Moneta uses PTD4 for CSb, while Dataflash uses PTC2-8.
Only call this function once at the beginning of the program to configure the IOs. Calling this function a second time will cause CSb to go low temporarily if it was high. Use SPI_ReturnToSingleSPIIOs() if a return to single SPI is required mid program.

Definition at line 61 of file spi_driver.c.

◆ SPI_Delay()

void SPI_Delay ( uint32_t  delayTime)

Performs a delayTime number of NOPs.

Parameters
delayTimeThe number of NOPs to be run.
Return values
void

Definition at line 140 of file spi_driver.c.

◆ SPI_DualExchange()

void SPI_DualExchange ( uint8_t  standardSPINumBytes,
uint8_t *  txBuffer,
uint32_t  txNumBytes,
uint8_t *  rxBuffer,
uint32_t  rxNumBytes,
uint32_t  dummyNumBytes 
)

Sends and receives bytes based on the function parameters. MOSI is used for the opcode and address, then MISO or MOSI are switched for transmission and receiving such that data is transmitted from/to the flash device along both lines. Their state will then be reverted to original SPI functionality.

Parameters
standardSPINumBytesThe number of bytes to be sent in standard single SPI mode. Note: Dummy bytes will be sent in standard single SPI mode.
*txBufferA pointer to the tx byte array to be transmitted. Should have tx_bytes elements.
txNumBytesThe total number of bytes to be transmitted including those in standard SPI.
*rxBufferA pointer to the rx byte array where received data will be stored. Should have rx_bytes elements.
rxNumBytesThe number of bytes to be received.
dummyNumBytesThe number of dummy bytes to be sent.
Return values
void

Definition at line 355 of file spi_driver.c.

◆ SPI_DualReceiveByte()

uint8_t SPI_DualReceiveByte ( )

Receives a byte along both MOSI and MISO and returns the value received.

Return values
uint8_tThe byte received in Little Endian format.

Definition at line 268 of file spi_driver.c.

◆ SPI_DualSendByte()

void SPI_DualSendByte ( uint8_t  transmittedByte)

Sends a byte along both MOSI and MISO.

Parameters
transmittedByteByte to be sent.
Return values
void

Definition at line 180 of file spi_driver.c.

◆ SPI_Exchange()

void SPI_Exchange ( uint8_t *  txBuffer,
uint32_t  txNumBytes,
uint8_t *  rxBuffer,
uint32_t  rxNumBytes,
uint32_t  dummyNumBytes 
)

Sends and receives bytes based on the function parameters. MISO and MOSI fill their standard SPI roles.

Parameters
*txBufferA pointer to the tx byte array to be transmitted. Should have tx_bytes elements.
txNumBytesThe number of bytes to be transmitted.
*rxBufferA pointer to the rx byte array where received data will be stored. Should have rx_bytes elements.
rxNumBytesThe number of bytes to be received.
dummyNumBytesThe number of dummy bytes to be sent.
Return values
void

Definition at line 325 of file spi_driver.c.

◆ SPI_JEDECReset()

void SPI_JEDECReset ( )

Performs a JEDEC reset on the SPI device.

Return values
void
Warning
There must be a short, user inserted, delay after resetting with a JEDEC reset.

Definition at line 492 of file spi_driver.c.

◆ SPI_PinClear()

void SPI_PinClear ( uint32_t  port,
uint32_t  pin 
)

Clears a given pin on a port to LOW.

Parameters
portThe port number.
pinThe pin number.
Return values
void

Definition at line 47 of file spi_driver.c.

◆ SPI_PinInit()

void SPI_PinInit ( uint32_t  port,
uint32_t  pin,
enum directionIO  direction 
)

Initializes a given pin as either an input or output.

Parameters
portThe port number. The type must be redefined based on the GPIO driver being used.
pinThe pin number.
directionINPUT or OUTPUT. See the directionIO enum type.
Return values
void

Definition at line 43 of file spi_driver.c.

◆ SPI_PinRead()

uint32_t SPI_PinRead ( uint32_t  port,
uint32_t  pin 
)

Reads the voltage on a given pin.

Parameters
portThe port number.
pinThe pin number.
Return values
32-bitword, 0 = LOW, 1 = HIGH.

Definition at line 56 of file spi_driver.c.

◆ SPI_PinSet()

void SPI_PinSet ( uint32_t  port,
uint32_t  pin 
)

Sets a given pin on a port to HIGH.

Parameters
portThe port number.
pinThe pin number.
Return values
void

Definition at line 51 of file spi_driver.c.

◆ SPI_QuadExchange()

void SPI_QuadExchange ( uint8_t  standardSPINumBytes,
uint8_t *  txBuffer,
uint32_t  txNumBytes,
uint8_t *  rxBuffer,
uint32_t  rxNumBytes,
uint32_t  dummyNumBytes 
)

Sends and receives bytes based on the function parameters. MOSI can used for the opcode and address, then MISO, MOSI, HOLDb, WPb are switched for transmission and receiving such that data is transmitted from/to the flash device along all 4 lines. Their state will then be reverted to original SPI functionality.

Parameters
standardSPINumBytesThe number of bytes to be sent in standard single SPI mode. Note: Dummy bytes will be sent in standard single SPI mode based on the input parameters.
*txBufferA pointer to the tx byte array to be transmitted. Should have tx_bytes elements.
txNumBytesThe total number of bytes to be transmitted including those in standard SPI.
*rxBufferA pointer to the rx byte array where received data will be stored. Should have rx_bytes elements.
rxNumBytesThe number of bytes to be received.
dummyNumBytesThe number of dummy bytes to be sent.
Return values
void

Definition at line 406 of file spi_driver.c.

◆ SPI_QuadReceiveByte()

uint8_t SPI_QuadReceiveByte ( )

Receives a byte along MOSI, MISO, HOLDb, and WPb and returns the value received.

Return values
uint8_tThe byte received in Little Endian format.

Definition at line 292 of file spi_driver.c.

◆ SPI_QuadSendByte()

void SPI_QuadSendByte ( uint8_t  transmittedByte)

Sends a byte along MISO, MOSI, WPb, and HOLDb.

Parameters
transmittedByteByte to be sent.
Return values
void

Definition at line 211 of file spi_driver.c.

◆ SPI_ReceiveByte()

uint8_t SPI_ReceiveByte ( )

Receives a byte along MISO and returns the value received.

Return values
uint8_tThe byte received in Little Endian format.

Definition at line 251 of file spi_driver.c.

◆ SPI_ReturnToSingleSPIIOs()

void SPI_ReturnToSingleSPIIOs ( )

Returns MISO and MOSI pins to their standard SPI state as an input and output.

Return values
void

Definition at line 85 of file spi_driver.c.

◆ SPI_SendBit()

void SPI_SendBit ( uint8_t  transmittedBit)

Sends a single bit along MOSI while toggling the clock.

Parameters
transmittedBitBit to be sent, either 1 or 0.
Return values
void

Definition at line 157 of file spi_driver.c.

◆ SPI_SendByte()

void SPI_SendByte ( uint8_t  transmittedByte)

Sends a byte along MOSI.

Parameters
transmittedByteByte to be sent.
Return values
void

Definition at line 170 of file spi_driver.c.

◆ SPI_Trigger()

void SPI_Trigger ( )

Triggers a falling edge on the SPI_TRIGGER_PORT/PIN output.

Return values
void

Definition at line 485 of file spi_driver.c.