[list]
[*]背景:ADS131A04作为SPI主设备,STM32L471作为SPI从设备,MCU通过SPI+DMA方式获取数据。
硬件连接:
[img]https://file1.elecfans.com/web2/M00/FF/A0/wKgZomapt-WAagD-AAA_evVnk9w786.jpg[/img]
MCU的SPI和DMA配置:
void InitSPI(void){ /* --- INSERT YOUR CODE HERE --- */ hspi1.Instance = SPI1; hspi1.Init.Mode = SPI_MODE_SLAVE; hspi1.Init.Direction = SPI_DIRECTION_2LINES; hspi1.Init.DataSize = SPI_DATASIZE_16BIT; hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; hspi1.Init.CLKPhase = SPI_PHASE_2EDGE; hspi1.Init.NSS = SPI_NSS_HARD_INPUT; 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; hspi1.State = HAL_SPI_STATE_RESET; if (HAL_SPI_Init(&hspi1) != HAL_OK) { Error_Handler(); }}void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle){ GPIO_InitTypeDef GPIO_InitStruct = {0}; if(spiHandle->Instance==SPI1) { /* USER CODE BEGIN SPI1_MspInit 0 */ /* USER CODE END SPI1_MspInit 0 */ /* SPI1 clock enable */ __HAL_RCC_SPI1_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /**SPI1 GPIO Configuration PA4 ------> SPI1_NSS PA5 ------> SPI1_SCK PA6 ------> SPI1_MISO PA7 ------> SPI1_MOSI */ GPIO_InitStruct.Pin = ADS131A04_SPI1_NSS_Pin|ADS131A04_SPI1_CLK_Pin|ADS131A04_SPI1_MISO_Pin|ADS131A04_SPI1_MOSI_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* SPI1 DMA Init */ /* SPI1_TX Init */ hdma_spi1_tx.Instance = DMA2_Channel4; hdma_spi1_tx.Init.Request = DMA_REQUEST_4; hdma_spi1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; hdma_spi1_tx.Init.PeriphInc = DMA_PINC_DISABLE; hdma_spi1_tx.Init.MemInc = DMA_MINC_ENABLE; hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_spi1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_spi1_tx.Init.Mode = DMA_NORMAL; hdma_spi1_tx.Init.Priority = DMA_PRIORITY_LOW; if (HAL_DMA_Init(&hdma_spi1_tx) != HAL_OK) { Error_Handler(); } __HAL_LINKDMA(spiHandle,hdmatx,hdma_spi1_tx); /* SPI1_RX Init */ hdma_spi1_rx.Instance = DMA2_Channel3; hdma_spi1_rx.Init.Request = DMA_REQUEST_4; hdma_spi1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_spi1_rx.Init.PeriphInc = DMA_PINC_DISABLE; hdma_spi1_rx.Init.MemInc = DMA_MINC_ENABLE; hdma_spi1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_spi1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_spi1_rx.Init.Mode = DMA_NORMAL; hdma_spi1_rx.Init.Priority = DMA_PRIORITY_LOW; if (HAL_DMA_Init(&hdma_spi1_rx) != HAL_OK) { Error_Handler(); } __HAL_LINKDMA(spiHandle,hdmarx,hdma_spi1_rx); /* SPI1 interrupt Init */ //HAL_NVIC_SetPriority(SPI1_IRQn, 0, 0); //HAL_NVIC_EnableIRQ(SPI1_IRQn); /* USER CODE BEGIN SPI1_MspInit 1 */ /* USER CODE END SPI1_MspInit 1 */ }}问题:ADC上电后,DOUT管脚一开始正常输出0xFF04,但是MCU初始化使能SPI后DOUT信号线电平被拉低,DOUT信号线上拉电阻试过100k,10k以及去掉上拉电阻,依然都是被拉低,可能是什么原因?
[font=inherit][img]https://file1.elecfans.com/web2/M00/FF/A0/wKgZomapt-eABvbNAAEJz9FbCeA735.jpg[/img][/font]
[/list]
[list]
[*]背景:ADS131A04作为SPI主设备,STM32L471作为SPI从设备,MCU通过SPI+DMA方式获取数据。
硬件连接:
[img]https://file1.elecfans.com/web2/M00/FF/A0/wKgZomapt-WAagD-AAA_evVnk9w786.jpg[/img]
MCU的SPI和DMA配置:
void InitSPI(void){ /* --- INSERT YOUR CODE HERE --- */ hspi1.Instance = SPI1; hspi1.Init.Mode = SPI_MODE_SLAVE; hspi1.Init.Direction = SPI_DIRECTION_2LINES; hspi1.Init.DataSize = SPI_DATASIZE_16BIT; hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; hspi1.Init.CLKPhase = SPI_PHASE_2EDGE; hspi1.Init.NSS = SPI_NSS_HARD_INPUT; 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; hspi1.State = HAL_SPI_STATE_RESET; if (HAL_SPI_Init(&hspi1) != HAL_OK) { Error_Handler(); }}void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle){ GPIO_InitTypeDef GPIO_InitStruct = {0}; if(spiHandle->Instance==SPI1) { /* USER CODE BEGIN SPI1_MspInit 0 */ /* USER CODE END SPI1_MspInit 0 */ /* SPI1 clock enable */ __HAL_RCC_SPI1_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /**SPI1 GPIO Configuration PA4 ------> SPI1_NSS PA5 ------> SPI1_SCK PA6 ------> SPI1_MISO PA7 ------> SPI1_MOSI */ GPIO_InitStruct.Pin = ADS131A04_SPI1_NSS_Pin|ADS131A04_SPI1_CLK_Pin|ADS131A04_SPI1_MISO_Pin|ADS131A04_SPI1_MOSI_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* SPI1 DMA Init */ /* SPI1_TX Init */ hdma_spi1_tx.Instance = DMA2_Channel4; hdma_spi1_tx.Init.Request = DMA_REQUEST_4; hdma_spi1_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; hdma_spi1_tx.Init.PeriphInc = DMA_PINC_DISABLE; hdma_spi1_tx.Init.MemInc = DMA_MINC_ENABLE; hdma_spi1_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_spi1_tx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_spi1_tx.Init.Mode = DMA_NORMAL; hdma_spi1_tx.Init.Priority = DMA_PRIORITY_LOW; if (HAL_DMA_Init(&hdma_spi1_tx) != HAL_OK) { Error_Handler(); } __HAL_LINKDMA(spiHandle,hdmatx,hdma_spi1_tx); /* SPI1_RX Init */ hdma_spi1_rx.Instance = DMA2_Channel3; hdma_spi1_rx.Init.Request = DMA_REQUEST_4; hdma_spi1_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_spi1_rx.Init.PeriphInc = DMA_PINC_DISABLE; hdma_spi1_rx.Init.MemInc = DMA_MINC_ENABLE; hdma_spi1_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD; hdma_spi1_rx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD; hdma_spi1_rx.Init.Mode = DMA_NORMAL; hdma_spi1_rx.Init.Priority = DMA_PRIORITY_LOW; if (HAL_DMA_Init(&hdma_spi1_rx) != HAL_OK) { Error_Handler(); } __HAL_LINKDMA(spiHandle,hdmarx,hdma_spi1_rx); /* SPI1 interrupt Init */ //HAL_NVIC_SetPriority(SPI1_IRQn, 0, 0); //HAL_NVIC_EnableIRQ(SPI1_IRQn); /* USER CODE BEGIN SPI1_MspInit 1 */ /* USER CODE END SPI1_MspInit 1 */ }}问题:ADC上电后,DOUT管脚一开始正常输出0xFF04,但是MCU初始化使能SPI后DOUT信号线电平被拉低,DOUT信号线上拉电阻试过100k,10k以及去掉上拉电阻,依然都是被拉低,可能是什么原因?
[font=inherit][img]https://file1.elecfans.com/web2/M00/FF/A0/wKgZomapt-eABvbNAAEJz9FbCeA735.jpg[/img][/font]
[/list]
举报