2011-02-02 07:13 PM
I'm trying to use USART3 with the regular mapping of Tx on PB10 and Rx on PB11. To start with I was just trying to get a single character to transmit. By the way, I'm using Atollic TrueSTUDIO. The following code does not seem to work. Any ideas would be helpful.
Thanks, Jim /* Configure USART Tx as function push-pull */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init( GPIOB, &GPIO_InitStructure ); RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART3, ENABLE); RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE ); USART_ClockStructInit( &USART_ClockInitStruct ); // The Struct Init function has USART_Clock disabled by default. //USART_ClockInitStruct.USART_Clock = USART_Clock_Enable; USART_ClockInit( USART3, &USART_ClockInitStruct ); USART_StructInit( &USART_InitStructure ); USART_Init( USART3, &USART_InitStructure ); USART_Cmd( USART3, ENABLE ); USART_SendData( USART3, 'H' ); #usart #usart #discovery2011-02-04 04:07 AM
Two quick observations. First you need to configure the GPIO outputs to be ''AF'' alternate function, ie the USART not the GPIO pin controller. Second, it is good practice to enable the APB clocks to the peripherals before programming register within those peripheral blocks, being synchronous, and all.
2011-02-05 04:48 PM
Sweet.
This seems to do the trick! Thanks, Jim RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB, ENABLE ); RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART3, ENABLE ); // Setup Tx pin. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init( GPIOB, &GPIO_InitStructure ); USART_ClockStructInit( &USART_ClockInitStruct ); USART_ClockInit( USART3, &USART_ClockInitStruct ); USART_StructInit( &USART_InitStructure ); USART_Init( USART3, &USART_InitStructure ); USART_Cmd( USART3, ENABLE ); char *s = ''Hello World!''; do { USART_SendData( USART3, *s ); while( ! USART_GetFlagStatus( USART3, USART_FLAG_TXE ) ); } while ( *(++s) );2011-02-06 12:35 PM
Just for completeness, attached is scrap of code that fires up USART3 and flashes the LEDs on the Discovery board.
Thanks again, Jim2011-02-21 05:20 AM
2011-02-21 05:50 AM
void USART_StructInit(USART_InitTypeDef * USART_InitStruct) fills each USART_InitStruct member with its default value.