cancel
Showing results for 
Search instead for 
Did you mean: 

USART1 = dead!

niklascooke2
Associate II
Posted on July 04, 2009 at 11:21

USART1 = dead!

3 REPLIES 3
swhite
Associate III
Posted on May 17, 2011 at 13:16

Quote:

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

Try changing the above line to

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

Remember that peripheral outputs only connect to port pins when they're configured as an ''alternate function'' ;) Peripheral inputs always connect.

You'll also need to enable the alternate function clock.

RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);

niklascooke2
Associate II
Posted on May 17, 2011 at 13:16

Hi everybody!

Im wondering if someone got a clue what the problem could be,

the Usart1 doesnt work at all. Ive tried everything!

Im using Crossworks 1.7 with STM32F103CBT6.

I get no signal mesured with a oscillscope.

Clock are set but nothing happens!

//Code

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOB | RCC_APB2Periph_USART1, ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_Init(GPIOA, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 ;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;

GPIO_Init(GPIOA, &GPIO_InitStructure);

USART_InitTypeDef USART_InitStructure;

USART_InitStructure.USART_BaudRate = 57600;

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

USART_Cmd(USART1, ENABLE);

While(1){

void SerialPutChar('a')

{

USART_SendData(USART1, c);

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

}

}

Regards Niklas :o

niklascooke2
Associate II
Posted on May 17, 2011 at 13:16

Hi swhite!

thank you so much!

This line made my day GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; !!

Ive been trying for a week now.

Thank you again!

Regards