STM32 SPI SCLK停止滴答作响

2019-07-14 17:36发布

我有STM32L052K8T6(主机),我试图通过SPI与AD7124-4 ADC(从机)通信。我的问题是STM在从tx缓冲区传输所有数据(在外部示波器上检查)后立即停止在SCLK上传输时钟脉冲,并忽略等待应答直到超时到期的请求。当没有时钟同步时,Slave没有机会回答。我的代码:
void initSPI (void)
{
GPIO_InitTypeDef GPIO_InitStructure;

__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_SPI1_CLK_ENABLE();

//GPIO - MOSI, MISO, CLK
GPIO_InitStructure.Pin = GPIO_PIN_4|GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStructure.Mode = GPIO_MODE_AF_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStructure.Alternate = GPIO_AF0_SPI1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);

HAL_NVIC_SetPriority(SPI1_IRQn, 1, 1);
HAL_NVIC_EnableIRQ(SPI1_IRQn);

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_2;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 7;

if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
    ErrorHandler();
}

HAL_SPI_MspInit(&hspi1);

__HAL_SPI_ENABLE(&hspi1);
}
我在调用这个函数:
  1. void SendReceiveData ()
  2. {
  3.     uint8_t tx = 64;
  4.     while (hspi1.State != HAL_SPI_STATE_READY);
  5.     HAL_SPI_TransmitReceive(&hspi1, &tx, &rx, 1, 10000);
  6. }
复制代码
即使我有一个很长的超时,它也会被忽略。HAL_SPI_TransmitReceive()返回HAL_OK。我的初始化有问题吗?

友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。