cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f0 discovery usart1 tx stays high

reetz
Associate
Posted on October 01, 2012 at 09:55

Hello,

I try to use the usart1 pa9 as tx and pa10 as rx with the following code

 /* Enable GPIO clock */

 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);   //PA9 ,PA10

 /* Enable USART clock */

 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

 /* Connect PXx to USARTx_Tx */

 GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_0);     //PA9 -> TX

 /* Connect PXx to USARTx_Rx */

 GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_0);    //PA10 -> RX

 /* Configure USART Tx as alternate function push-pull */

 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

 GPIO_Init(GPIOA, &GPIO_InitStructure);

 /* Configure USART Rx as alternate function push-pull */

 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

 GPIO_Init(GPIOA, &GPIO_InitStructure);

 /* USART configuration */

 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_HardwareFlowControl = USART_HardwareFlowControl_None;

 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

 USART_Init(USART1, &USART_InitStructure);

 /* Enable USART */

 USART_Cmd(USART1, ENABLE);

sending when KEY (Pa0) is pressed:

 USART_SendData(USART1, (uint8_t) 'F');

                  while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);

                  while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);

All I get is a continuous high on the port, no reaction whatsoever.

TIA

tom

#stm32f0-usart
2 REPLIES 2
Posted on October 01, 2012 at 16:04

Looks reasonable enough.

Perhaps have a loop generating constant traffic, see if that works

while(1)
{
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, 0x58);
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
reetz
Associate
Posted on October 02, 2012 at 06:22

Thanks Clive, that makes it easier to see.

Both versions work now (key and continuous)

I elimiated same fiddling with port a which was

above the code i posted.

Thanks

tom