Question
STM32-VLDiscovery UART between Eval & PC Problem
Posted on December 19, 2011 at 17:20
Hi
I trying to access UART connection between eval board and pc. I am using uart 1 on PA9 and PA To change the signals i am using a MAX From the eval board to the pc the signals are correct, but bei receiving the signals interrupt driven the signals are defect. The interrupt gets invoke, but the characters are totally wrong. Has anyone any idea?//set up usart
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
USART_ClockInitTypeDef USART_ClockInitStructure;
//set up uart**************************************************************************************
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO, ENABLE);
initInterrupt();
//Set USART1 Tx (PA.09) as AF push-pull
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
//Set USART1 Rx (PA.10) as input floating
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_ClockStructInit(&USART_ClockInitStructure);
USART_ClockInit(USART1, &USART_ClockInitStructure);
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
//Write USART1 parameters
USART_Init(USART1, &USART_InitStructure);
//Enables interrupt
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
//Enable USART1
USART_Cmd(USART1, ENABLE);
for(i = 0; i < 100; i ++)
{
USART_SendData(USART1, 0x54);
while(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET)
{
}
}
//Interrupt routine
void USART1_IRQHandler(void)
{
if(USART_GetITStatus(USART1, USART_IT_RXNE) != RESET)
{
/* Read one byte from the receive data register */
uint8_t test = 0;
PCOutSPIINBuffer[PCOutSPIINBufferPointer++] = USART_ReceiveData(USART1);
test = PCOutSPIINBuffer[PCOutSPIINBufferPointer - 1];
if(PCOutSPIINBufferPointer == NbrOfDataToRead)
{
//todo error Buffer overflow
PCOutSPIINBufferPointer = 0;
USART_ITConfig(USART1, USART_IT_RXNE, DISABLE);
}
}
#stmvl-discovery-usart