完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
STM32F4用的HAL库,SPI3+DMA方式读取25FL512S片子数据,读出来的数据错误,之前没用DMA的时候读出来的数据是对的,为了提高速度换成DMA出现问题了,请大神们帮忙分析下?下面是代码:/* SPI3 init function */
void MX_SPI3_Init(void) { hspi3.Instance = SPI3; hspi3.Init.Mode = SPI_MODE_MASTER; hspi3.Init.Direction = SPI_DIRECTION_2LINES; hspi3.Init.DataSize = SPI_DATASIZE_8BIT; hspi3.Init.CLKPolarity = SPI_POLARITY_HIGH; hspi3.Init.CLKPhase = SPI_PHASE_2EDGE; hspi3.Init.NSS = SPI_NSS_SOFT; hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_8; hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB; hspi3.Init.TIMode = SPI_TIMODE_DISABLE; hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; hspi3.Init.CRCPolynomial = 10; HAL_SPI_Init( hspi3); } void HAL_SPI_MspInit(SPI_HandleTypeDef* hspi) { GPIO_InitTypeDef GPIO_InitStruct; if(hspi->Instance==SPI3) { /* USER CODE BEGIN SPI3_MspInit 0 */ /* USER CODE END SPI3_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_SPI3_CLK_ENABLE(); /* DMA controller clock enable */ __HAL_RCC_DMA1_CLK_ENABLE(); /**SPI3 GPIO Configuration PA15 ------> SPI3_NSS1 PD2 ------> SPI3_NSS2 PD0 ------> SPI3_WP PD1 ------> SPI3_HOLD PD4 ------> SPI3_RST PC10 ------> SPI3_SCK PC11 ------> SPI3_MISO PC12 ------> SPI3_MOSI */ GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF6_SPI3; HAL_GPIO_Init(GPIOC, GPIO_InitStruct); /* SPI3 DMA Init */ /* SPI3_RX Init */ hdma_spi3_rx.Instance = DMA1_Stream0; hdma_spi3_rx.Init.Channel = DMA_CHANNEL_0; hdma_spi3_rx.Init.Direction = DMA_PERIPH_TO_MEMORY; hdma_spi3_rx.Init.PeriphInc = DMA_PINC_DISABLE; hdma_spi3_rx.Init.MemInc = DMA_MINC_ENABLE; hdma_spi3_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; hdma_spi3_rx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; hdma_spi3_rx.Init.Mode = DMA_NORMAL; hdma_spi3_rx.Init.Priority = DMA_PRIORITY_HIGH; hdma_spi3_rx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; hdma_spi3_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; hdma_spi3_rx.Init.MemBurst = DMA_MBURST_INC4; hdma_spi3_rx.Init.PeriphBurst = DMA_PBURST_INC4; HAL_DMA_Init( hdma_spi3_rx); __HAL_LINKDMA(hspi,hdmarx,hdma_spi3_rx); /* SPI3_TX Init */ hdma_spi3_tx.Instance = DMA1_Stream5; hdma_spi3_tx.Init.Channel = DMA_CHANNEL_0; hdma_spi3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH; hdma_spi3_tx.Init.PeriphInc = DMA_PINC_DISABLE; hdma_spi3_tx.Init.MemInc = DMA_MINC_ENABLE; hdma_spi3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; hdma_spi3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; hdma_spi3_tx.Init.Mode = DMA_NORMAL; hdma_spi3_tx.Init.Priority = DMA_PRIORITY_MEDIUM; hdma_spi3_tx.Init.FIFOMode = DMA_FIFOMODE_DISABLE; hdma_spi3_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL; hdma_spi3_tx.Init.MemBurst = DMA_MBURST_INC4; hdma_spi3_tx.Init.PeriphBurst = DMA_PBURST_INC4; HAL_DMA_Init( hdma_spi3_tx); __HAL_LINKDMA(hspi,hdmatx,hdma_spi3_tx); /* DMA interrupt init */ /* DMA1_Stream0_IRQn interrupt configuration */ //HAL_NVIC_SetPriority(SPI3_IRQn, 6, 0); //HAL_NVIC_EnableIRQ(SPI3_IRQn); /* DMA interrupt init */ /* DMA1_Stream0_IRQn interrupt configuration */ HAL_NVIC_SetPriority(DMA1_Stream0_IRQn, 6, 0); HAL_NVIC_EnableIRQ(DMA1_Stream0_IRQn); /* DMA1_Stream5_IRQn interrupt configuration */ HAL_NVIC_SetPriority(DMA1_Stream5_IRQn, 6, 1); HAL_NVIC_EnableIRQ(DMA1_Stream5_IRQn); /* USER CODE BEGIN SPI3_MspInit 1 */ /* USER CODE END SPI3_MspInit 1 */ } } void HAL_SPI_MspDeInit(SPI_HandleTypeDef* hspi) { if(hspi->Instance==SPI3) { /* USER CODE BEGIN SPI3_MspDeInit 0 */ /* USER CODE END SPI3_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_SPI3_CLK_DISABLE(); /* DMA controller clock enable */ __HAL_RCC_DMA1_CLK_DISABLE(); /**SPI3 GPIO Configuration PC10 ------> SPI3_SCK PC11 ------> SPI3_MISO PC12 ------> SPI3_MOSI */ HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12); /* SPI3 DMA DeInit */ HAL_DMA_DeInit(hspi->hdmarx); /HAL_DMA_DeInit(hspi->hdmatx); HAL_NVIC_DisableIRQ(DMA1_Stream0_IRQn); HAL_NVIC_DisableIRQ(DMA1_Stream5_IRQn); //HAL_NVIC_DisableIRQ(SPI3_IRQn); /* USER CODE BEGIN SPI3_MspDeInit 1 */ /* USER CODE END SPI3_MspDeInit 1 */ } } #include "stm32f4xx_it.c"文件下 /** * @brief This function handles DMA1 stream0 global interrupt. */ void DMA1_Stream0_IRQHandler(void) { /* USER CODE BEGIN DMA1_Stream0_IRQn 0 */ /* USER CODE END DMA1_Stream0_IRQn 0 */ HAL_DMA_IRQHandler( hdma_spi3_rx); /* USER CODE BEGIN DMA1_Stream0_IRQn 1 */ /* USER CODE END DMA1_Stream0_IRQn 1 */ } /** * @brief This function handles DMA1 stream5 global interrupt. */ void DMA1_Stream5_IRQHandler(void) { /* USER CODE BEGIN DMA1_Stream5_IRQn 0 */ /* USER CODE END DMA1_Stream5_IRQn 0 */ HAL_DMA_IRQHandler( hdma_spi3_tx); /* USER CODE BEGIN DMA1_Stream5_IRQn 1 */ /* USER CODE END DMA1_Stream5_IRQn 1 */ } main函数下定时读取数据调用的函数 void SPI_FLASH_BufferRead(UINT8 chipNum,UINT8* pBuffer, UINT32 ReadAddr, UINT16 NumByteToRead) { if(ReadAddr+RX_DATA_LEN <= S25F_FLASH_SIZE) { /* 选择芯片 */ SPI_FLASH_Select(chipNum); /*使能片选*/ SPI_FLASH_CS_ENABLE(); /*发送读数据指令*/ SPI_FLASH_SendByte(S25F_ReadData); /*发送32位数据地址*/ SPI_FLASH_Send4Bytes(ReadAddr); if(NumByteToRead> RX_DATA_LEN ) { NumByteToRead = RX_DATA_LEN ; } HAL_SPI_Receive_DMA( SpiHandle,pBuffer,NumByteToRead); //取消片选信号 SPI_FLASH_CS_DISABLE(); } } HAL_SPI_Receive_DMA这边读出来的数据一直不对,另外我的HAL_SPI_RxCpltCallback函数除了库文件Stm32f4xx_hal_spi.c下,没在别的文件里重新编写。 请各位帮忙分析下什么原因? |
|
相关推荐
1个回答
|
|
STM32F4下的SPI+DMA读取数据不对可能由多种原因导致。以下是一些可能的原因:
为了解决这个问题,你可以采取以下措施:
通过逐一排查上述可能的原因,你应该能够找到导致STM32F4下SPI+DMA读取数据不对的具体原因,并进行相应的修复。
|
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1685 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1588 浏览 1 评论
1013 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
706 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1631 浏览 2 评论
1893浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
679浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
538浏览 3评论
559浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
526浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-5 01:34 , Processed in 0.662950 second(s), Total 78, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号