USART STM32F4 PROBLEM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-03-26 12:51 PM
Hi, I have an error in my code and I can not seem identifying the problem
The erreur is : ..\main.c(97): error: #169: expected a declarationThis is my code /**************************************************************************************/ #include ''stm32f4_discovery.h'' #include <stm32f4xx_usart.h> GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure;void RCC_Configuration(void);void GPIO_Configuration(void);void USART1_Configuration(void);void RCC_Configuration(void){ /* --------------------------- System Clocks Configuration -----------------*/ /* USART1 clock enable */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); /* GPIOA clock enable */ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOD, ENABLE);} /**************************************************************************************/ void GPIO_Configuration(void){ /*-------------------------- GPIO Configuration ----------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); /* Connect USART pins to AF */ GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1); // USART1_TX GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1); // USART1_RX GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOD, &GPIO_InitStructure);} /**************************************************************************************/ void USART1_Configuration(void){ /* USARTx configuration ------------------------------------------------------*/ /* 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_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);} /**************************************************************************************/ char test;int main(void){ RCC_Configuration(); GPIO_Configuration(); USART1_Configuration(); while(1) { uint16_t Data; while(USART_GetITStatus(USART1, USART_IT_RXNE) == RESET); // Wait for Char Data = USART_ReceiveData(USART1); // Collect Char while(USART_GetITStatus(USART1, USART_IT_TXE) == RESET); // Wait for Empty USART_SendData(USART3, Data); // Echo Char } while(1); // Don't want to exit}}- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-03-26 1:01 PM
One too many closing braces? Helps when you paste code with line number references to use the ''Format Code Block'' and check Line Numbers
Random reference to USART3 Also be aware, and I think I've pointed this out before, you cannot use PA9 on the STM32F4-Discovery, read the schematic.Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-03-26 1:08 PM
- /**************************************************************************************/
- #include ''stm32f4_discovery.h''
- #include <stm32f4xx_usart.h>
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- void RCC_Configuration(void);
- void GPIO_Configuration(void);
- void USART1_Configuration(void);
- int main(void)
- {
- RCC_Configuration();
- GPIO_Configuration();
- USART1_Configuration();
- while(1)
- {
- uint16_t Data;
- while(USART_GetITStatus(USART1, USART_IT_RXNE) == RESET); // Wait for Char
- Data = USART_ReceiveData(USART1); // Collect Char
- while(USART_GetITStatus(USART1, USART_IT_TXE) == RESET); // Wait for Empty
- USART_SendData(USART3, Data); // Echo Char
- }
- }
- void RCC_Configuration(void)
- {
- /* --------------------------- System Clocks Configuration -----------------*/
- /* USART1 clock enable */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
- /* GPIOA clock enable */
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
- }
- /**************************************************************************************/
- void GPIO_Configuration(void)
- {
- /*-------------------------- GPIO Configuration ----------------------------*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 | GPIO_Pin_12;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /* Connect USART pins to AF */
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_USART1); // USART1_RX
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource12, GPIO_AF_USART1); // USART1_TX
- }
- /**************************************************************************************/
- void USART1_Configuration(void)
- {
- /* USARTx configuration ------------------------------------------------------*/
- /* 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_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);
- }
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-03-26 1:15 PM
One too many closing braces?
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-03-26 1:49 PM
plz my program dont work i can't send any data to an other xbee can you help me to solve this problem
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-03-26 1:54 PM
86. } <--- WHAT DOES THIS PAIR WITH?
PA9 / USART1 is NOT usable on the STM32F4-DISCO board.USART2 PA2/PA3 should be usable.[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/USART%20example%20code%20for%20Nucleo%20F401RE&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/AllItems.aspx¤tviews=9]Example HereUp vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-03-26 4:19 PM
I tried but it does not work here is my new code
- /**************************************************************************************/
- #include ''stm32f4_discovery.h''
- #include <stm32f4xx_usart.h>
- GPIO_InitTypeDef GPIO_InitStructure;
- USART_InitTypeDef USART_InitStructure;
- void RCC_Configuration(void);
- void GPIO_Configuration(void);
- void USART1_Configuration(void);
- void SysTick_Handler(void);
- void RCC_Configuration(void)
- {
- /* --------------------------- System Clocks Configuration -----------------*/
- /* USART1 clock enable */
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
- /* GPIOA clock enable */
- RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA|RCC_AHB1Periph_GPIOD, ENABLE);
- }
- /**************************************************************************************/
- void GPIO_Configuration(void)
- {
- /*-------------------------- GPIO Configuration ----------------------------*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
- GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /* Connect USART pins to AF */
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2); // USART1_TX
- GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2); // USART1_RX
- }
- /**************************************************************************************/
- void USART1_Configuration(void)
- {
- /* USARTx configuration ------------------------------------------------------*/
- /* 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_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(USART2, &USART_InitStructure);
- USART_Cmd(USART2, ENABLE);
- }
- char Uart2_Data_Ready()
- {
- if (USART_GetFlagStatus(USART2, USART_FLAG_RXNE) == SET)
- {
- return(1);
- }
- return(0);
- }
- void Uart2_write(char ch)
- {
- while (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET);
- USART_SendData(USART2, ch);
- }
- char Uart2_read()
- {
- return(USART_ReceiveData(USART2));
- }
- /**************************************************************************************/
- char test;
- int main(void)
- {
- char ch;
- RCC_Configuration();
- GPIO_Configuration();
- USART1_Configuration();
- while(1)
- {
- if(Uart2_Data_Ready()==1)
- {
- ch=Uart2_read();
- Uart2_write(ch);
- }
- return 0;
- }
- while(1); // Don't want to exit
- }
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-03-26 4:49 PM
I tried but it does not work here is my new code
Yeah, I'm not sure what ''not working'' means, and how I would debug it. The ''return 0'' in the while() loop of main() looks out of place.Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2014-03-26 7:04 PM
i have a same problem
