spi主机程序STM32CubeMx生成Hal库DMA发送接收intmain(void){/*USERCODEBEGIN1*//*USERCODEEND1*//*MCUConfiguration--------------------------------------------------------*//*Resetofallperipherals,InitializestheFlashinterfaceandtheSystick.*/HAL_Init();/*USERCODEBEGINInit*//*USERCODEENDInit*//*Configurethesystemclock*/SystemClock_Config();/*USERCODEBEGINSysInit*//*USERCODEENDSysInit*//*Initializeallconfiguredperipherals*/MX_GPIO_Init();MX_DMA_Init();MX_USART1_UART_Init();MX_SPI5_Init();/*USERCODEBEGIN2*/// HAL_UART_Receive_DMA(&huart1,rxBuffer,BUFFER_SIZE); /*USERCODEEND2*//*Infiniteloop*//*USERCODEBEGINWHILE*/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);/*USERCODEENDWHILE*//*USERCODEBEGIN3*/}/*USERCODEEND3*/}
1