2014-12-22 08:14 AM
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){}
}
2014-12-25 07:13 PM
Dear Sir
I missed one word of my last postI 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 zeroDear Sir I could not got above Please adviceProbably because the reset setting of the bits related to the AF Mux are zero.
2014-12-26 06:44 AM