完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
望大家帮我看看:DMA+USART1时,接收没问题,为什么发送老是掉倒数第二字节,倒数第一字节总是传在第一个字节上来了?具体配置如下:
USART配置 USART_InitTypeDef USART_InitStructure; USART_InitStructure.USART_BaudRate = 128000; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_InitStructure.USART_Clock = USART_Clock_Disable; USART_InitStructure.USART_CPOL = USART_CPOL_Low; USART_InitStructure.USART_CPHA = USART_CPHA_1Edge; USART_InitStructure.USART_LastBit = USART_LastBit_Disable; USART_Init(USART1, &USART_InitStructure); // USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // USART_ITConfig(USART1, USART_IT_TXE, ENABLE); USART_Cmd(USART1, DISABLE); DMA配置 DMA_InitTypeDef DMA_InitStructure; DMA_DeInit(DMA1_Channel4); DMA_InitStructure.DMA_PeripheralBaseAddr = (UINT32)&(USART1->DR); DMA_InitStructure.DMA_MemoryBaseAddr = (UINT32)SoundDataBuffer; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST; DMA_InitStructure.DMA_BufferSize = 512; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte; DMA_InitStructure.DMA_Mode = DMA_Mode_Normal; DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_Init(DMA1_Channel4, &DMA_InitStructure); DMA_ITConfig(DMA1_Channel4, DMA_IT_TC, ENABLE); USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE); DMA_DeInit(DMA1_Channel5); DMA_InitStructure.DMA_PeripheralBaseAddr = (UINT32)&(USART1->DR); DMA_InitStructure.DMA_MemoryBaseAddr = (u32)SoundDataBuffer; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 512; DMA_Init(DMA1_Channel5, &DMA_InitStructure); DMA_ITConfig(DMA1_Channel5, DMA_IT_TC, ENABLE); USART_DMACmd(USART1, USART_DMAReq_Rx, ENABLE); 在主程序中启动第一次,然后在结束中断中将发送与接收交替开启: void DMA1_Channel4_IRQHandler(void) { DMA1->IFCR = DMA1_FLAG_TC4; DMA1_Channel4->CCR &= ((u32)0xFFFFFFFE); *((PUINT32)0x40020064) = (UINT32)SoundDataBuffer; DMA1_Channel5->CNDTR = 512; DMA1_Channel5->CCR |= ((u32)0x00000001); *((PUINT32)0x4001380c) = (UINT32)0x00002004; } /******************************************************************************* * Function Name : DMA1_Channel5_IRQHandler * Description : This function handles DMA Stream 5 interrupt request. * Input : None * Return : None * Created By: 何宣见(hexuanjian2005@126.com) * Created date: 2011.02.11 *------------------------------------------------------------------------------- *******************************************************************************/ void DMA1_Channel5_IRQHandler(void) { DMA1->IFCR = DMA1_FLAG_TC5; DMA1_Channel5->CCR &= ((u32)0xFFFFFFFE); *((PUINT32)0x40020064) = (UINT32)SoundDataBuffer; DMA1_Channel4->CNDTR = 512; DMA1_Channel4->CCR |= ((u32)0x00000001); *((PUINT32)0x4001380c) = (UINT32)0x00002008; } |
|
相关推荐
4个回答
|
|
|
|
|
|
|
|
|
|
问题已发现,先开串口,再开DMA就对了
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1777 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1621 浏览 1 评论
1080 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
728 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1678 浏览 2 评论
1938浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
731浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
570浏览 3评论
595浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
554浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 12:37 , Processed in 1.031585 second(s), Total 82, Slave 66 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号