参考:
https://os.mbed.com/platforms/ST-Nucleo-F746ZG/
um1905-description-of-stm32f7-hal-and-lowlayer-drivers-stmicroelectronics.pdf page 1059 。
我们使用 SPI1 ,将 PA6 和PA7 对接 ,
ide 使用 STM32CubdeIDE ,
记得一定要将默认的 DataSize 4 修改为 8 。
主要代码如下:
MX_SPI1_Init();
/* USER CODE BEGIN 2 */
uint8_t buffer[1024]={0};
int i = 0 ;
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
u8 tx=95;
u8 rx=0;
int ret = HAL_SPI_TransmitReceive(&hspi1,&tx,&rx,1,HAL_MAX_DELAY);
if(ret == 0){
i++;
HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_0);
HAL_Delay(1000);
if(rx == (tx & 0b11111111)){
int s = sprintf((char*)buffer,"ok :%d\n",rx);
HAL_UART_Transmit(&huart3,buffer,s,HAL_MAX_DELAY);
} else{
int s = sprintf((char*)buffer,"error :%d\n",rx);
HAL_UART_Transmit(&huart3,buffer,s,HAL_MAX_DELAY);
}
} else {
HAL_Delay(1000);
int s= sprintf((char*)buffer,"error\n");
HAL_UART_Transmit(&huart3,buffer,s,HAL_MAX_DELAY);
}
}
/* USER CODE END 3 */
然后可以在pc端的串口助手看到结果。