cancel
Showing results for 
Search instead for 
Did you mean: 

Garbage character in Usart buffer on reset

gvigelet2
Associate II
Posted on January 06, 2014 at 21:20

Hello Everyone, 

I have been having this issue for a while on a STM32L100-Discovery board, apparently on reset there is always a garbage character transmitted to the terminal.  After the reset the USART works fine.  My code to initialize the USART is below, any help or ideas would be welcome and appreciated.  Thanks in advance.

GPIO_InitTypeDef GPIO_InitStructure;

USART_InitTypeDef USART_InitStructure;

NVIC_InitTypeDef   NVIC_InitStructure;

    int c = 0x1FFFF;

/**

*  USART1 GPIO Configuration

PA9 ------> USART1_TX

PA10 ------> USART1_RX

*/

/*Enable or disable the AHB1 peripheral clock */

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

/*Configure GPIO pin */

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9|GPIO_Pin_10;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;

GPIO_Init(GPIOA, &GPIO_InitStructure);

/*Configure GPIO pin alternate function */

GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1);

/*Configure GPIO pin alternate function */

GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);

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 configuration */

USART_Init(USART1, &USART_InitStructure);

USART_Cmd(USART1, DISABLE);

NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 );

/* Enable USART Interrupt */

NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 8;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

/* Enable USART */

USART_Cmd(USART1, ENABLE);

// enable interrupt for uart

USART_ITConfig(USART1, USART_IT_TXE, DISABLE);

USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);

On first printf we see, second printf is fine:

ÿBegin

Success

3 REPLIES 3
Posted on January 06, 2014 at 22:00

Would an external pull-up on the TX line help? Or some reordering of the pin configuration and enablement?

Your goal is to avoid seeing a phantom start bit, observe condition with scope to better understand the glitch behaviour.
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
gvigelet2
Associate II
Posted on January 07, 2014 at 14:56

Thanks Clive I will take a look at it today on the scope and see what is going on and definitely try the pull-up resistor.

Thanks Again.

George

gvigelet2
Associate II
Posted on January 07, 2014 at 15:08

Thanks Clive again, a 10k pull-up on the transmit line got rid of the phantom data on reset.