How to use the SPI Library
1 Declare the SPI Hanlde, for example:SPI_HandleTypeDef hspi
2 initializing the underlying resource by implementing the Hal_spi_mspinit () function
The following two must be initialized
A enable SPI clock
b Configuring the SPI Pins
The following is initialized as needed
C NVIC Interrupt Configuration
D DMA Configuration
3 configuration Hspi, including mode, DATASIZE,BAUDRATE,MSB/LSB,CRC, etc.
4 Call the Hal_spi_init () function, initialize the SPI configuration, and the underlying resource (by calling Hal_spi_mspinit ())
Initializing and configuring functions
-
Span class= "pun"? Hal_spi_init ()
-
Span class= "pun"? Hal_spi_deinit ()
-
Span class= "pun"? Hal_spi_mspinit ()
-
Span class= "pun"? Hal_spi_mspdeinit ()
-
Span class= "pun"? hal_spi_initextended ()
Note:
In the SPI, DataSize can specify the 4-16bit data, in the SPI_DR register, whether it is byte or word, data is always right-aligned, when communicating, only bits in the data word range will be output with the clock
For example, only 0-->5 bits on the left will be output, and only 0-->13 bits on the right will be output
使用单线模式时,主机的MISO,从机的MOSI都可以作为普通IO使用。
From for notes (Wiz)
Hal Drive Library Learning-spi