AnsweredAssumed Answered

stm32 discovery, usart not working at all ?

Question asked by mccarty.michael on Aug 6, 2012
Latest reply on Aug 10, 2012 by Andrew Neil
I had tried to move a working application to my stm32 discovery 'b'. I defined it as STM32F10X_LD_VL and am using the latest libraries from the stdperiph. 

The usart does not work at all (no high/low on scope). I had a fairly convoluted usart2 that did int on rx and dma on tx so I enabled usart3 and got the same result which is this. 

When I enable printf my code sits in this while loop forever 
while (USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET)
When I use USART_SendData(), I never see anything on the pins, even with a scope. It's always low. I send data to the usart and there is nothing ever in the buffer, so I'm pretty sure its either way. 

Its almost like its off. Moving the code back to my other board usart2 and 3 are working fine. 

here is the code i use to configure my usarts

void USART2_Config(void)
{
     USART_InitTypeDef           USART_InitStructure;
     NVIC_InitTypeDef           NVIC_InitStructure;
     
     //Usart2_GPIO();
     GPIO_InitTypeDef GPIO_InitStructure;
     #ifndef STM32F10X_LD_VL
     GPIO_PinRemapConfig(GPIO_Remap_USART2, ENABLE);
     #endif
     RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA, ENABLE);
     RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2, ENABLE); 


     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;              
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;  
     GPIO_Init(GPIOA, &GPIO_InitStructure);             


     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;             
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;   
     GPIO_Init(GPIOA, &GPIO_InitStructure);     
     USART_Cmd(USART2, DISABLE);


     /* Enable the USARTz 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);
     
    USART_InitStructure.USART_BaudRate = 115200;
     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_Init(USART2, &USART_InitStructure);


     // enable this int to trigger dma ?
     USART_ITConfig(USART2, USART_IT_RXNE, ENABLE);
     //USART_ITConfig(USART2, USART_IT_TXE, ENABLE);


     // setup dma for usart
     USART_DMACmd(USART2, USART_DMAReq_Tx | USART_DMAReq_Rx, ENABLE);


     // hold onto your butts
     USART_Cmd(USART2, ENABLE);
}


void USART3_Config(void)
{
     USART_InitTypeDef           USART_InitStructure;
     
     //Usart2_GPIO();
     GPIO_InitTypeDef GPIO_InitStructure;
     


     RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE);
     RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART3, ENABLE); 


     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;              
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;  
     GPIO_Init(GPIOB, &GPIO_InitStructure);             


     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;             
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;   
     GPIO_Init(GPIOB, &GPIO_InitStructure);
          
     USART_Cmd(USART3, DISABLE);


    USART_InitStructure.USART_BaudRate = 115200;
     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_Init(USART3, &USART_InitStructure);


     // hold onto your butts
     USART_Cmd(USART3, ENABLE);
}

 If I never get responses to this post I would at least like to say thanks to Clive, even though this is my first post you have helped me several times already. 



Outcomes