Thus, we should reset the flag when starting the transmission and set it when the transmission is completed. If it is set to 0, the SPI1 peripheral is busy.
If the completed1 flag is set to 1, the data exchange via SPI1 is finished. You should also declare these variables in all of the files where they are used: extern uint8_t completed1 As we activated four interrupt requests, let’s define four flags which will indicate the transmission status for all SPIs: uint8_t completed1 = 1 Hdma_spi1_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE Īll interrupts are located in the file stm32f4xx_it.c (if you use another microcontroller this file could have another name, for example, stm32f1xx_it.c. Hdma_spi1_tx.Init.Priority = DMA_PRIORITY_VERY_HIGH Hdma_spi1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE Hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE Hdma_spi1_tx.Init.MemInc = DMA_MINC_ENABLE Hdma_spi1_tx.Init.PeriphInc = DMA_PINC_DISABLE Hdma_spi1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH Hdma_spi1_tx.Init.Channel = DMA_CHANNEL_3 The DMA initialization is held in the HAL_SPI_MspInit() function: hdma_spi1_tx.Instance = DMA2_Stream3 First of all, the initialization function is called: void MX_SPI1_Init(void) Let’s look at some generated functions using the SPI1 module as an example.
After that, the configuration is fully completed, so, we can begin the programming process ? There are no differences between the configurations of different modules, so, we won’t stop on this point. Now, we should repeat all these steps for other SPI peripherals (SPI2, SPI3, SPI4).