STM32F767BIT6 SPI1 SPI2发送问题

2019-07-20 11:51发布

在使用STM32F767的SPI时候发现了一些奇特的现象,百思不得其解,特此分享,看能否找出真相。
件环境:STM32F767 SPI1 PD7 PG9 PG10PG11 SPI2 PB12 PB13PB14 PB15
件环境:KEIL5STM32Cube SPI1 Master SPI2 Master
最后现象是SPI1 四根线无任何输出     file:///C:/Users/admin/AppData/Local/Temp/msohtmlclip1/01/clip_image001.giffile:///C:/Users/admin/AppData/Local/Temp/msohtmlclip1/01/clip_image001.giffile:///C:/Users/admin/AppData/Local/Temp/msohtmlclip1/01/clip_image001.gif SPI2 SCK CS正常输出MOSI波形如下: ??????????????????????????????



友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
3条回答
scf7begin
2019-07-20 15:10

main.c
int main(void)
{
  /* USER CODE BEGIN 1 */
  uint8_t tx[5]={0x55,0xAA,0x00,0x55,0xAA};
  uint8_t rx[5];
  /* USER CODE END 1 */
  /* MCUConfiguration----------------------------------------------------------*/
  /* 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 configuredperipherals */
  MX_GPIO_Init();
  MX_SPI1_Init();
  MX_SPI2_Init();
  /* USER CODE BEGIN 2 */
  //__HAL_SPI_ENABLE(&hspi1);
  /* USER CODE END 2 */
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */
  /* USER CODE BEGIN 3 */
  HAL_SPI_Transmit(&hspi1,tx,5,200);
  HAL_SPI_Transmit(&hspi2,tx,5,200);
  //SPI1->DR =0x55;
  HAL_Delay(1);
    if(rx[0])
    {
      HAL_GPIO_WritePin(GPIOG,GPIO_PIN_14,SET);
    }
    else  
    {
      HAL_GPIO_WritePin(GPIOG,GPIO_PIN_14,RESET);
    }
  }
  /* USER CODE END 3 */
}


spi.c
SPI_HandleTypeDef hspi1;
SPI_HandleTypeDef hspi2;
/* SPI1 init function */
voidMX_SPI1_Init(void)
{
  hspi1.Instance = SPI1;
  hspi1.Init.Mode = SPI_MODE_MASTER;
  hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
  hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
  hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT;
  hspi1.Init.BaudRatePrescaler =SPI_BAUDRATEPRESCALER_64;
  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi1.Init.CRCCalculation =SPI_CRCCALCULATION_DISABLE;
  hspi1.Init.CRCPolynomial = 7;
  hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
  hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
  if (HAL_SPI_Init(&hspi1) != HAL_OK)
  {
    _Error_Handler(__FILE__, __LINE__);
  }
}

一周热门 更多>