cancel
Showing results for 
Search instead for 
Did you mean: 

USART1 with STM32F0 Discovery

pic_micro
Associate II
Posted on December 22, 2014 at 17:14

Dear All,

I write a program for USART1 of STM32F0 Discovery board. I am sure that my hardware is working . I configured with PuTTY but it does not display the message Please advice PA10 RX to MAX 232 pin 12 PA9 TX to MAX 232 pin 11

#include ''stm32f0xx.h''
#include ''stm32f0xx_tim.h''
#include <
stm32f0xx_rcc.h
>
#include ''stm32f0xx_usart.h''
void gpio_init(){
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd (RCC_AHBPeriph_GPIOC | RCC_AHBPeriph_GPIOA,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_8 ; 
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC, &GPIO_InitStructure); 
}
void LED(){
GPIOC->ODR ^= GPIO_Pin_8;
}
void USART_gpio_Initialize(){
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_0);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_0);
//Configure USART1 pins: Rx and Tx ----------------------------
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
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);
}
void USART_Initialize(){
//Configure USART2 setting: ----------------------------
USART_InitTypeDef USART_InitStructure;
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); 
USART_Cmd(USART1,ENABLE);
}
void Send_Data(){
while(1) {
while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET);
USART_SendData(USART1, 'A');
}
}
int main(){
gpio_init();
LED();
USART_gpio_Initialize();
USART_Initialize();
Send_Data();
//while(1){}
}

11 REPLIES 11
pic_micro
Associate II
Posted on December 26, 2014 at 04:13

Dear Sir

I missed one word of my last post

I configured the USART1 for pin PB6 - PB7 and it is working but stranger is it does

NOT

care about following codes

Probably because the reset setting of the bits related to the AF Mux are zero

Dear Sir I could not got above 

Please advice

Probably because the reset setting of the bits related to the AF Mux are zero.

Posted on December 26, 2014 at 15:44

0690X00000605DnQAI.png
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..