spi从机
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_SPI_TransmitReceive(&hspi5, spi_tx, spi_rx, 10, 0xFF);
for(int i = 0;i slave rx %s\r\n",spi_rx);
HAL_UART_Transmit_DMA(&huart1,buf,strlen(buf));
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
while (HAL_SPI_GetState(&hspi5) != HAL_SPI_STATE_READY)
{
// HAL_SPI_TransmitReceive_DMA(&hspi5,spi_tx,spi_rx,10);
// if(HAL_SPI_TransmitReceive_DMA(&hspi5,spi_tx,spi_rx,10) != HAL_OK)
// {
// /* Transfer error in transmission process */
// Error_Handler();
// }
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
}
/* USER CODE END 3 */
}
1