spi主机程序
STM32CubeMx生成
Hal库
DMA发送接收
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_DMA_Init();
MX_USART1_UART_Init();
MX_SPI5_Init();
/* USER CODE BEGIN 2 */
// HAL_UART_Receive_DMA(&huart1,rxBuffer,BUFFER_SIZE);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6, GPIO_PIN_RESET);
spi_tx[0] =6;
spi_tx[1] = 7;
spi_tx[2] = 8;
spi_tx[3] = 9;
memset(spi_rx,0,BUFFER_SIZE);
HAL_SPI_TransmitReceive_DMA(&hspi5,spi_tx,spi_rx,BUFFER_SIZE);
HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6, GPIO_PIN_SET);
HAL_Delay(1000);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
1