GlobLib
HAL and API libraries for MCUs and hardware.
|
This module contains low level functions for the SPI bus. More...
Files | |
file | stm32f103cb_spi.h |
Header file for stm32f103cb SPI. | |
Macros | |
#define | SPI_DEFAULT_SPEED SPI_SPEED_8 |
Serial clock rate. | |
#define | SPI_DEFAULT_CLOCK SPI_CLOCK_HIGH |
Clock reset state. | |
#define | SPI_DEFAULT_PHASE SPI_PHASE_SECOND |
Clock capture edge relative to clock. | |
#define | SPI_DEFAULT_DATA SPI_DATA_8 |
Data frame size. | |
#define | SPI_DEFAULT_ENDIAN SPI_MSB |
Data frame order. | |
Typedefs | |
typedef uint16_t(* | spi_u16_fp_v) (void) |
Funtion point typedef for void(*fp)(void) | |
typedef void(* | spi_v_fp_u16) (uint16_t) |
Funtion point typedef for void(*fp)(uint8_t) | |
Enumerations |
Functions | |
mcu_error | SPI_setup (spi_periph periph) |
Sets up the SPI peripheral with standard setting doneted with macro defines. More... | |
mcu_error | SPI_setSpeed (spi_periph periph, spi_speed speed) |
Sets the speed of the serial clock. More... | |
mcu_error | SPI_setClockPolarity (spi_periph periph, spi_clock polarity) |
Sets the polarity of the clock during the idle state. More... | |
mcu_error | SPI_setDataFrame (spi_periph periph, spi_data data) |
Sets the size of the data frame for one transmission. More... | |
mcu_error | SPI_setEndian (spi_periph periph, spi_endian endian) |
Sets order of the transmitted data frame. More... | |
mcu_error | SPI_setPhase (spi_periph periph, spi_phase phase) |
Sets the phase of the clock. More... | |
spi_u16_fp_v | SPI_getGetAdd (spi_periph periph) |
Get the function address of the get function for the port. More... | |
spi_v_fp_u16 | SPI_getPutAdd (spi_periph periph) |
Get the function address of the put function for the port. More... | |
mcu_error | SPI_put (spi_periph periph, uint16_t data) |
Send one data frame on the data bus. (blocking) More... | |
uint16_t | SPI_get (spi_periph periph) |
Recieve a byte from the recieve buffer. (blocking) More... | |
mcu_error | SPI_enableTxISR (spi_periph periph, void(*handler)(void)) |
Enable the peripheral's transmit interrupt. More... | |
mcu_error | SPI_enableRxISR (spi_periph periph, void(*handler)(uint16_t)) |
Enable the peripheral's receive interrupt. More... | |
mcu_error | SPI_disableTxISR (spi_periph periph) |
Disable the peripheral's transmit interrupt. More... | |
mcu_error | SPI_disableRxISR (spi_periph periph) |
Disable the peripheral's receive interrupt. More... | |
void | SPI_write (spi_periph periph, gpio_port port, gpio_pin pin, spi_csPol polarity, uint16_t address, uint16_t data) |
Write a data frame to a slave device using standard protocole. More... | |
void | SPI_repeatWrite (spi_periph periph, gpio_port port, gpio_pin pin, spi_csPol polarity, uint16_t address, uint16_t *data, uint16_t count) |
Write multiple data frames to a slave device using standard protocole. More... | |
uint16_t | SPI_read (spi_periph periph, gpio_port port, gpio_pin pin, spi_csPol polarity, uint16_t address) |
Read a data frame from the slave device using standard protocole. More... | |
void | SPI_repeatRead (spi_periph periph, gpio_port port, gpio_pin pin, spi_csPol polarity, uint16_t address, uint16_t *data, uint16_t count) |
Read multiple data frames from the slave device using standard protocole. More... | |
This module contains low level functions for the SPI bus.
enum spi_clock |
The idle state the clock line is left with no activity.
Enumerator | |
---|---|
SPI_CLOCK_LOW |
Clock is low when idle. |
SPI_CLOCK_HIGH |
Clock is high when idle. |
Definition at line 87 of file stm32f103cb_spi.h.
enum spi_csPol |
The polarity of the chip select pin.
This is used by SPI_write(), SPI_read(), SPI_repeatWrite() and SPI_repeatRead()
Enumerator | |
---|---|
SPI_CS_LOW |
Chip select pin is active low. |
SPI_CS_HIGH |
Chip select pin is active high. |
Definition at line 129 of file stm32f103cb_spi.h.
enum spi_data |
The number of data bits send in one transmission.
Enumerator | |
---|---|
SPI_DATA_8 |
One data frame is 8 bits. |
SPI_DATA_16 |
One data frame is 16 bits. |
Definition at line 96 of file stm32f103cb_spi.h.
enum spi_endian |
Byte order for send data.
Enumerator | |
---|---|
SPI_LSB |
Data is sent LSB first. |
SPI_MSB |
Data is sent MSB first. |
Definition at line 106 of file stm32f103cb_spi.h.
enum spi_periph |
Peripheral SPI ports available.
Enumerator | |
---|---|
SPI_1 |
The first SPI peripheral. |
SPI_2 |
The second SPI peripheral. |
Definition at line 60 of file stm32f103cb_spi.h.
enum spi_phase |
The phase at which the data is captured on the clock line.
This value is relative to the clock idle line, so SPI_CLOCK_HIGH with SPI_PHASE_FIRST will capture data on the falling edge.
Enumerator | |
---|---|
SPI_PHASE_FIRST |
Captured on first transition. |
SPI_PHASE_SECOND |
Captured on second transition. |
Definition at line 118 of file stm32f103cb_spi.h.
enum spi_speed |
Clock rates for the serial clock.
These rates control the clock divisor applied between the main clock and the serial clock. These rates are tried to met as accurately as possible, but will not be exceeded.
Definition at line 72 of file stm32f103cb_spi.h.
mcu_error SPI_disableRxISR | ( | spi_periph | periph | ) |
Disable the peripheral's receive interrupt.
periph | The port to modify |
Definition at line 198 of file stm32f103cb_spi.c.
mcu_error SPI_disableTxISR | ( | spi_periph | periph | ) |
Disable the peripheral's transmit interrupt.
periph | The port to modify |
Definition at line 159 of file stm32f103cb_spi.c.
mcu_error SPI_enableRxISR | ( | spi_periph | periph, |
void(*)(uint16_t) | handler | ||
) |
Enable the peripheral's receive interrupt.
The given function is called when a data frame has been received.
periph | The port to modify |
handler | The function to call on ISR event. |
Definition at line 126 of file stm32f103cb_spi.c.
mcu_error SPI_enableTxISR | ( | spi_periph | periph, |
void(*)(void) | handler | ||
) |
Enable the peripheral's transmit interrupt.
The given function is called when a data frame has finished being transfered along the serial line.
periph | The port to modify |
handler | The function to call on ISR event. |
Definition at line 94 of file stm32f103cb_spi.c.
uint16_t SPI_get | ( | spi_periph | periph | ) |
Recieve a byte from the recieve buffer. (blocking)
The size of the data fram is determined by SPI_setDataFrame(). Data is not returned until a full frame is received.
periph | The port to modify. |
Definition at line 577 of file stm32f103cb_spi.c.
spi_u16_fp_v SPI_getGetAdd | ( | spi_periph | periph | ) |
Get the function address of the get function for the port.
Definition at line 512 of file stm32f103cb_spi.c.
spi_v_fp_u16 SPI_getPutAdd | ( | spi_periph | periph | ) |
Get the function address of the put function for the port.
Definition at line 531 of file stm32f103cb_spi.c.
mcu_error SPI_put | ( | spi_periph | periph, |
uint16_t | data | ||
) |
Send one data frame on the data bus. (blocking)
The size of the data fram is determined by SPI_setDataFrame(). Data is not transmitted until the previous byte is sent.
periph | The port to modify |
data | The data to send |
Definition at line 549 of file stm32f103cb_spi.c.
uint16_t SPI_read | ( | spi_periph | periph, |
gpio_port | port, | ||
gpio_pin | pin, | ||
spi_csPol | polarity, | ||
uint16_t | address | ||
) |
Read a data frame from the slave device using standard protocole.
periph | The port to read from. |
port | The gpio port the chip select pin is attached to. |
pin | The gpio pin on the port for chip select. |
polarity | The polarity of the chip select pin given by spi_csPol. |
address | The address to read the data from. |
Definition at line 705 of file stm32f103cb_spi.c.
void SPI_repeatRead | ( | spi_periph | periph, |
gpio_port | port, | ||
gpio_pin | pin, | ||
spi_csPol | polarity, | ||
uint16_t | address, | ||
uint16_t * | data, | ||
uint16_t | count | ||
) |
Read multiple data frames from the slave device using standard protocole.
Data is returned in data
periph | The port to read from. |
port | The gpio port the chip select pin is attached to. |
pin | The gpio pin on the port for chip select. |
polarity | The polarity of the chip select pin given by spi_csPol. |
address | The address to read the data from. |
data | Pointer to the container to store the data. |
count | The number of data frames to read. |
Definition at line 758 of file stm32f103cb_spi.c.
void SPI_repeatWrite | ( | spi_periph | periph, |
gpio_port | port, | ||
gpio_pin | pin, | ||
spi_csPol | polarity, | ||
uint16_t | address, | ||
uint16_t * | data, | ||
uint16_t | count | ||
) |
Write multiple data frames to a slave device using standard protocole.
periph | The port to write to. |
port | The gpio port the chip select pin is attached to. |
pin | The gpio pin on the port for chip select. |
polarity | The polarity of the chip select pin given by spi_csPol. |
address | The address to send the data to. |
data | Pointer to the data to write to the bus. |
count | The number of data frames to send. |
Definition at line 655 of file stm32f103cb_spi.c.
mcu_error SPI_setClockPolarity | ( | spi_periph | periph, |
spi_clock | polarity | ||
) |
Sets the polarity of the clock during the idle state.
periph | The port to modify |
polarity | The clock polarity defined by spi_clock |
Definition at line 344 of file stm32f103cb_spi.c.
mcu_error SPI_setDataFrame | ( | spi_periph | periph, |
spi_data | data | ||
) |
Sets the size of the data frame for one transmission.
periph | The port to modify |
data | The frame size defined by spi_data |
Definition at line 388 of file stm32f103cb_spi.c.
mcu_error SPI_setEndian | ( | spi_periph | periph, |
spi_endian | endian | ||
) |
Sets order of the transmitted data frame.
periph | The port to modify |
endian | The frame order define by spi_endian |
Definition at line 431 of file stm32f103cb_spi.c.
mcu_error SPI_setPhase | ( | spi_periph | periph, |
spi_phase | phase | ||
) |
Sets the phase of the clock.
The works in conjuction with SPI_setClockPolarity(). Example: SPI_CLOCK_HIGH in combination with SPI_PHASE_SECOND will result on data being captured on the rising edge.
periph | The port to modify |
phase | The phase of the clock define by spi_phase |
Definition at line 472 of file stm32f103cb_spi.c.
mcu_error SPI_setSpeed | ( | spi_periph | periph, |
spi_speed | speed | ||
) |
Sets the speed of the serial clock.
This function attempts to match the requested speed as close as possible, without exceeding the rate specified.
periph | The port to modify |
speed | The speed desired, defined by spi_speed |
Definition at line 262 of file stm32f103cb_spi.c.
mcu_error SPI_setup | ( | spi_periph | periph | ) |
Sets up the SPI peripheral with standard setting doneted with macro defines.
periph | The port to set up. |
Definition at line 33 of file stm32f103cb_spi.c.
void SPI_write | ( | spi_periph | periph, |
gpio_port | port, | ||
gpio_pin | pin, | ||
spi_csPol | polarity, | ||
uint16_t | address, | ||
uint16_t | data | ||
) |
Write a data frame to a slave device using standard protocole.
periph | The port to write to. |
port | The gpio port the chip select pin is attached to. |
pin | The gpio pin on the port for chip select. |
polarity | The polarity of the chip select pin given by spi_csPol. |
address | The address to send the data to. |
data | The data to write to the bus. |
Definition at line 627 of file stm32f103cb_spi.c.