cancel
Showing results for 
Search instead for 
Did you mean: 

USART

timothy
Associate II
Posted on July 17, 2013 at 05:19

I tried configuring. Im using the STM32F103RB

/* Setup GPIO pin GPIO_USART1_TX. */
GPIO_InitTypeDef GPIO_InitStructure; // GPIO structure
USART_InitTypeDef USART_InitStructure; // USART Structure
USART_ClockInitTypeDef USART_ClockInitStructure; // USART Clock Source
USART_Cmd(USART1, ENABLE);
//USART_ClearFlag(USART1,USART_FLAG_TXE);
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 , ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
//GPIO Configuration
GPIO_PinRemapConfig(GPIO_Remap_USART1,ENABLE);
// Enable Clock
USART_ClockInitStructure.USART_Clock = USART_Clock_Enable;
USART_ClockInitStructure.USART_CPHA = USART_CPHA_1Edge;
USART_ClockInitStructure.USART_CPOL = USART_CPOL_Low;
USART_ClockInitStructure.USART_LastBit = USART_LastBit_Enable;
USART_ClockInit(USART1, &USART_ClockInitStructure);
// USART Configure
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_InitStructure.USART_Parity = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_WordLength = USART_Parity_No;
USART_Init(USART1, &USART_InitStructure); // Stops here
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA9-UART.TX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOB, &GPIO_InitStructure);

the USART but still fail to make it work any suggestions? #usart-h103-stm32f103
2 REPLIES 2
Posted on July 17, 2013 at 05:48

Well you're totally butchering that!

Ok, so what pins are you using for the USART1? Cause you have PA9/PA10, and remapped at PB6/PB7. You're remapping and then configuring PB9/PB You're not enabling the USART1 and GPIOA/B clocks. You really don't need to do the clock configuration for ASYNC modes, this is not the same as enabling the peripheral clocks. Remember also that the CMOS levels from the CPU are not designed to interface at RS232 levels. This is a more rational ordering using USART1 with PA9/PA10

GPIO_InitTypeDef GPIO_InitStructure; // GPIO structure
USART_InitTypeDef USART_InitStructure; // USART Structure
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA, ENABLE);
/* Configure USART Tx as alternate function push/pull */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //PA9-UART.TX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Configure USART Rx as input floating */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_Init(GPIOA, &GPIO_InitStructure);
// USART Configure
USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_InitStructure.USART_Parity = USART_WordLength_8b;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_WordLength = USART_Parity_No;
USART_Init(USART1, &USART_InitStructure); 
USART_Cmd(USART1, ENABLE);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
timothy
Associate II
Posted on July 17, 2013 at 05:58

Yea thanks sorry i think i just confused myself which is probably why it wouldnt work. Thank a ton.

-Tim