GlobLib
HAL and API libraries for MCUs and hardware.
stm32f103cb_spi.h
Go to the documentation of this file.
1 #ifndef STM32F103CB_SPI_H_
2 #define STM32F103CB_SPI_H_
3 
36 #include "stm32f103cb_gpio.h"
37 #include "stm32f103cb_debug.h"
38 #include "stm32f103cb_clock.h"
39 #include <libopencm3/stm32/f1/spi.h>
40 #include <stdint.h>
41 
42 #define SPI_DEFAULT_SPEED SPI_SPEED_8
43 #define SPI_DEFAULT_CLOCK SPI_CLOCK_HIGH
44 #define SPI_DEFAULT_PHASE SPI_PHASE_SECOND
45 #define SPI_DEFAULT_DATA SPI_DATA_8
46 #define SPI_DEFAULT_ENDIAN SPI_MSB
47 
48 
51 typedef uint16_t (*spi_u16_fp_v)(void);
55 typedef void (*spi_v_fp_u16)(uint16_t);
56 
60 typedef enum{
61 
64 }spi_periph;
65 
72 typedef enum{
73 
74  SPI_SPEED_025 = 250000,
75  SPI_SPEED_05 = 500000,
76  SPI_SPEED_1 = 1000000,
77  SPI_SPEED_4 = 4000000,
78  SPI_SPEED_8 = 8000000,
79  SPI_SPEED_16 = 16000000,
80  SPI_SPEED_32 = 32000000,
81 
82 }spi_speed;
83 
87 typedef enum{
88 
91 }spi_clock;
92 
96 typedef enum{
97 
100 
101 }spi_data;
102 
106 typedef enum{
107 
110 
111 }spi_endian;
112 
118 typedef enum{
119 
122 
123 }spi_phase;
129 typedef enum{
130 
133 }spi_csPol;
134 
218 mcu_error SPI_put(spi_periph periph, uint16_t data);
226 uint16_t SPI_get(spi_periph periph);
237 mcu_error SPI_enableTxISR(spi_periph periph, void(*handler)(void));
251 mcu_error SPI_enableRxISR(spi_periph periph, void(*handler)(uint16_t));
282 void SPI_write(spi_periph periph, gpio_port port, gpio_pin pin,
283  spi_csPol polarity, uint16_t address, uint16_t data);
294 void SPI_repeatWrite(spi_periph periph, gpio_port port, gpio_pin pin,
295  spi_csPol polarity, uint16_t address, uint16_t *data, uint16_t count);
305 uint16_t SPI_read(spi_periph periph, gpio_port port, gpio_pin pin,
306  spi_csPol polarity, uint16_t address);
318 void SPI_repeatRead(spi_periph periph, gpio_port port, gpio_pin pin,
319  spi_csPol polarity, uint16_t address, uint16_t *data, uint16_t count);
320 
323 #endif
gpio_port
GPIO ports available for the MCU.
mcu_error SPI_setClockPolarity(spi_periph periph, spi_clock polarity)
Sets the polarity of the clock during the idle state.
The second SPI peripheral.
mcu_error SPI_setDataFrame(spi_periph periph, spi_data data)
Sets the size of the data frame for one transmission.
Header file for stm32f103cb DEBUG.
Header file for stm32f103 GPIO.
mcu_error SPI_enableTxISR(spi_periph periph, void(*handler)(void))
Enable the peripheral&#39;s transmit interrupt.
spi_speed
Clock rates for the serial clock.
spi_u16_fp_v SPI_getGetAdd(spi_periph periph)
Get the function address of the get function for the port.
spi_v_fp_u16 SPI_getPutAdd(spi_periph periph)
Get the function address of the put function for the port.
One data frame is 16 bits.
One data frame is 8 bits.
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.
Clock is low when idle.
Captured on first transition.
spi_clock
The idle state the clock line is left with no activity.
Maximum 32MHz serial clock.
Captured on second transition.
Maximum 4MHz serial clock.
mcu_error SPI_setPhase(spi_periph periph, spi_phase phase)
Sets the phase of the clock.
void(* spi_v_fp_u16)(uint16_t)
Funtion point typedef for void(*fp)(uint8_t)
spi_data
The number of data bits send in one transmission.
gpio_pin
GPIO pins available for each port.
spi_csPol
The polarity of the chip select pin.
mcu_error SPI_setSpeed(spi_periph periph, spi_speed speed)
Sets the speed of the serial clock.
mcu_error SPI_enableRxISR(spi_periph periph, void(*handler)(uint16_t))
Enable the peripheral&#39;s receive interrupt.
Data is sent MSB first.
Maximum 500KHz serial clock.
mcu_error SPI_setEndian(spi_periph periph, spi_endian endian)
Sets order of the transmitted data frame.
mcu_error SPI_disableTxISR(spi_periph periph)
Disable the peripheral&#39;s transmit interrupt.
spi_endian
Byte order for send data.
Maximum 8MHz serial clock.
Chip select pin is active high.
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.
Chip select pin is active low.
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.
mcu_error SPI_setup(spi_periph periph)
Sets up the SPI peripheral with standard setting doneted with macro defines.
uint16_t SPI_get(spi_periph periph)
Recieve a byte from the recieve buffer. (blocking)
Clock is high when idle.
Data is sent LSB first.
Header file for stm32f103 CLOCK.
Maximum 1MHz serial clock.
The first SPI peripheral.
spi_phase
The phase at which the data is captured on the clock line.
mcu_error SPI_disableRxISR(spi_periph periph)
Disable the peripheral&#39;s receive interrupt.
Maximum 16MHz serial clock.
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.
spi_periph
Peripheral SPI ports available.
Maximum 250KHz serial clock.
uint16_t(* spi_u16_fp_v)(void)
Funtion point typedef for void(*fp)(void)
mcu_error SPI_put(spi_periph periph, uint16_t data)
Send one data frame on the data bus. (blocking)
mcu_error
Error enumerators for the Debug peripheral.