2011-09-27 11:12 PM
Hi,
Im trying to get the usart2 working but for some reason I get random corrupted data when I send message to the STM32F103T8. I can send messages from the STM32 to the computer without any corrupted bytes but not the other way around.The usart2 is piping the received messages to a DMA. I've activated the usart2 in the following way: DMA_DeInit(DMA1_Channel6); DMA_StructInit(&DMA_InitStructure); DMA_InitStructure.DMA_PeripheralBaseAddr = USART2_DR_Base; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)gRXBuf2; //Define in usart2.h DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_BufferSize = RX_BUF_SIZE2; //Define in usart2.h DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_M2M = DMA_M2M_Disable; DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh; DMA_Init( DMA1_Channel6, &DMA_InitStructure );USART_InitStructure2.USART_BaudRate = 4800;
USART_InitStructure2.USART_WordLength = USART_WordLength_8b;
USART_InitStructure2.USART_StopBits = USART_StopBits_1;
USART_InitStructure2.USART_Parity = USART_Parity_No;
USART_InitStructure2.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure2.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
/* Configure USART2 */
USART_Init(USART2, &USART_InitStructure2);
/* Enable USART2 Receive and Transmit interrupts */ USART_ITConfig(USART2, USART_IT_TC, ENABLE); // Enable USART2 Receive DMA requests USART_DMACmd(USART2, USART_DMAReq_Rx, ENABLE); // Enable DMA1 USART RX channel DMA_Cmd(DMA1_Channel6, ENABLE); // Enable USART2 USART_Cmd(USART2, ENABLE);I have also enabled the usart2 clock as following: RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);And finally enabled the usart2 interrupt: NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);I've done a simple program which checks when new data have been added to the DMA memory where the received data is and send the exact same data back to the computer.Then i connect to the STM32 with the windows xp hyperterminal and sends some chars.For example if i send GPGGA, I might get back something like GP=GA or even worse like G?G, where some chars is ''.Does anyone have any idea what might be wrong? I would really appriciate the help.CheersMike #stm32-stm32f103-usart-corrupted2012-06-12 06:31 AM
He said he was reading into the wrong memory area or one used by other buffers.
C coders would probably use the following : DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&USART2->DR; The address is also easy enough to figure from the reference manual. If DMA isn't working as you expect, go back and try simple polling. For 4800 baud, DMA reception seems like overkill as managing the buffers and handling timely processing of partial buffers is non-trivial. For DMA transmit you at least have quantified amounts of data you can deal with at the TC interrupts.2012-06-15 06:10 AM
Thank you Clive for your fast response
I had send something from the arm to the pc successfully only USART_SendData(USART2, 0x08 ); // in while loopbut i couldn't receive any thing even though I had do the same what Mikael did , and I had also used small buffer size to keep work in the memory limitation but it's the same that's what made me not sure for the base address of the USART2 (But now I sure it's 0x40004404 ).
by the way I'm using Lab view for communication with the ARM instead of Hyper terminal.