我芯片使用内部时钟72Mhz 主频 ,使用环境:DMA1_Channel5 通道接收usart1 , DMA1_Channel4 通道发送Usart1,硬件RTS ,串口空闲中断开启,485芯片 max3485,在接收数据时usart1只有第一个byte能正确接收,其它数据都不正确。在用DMA发送时完全接收不到数据。请问这个情况怎么处理。软件控制收发吗
程序源码
您好,附件为CH32V307 串口1DMA收发的例程,同样使用了串口空闲中断,你可以参考一下。此外注意一下,若ld文件中将FLASH和RAM大小配置为288+32的话,需要通过ISP工具下载配置一下,否则建议用256+64,不然程序可能会有问题。后续若有问题,可通过邮箱和我沟通(lzs@wch.cn)。
WCHISPTool工具下载链接:/downloads/WCHISPTool_Setup_exe.html?
图1
图2
DMA通信这个配置我这边用其它的端口测试都没有问题。但就485通信不正常
配置没有奇偶效验,但偶效验能收到数据,但发不出来数据
DMA_Channel_TypeDef *channel, uint8_t *adsRx, uint32_t size) {
GPIO_InitTypeDef GPIO_InitStructure = { 0 };
USART_InitTypeDef USART_InitStructure = { 0 };
DMA_InitTypeDef DMA_InitStructure = { 0 };
NVIC_InitTypeDef NVIC_InitStructure = { 0 };
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
USART_InitStructure.USART_BaudRate = baudrate;
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;
DMA_DeInit(channel);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32) (&usart->DATAR); /* USART2->DATAR:0x40004404 */
DMA_InitStructure.DMA_MemoryBaseAddr = (u32) adsRx;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = size;
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;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA,
ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
/* USART1 TX-->A.9 RX-->A.10 */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; /* RTS-->A.12 */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_InitStructure.USART_HardwareFlowControl =
USART_HardwareFlowControl_RTS;
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
USART_ITConfig(usart, USART_IT_IDLE, ENABLE);
USART_Init(usart, &USART_InitStructure);
DMA_Init(channel, &DMA_InitStructure);
DMA_Cmd(channel, ENABLE);
NVIC_Init(&NVIC_InitStructure);
//配置发送DMA
DMA_DeInit(DMA1_Channel4);
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32) (&USART1->DATAR); /* USART2->DATAR:0x40004804 */
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) USART_TX_BUF;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralDST;
DMA_InitStructure.DMA_BufferSize = USART_TEC_LEN;
DMA_Init(DMA1_Channel4, &DMA_InitStructure);
USART_DMACmd(usart, USART_DMAReq_Rx | USART_DMAReq_Tx, ENABLE);
。
您好,您可以尝试由串口引脚直接读取串口打印的输出,检查打印内容是否正确。如果还有问题,可以发送邮件至lbw@wch.cn进一步沟通。