Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| stm32:peripherals:spi [2016/09/21 11:54] – feur | stm32:peripherals:spi [2022/12/28 08:36] (current) – [SPI_CR1 Configuration register 1] ruan | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== SPI / I²S 1..6 ====== | ====== SPI / I²S 1..6 ====== | ||
| - | |||
| - | {{ spi_complete.svg? | ||
| The SPI interface offers 2 main functions: SPI and I²S (audio protocol). \\ | The SPI interface offers 2 main functions: SPI and I²S (audio protocol). \\ | ||
| - | There are a total of 6 SPI controllers which can be configured and used independently. \\ \\ | + | There are a total of 6 SPI controllers which can be configured and used independently. |
| + | |||
| + | |||
| + | \\ {{spi_complete.svg? | ||
| ===== Features ===== | ===== Features ===== | ||
| Line 14: | Line 15: | ||
| * Slave select either by hardware or software. | * Slave select either by hardware or software. | ||
| * Interrupt, CRC and DMA support. | * Interrupt, CRC and DMA support. | ||
| - | \\ | ||
| - | |||
| - | ===== Programming Example ===== | ||
| - | |||
| - | The code snippet bellow shows how to configure and use the SPI peripheral. | ||
| - | |||
| - | <code c> | ||
| - | #include " | ||
| - | |||
| - | RCC-> | ||
| - | RCC-> | ||
| - | |||
| - | /* Configure GPIO pin A.4 to A.7 in alternate function mode. */ | ||
| - | GPIOA-> | ||
| - | GPIOA-> | ||
| - | |||
| - | GPIOA-> | ||
| - | GPIOA-> | ||
| - | |||
| - | GPIOA-> | ||
| - | GPIOA-> | ||
| - | |||
| - | /* Configure SPI1 in slave mode. */ | ||
| - | SPI1-> | ||
| - | SPI1-> | ||
| - | |||
| - | SPI1-> | ||
| - | (0x1 << 6u); /* Enable SPI. */ | ||
| - | |||
| - | </ | ||
| - | \\ | ||
| - | |||
| - | > {{logo_hal.svg? | ||
| - | > [[https:// | ||
| - | > [[https:// | ||
| \\ | \\ | ||
| ===== Configuration Registers ===== | ===== Configuration Registers ===== | ||
| - | ==== CRx ==== | + | ==== SPI_CR1 - Configuration register 1 ==== |
| - | + | ||
| - | === CR1 === | + | |
| - | + | ||
| - | Configuration register 1 \\ | + | |
| (not used in I²S mode) | (not used in I²S mode) | ||
| Line 78: | Line 40: | ||
| |:::|1|Data frame: 16 bit|| | |:::|1|Data frame: 16 bit|| | ||
| - | === CR2 === | + | ==== SPI_CR2 - Configuration register 2 ==== |
| - | + | ||
| - | Configuration register 2 | + | |
| \\ {{spi_reg_cr2.svg}} \\ \\ | \\ {{spi_reg_cr2.svg}} \\ \\ | ||
| Line 96: | Line 56: | ||
| |:::|1|TX empty interrupt enabled| | |:::|1|TX empty interrupt enabled| | ||
| - | ==== CRCPR ==== | + | ==== SPI_CRCPR - CRC polynomial register |
| - | + | ||
| - | CRC polynomial register \\ | + | |
| (not used in I²S mode) | (not used in I²S mode) | ||
| Line 105: | Line 63: | ||
| Contains polynomial used to calculate CRC. Reset value: '' | Contains polynomial used to calculate CRC. Reset value: '' | ||
| - | ==== RXCRCR | + | ==== SPI_RXCRCR - RX CRC register |
| - | + | ||
| - | RX CRC register \\ | + | |
| (not used in I²S mode) | (not used in I²S mode) | ||
| Line 114: | Line 70: | ||
| Contains computed CRC value of received bytes. \\ | Contains computed CRC value of received bytes. \\ | ||
| - | ==== TXCRCR | + | ==== SPI_TXCRCR - TX CRC register |
| - | + | ||
| - | TX CRC register \\ | + | |
| (not used in I²S mode) | (not used in I²S mode) | ||
| Line 123: | Line 77: | ||
| Contains computed CRC value of transmitted bytes. \\ | Contains computed CRC value of transmitted bytes. \\ | ||
| - | ==== I2SCFGR | + | ==== SPI_I2SCFGR - I²S configuration register |
| - | + | ||
| - | I²S configuration register \\ | + | |
| (not used in SPI mode) | (not used in SPI mode) | ||
| \\ {{spi_reg_i2scfgr.svg}} \\ \\ | \\ {{spi_reg_i2scfgr.svg}} \\ \\ | ||
| - | ==== I2SPR ==== | + | ==== SPI_I2SPR - I²S prescaler register |
| - | + | ||
| - | I²S prescaler register \\ | + | |
| (not used in SPI mode) | (not used in SPI mode) | ||
| Line 139: | Line 89: | ||
| ===== Data Register ===== | ===== Data Register ===== | ||
| - | ==== DR ==== | + | ==== SPI_DR - Data register |
| - | + | ||
| - | Data register | + | |
| \\ {{spi_reg_dr.svg}} \\ \\ | \\ {{spi_reg_dr.svg}} \\ \\ | ||
| Line 150: | Line 98: | ||
| \\ | \\ | ||
| - | ===== Legend | + | ===== Programming Example |
| + | |||
| + | The code snippet bellow shows how to configure and use the SPI peripheral. | ||
| + | |||
| + | <code c> | ||
| + | #include " | ||
| + | |||
| + | RCC-> | ||
| + | RCC-> | ||
| + | |||
| + | /* Configure GPIO pin A.4 to A.7 in alternate function mode. */ | ||
| + | GPIOA-> | ||
| + | GPIOA-> | ||
| + | |||
| + | GPIOA-> | ||
| + | GPIOA-> | ||
| + | |||
| + | GPIOA-> | ||
| + | GPIOA-> | ||
| + | |||
| + | /* Configure SPI1 in slave mode. */ | ||
| + | SPI1-> | ||
| + | SPI1-> | ||
| + | |||
| + | SPI1-> | ||
| + | (0x1 << 6u); /* Enable SPI. */ | ||
| + | |||
| + | </ | ||
| + | \\ | ||
| - | \\ {{legende.svg}} \\ \\ | ||