2013-08-09 09:34 AM
What is wrong. it isn't show data in terminal,
********************************************************************** &sharpinclude <stm32f4xx.h> &sharpinclude <stm32f4xx_rcc.h> &sharpinclude <stm32f4xx_gpio.h> &sharpinclude <main.h> &sharpinclude <stm32f4xx_usart.h> &sharpinclude <stdio.h> //****************************************************************************** char str[14]; char msg1; int msg; //********************** Function *********************************************** void USART_SETUP (void); void delay(void); void USART1_PUTC(unsigned char c); void USART1_PUTS(unsigned char *s); int USART1_GETC(void); //************************ Main Function *************************************** int main() { USART_SETUP(); STM_EVAL_LEDInit(LED3); STM_EVAL_LEDInit(LED4); STM_EVAL_LEDInit(LED5); STM_EVAL_LEDInit(LED6); STM_EVAL_LEDOn(LED6); while(1) { while(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)==RESET); msg1 = USART_ReceiveData(USART1); while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET); USART_SendData(USART1,msg1); } } //*************************************************************************** void delay (void) { unsigned int i,j; for(i=0;i<5000;i++) { for(j=0;j<700;j++); } } //***************************** USART_SETUP ******************************* void USART_SETUP(void) { GPIO_InitTypeDef GPIO_InitStruct; USART_InitTypeDef USART_InitStruct; RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); /* USART2 use port A and pin 8-12 PA8 is USART1_CK PA9 is USART1_TX PA10 is USART1_RX PA11 is USART1_CTS PA12 is USART1_RTS */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1); GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1); /* Configure PA2 in AF pushpull mode */ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10 ; GPIO_InitStruct.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_Init(GPIOA, &GPIO_InitStruct); /* USARTx configured as follow: - BaudRate = 9600 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStruct.USART_BaudRate = 115200; USART_InitStruct.USART_WordLength = USART_WordLength_8b; USART_InitStruct.USART_StopBits = USART_StopBits_1; USART_InitStruct.USART_Parity = USART_Parity_No; USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USART1, &USART_InitStruct); USART_Cmd(USART1, ENABLE); } void USART1_PUTC(unsigned char c) { while(USART_GetFlagStatus(USART1,USART_FLAG_TXE)==RESET); USART_SendData(USART1,(int) c); } void USART1_PUTS(unsigned char *s) { while(*s) { USART1_PUTC(*s++); } } int USART1_GETC(void) { while(USART_GetFlagStatus(USART1,USART_FLAG_RXNE)==RESET); return(USART_ReceiveData(USART1)); } #stm32f4 #usart #rs2322013-08-11 03:45 PM
You haven't explicitly stated that you're using an STM32F4-Discovery board, but if you are PA9 is not usable for a USART pin due to a huge bulk capacitor being attached to it.
Might help if your comments were somewhat coherent with the code. A secondary issue with USART functionality is with timing, from both the perspective of the external crystal used, and the value defined for HSE_VALUE. Thirdly, the output/input for the STM32 is CMOS levels, this is NOT compatible with RS232 levels, and requires some interface circuitry.2013-08-12 01:34 AM
Is this going to display some characters on your PC?
2013-08-13 09:20 AM
Is this going to display some characters on your PC?
The example as presented attempts to echo back received characters to the sender, presumably a terminal app on a PC.2013-08-13 09:24 PM
First, I define HSE_Value = 8000000 in option and headfile stm32f4xx.h
Secondly, I connect port USART with interface circuit with MAX3232 Third, I connect port PA9 follow Datasheet STM32F407 and it same problem Thank you2013-08-13 09:28 PM
Yes, It show some character but it not english character.
2013-08-14 05:03 AM
Reinterating, PA9 is NOT usable on the STM32F4-Discovery board
Send a stream of characters, review signal on scope.