2017-09-11 07:33 AM
Hi,
Now I'm trying to implement UART function as the below,
But the problem is keep showing in RS232 Tool.
I'm just referring fully reference posting such as
https://community.st.com/thread/19577?commentID=48791#comment
There's no miss match. But I don't know what is the problem and how to resolve this.
Could you please any advice to resolve this problem?
I guess one thing is there's noUSARTx->BRR declaration.
Is this possible way to happen the problem??
USART_InitTypeDef USART_InitStructure;int putcharx(int ch)
{ while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); USART_SendData(USART1, (uint8_t)ch); return ch; } int main(void) { RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);
//UART////////////////////////////////////////////////////////////////////////
/*-------------------------- 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_RXUSART_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);
/////////////////////////////////////////////////////////////////////////////////
while (1) { USART_SendData(USART1, 0x49); // Send 'I' //TEST 2}
In case TEST 1 and TEST2 have the same output result as the below image.
What am I supposed to do to resolve this problem?
should I have to calculate about
USARTx->BRR
? Note: this post was migrated and contained many threaded conversations, some content may be missing.Solved! Go to Solution.
2017-09-12 09:34 AM
See here, where you were told about removing SB15
https://community.st.com/0D50X00009XkXNtSAN
2017-09-11 07:50 AM
Can we *PLEASE* keep all your USART related adventures in one thread? Your audience here is limited.
You would need to make sure HSE_VALUE is correctly defined for the board, perhaps in stm32f4xx_conf.h and be 8000000 and not 25000000. Check also that system_stm32f4xx.c configures the PLL with the expectation of an 8 MHz crystal and not a 25 MHz one.
Unless you change the bus speeds dynamically you shouldn't need to revisit USART->BRR
Send an 0x55 data pattern and confirm the bit timing with a scope. Don't send data to the register unless TXE is asserted, you'll just garble things.
2017-09-12 09:16 AM
Clive, I'm struggling to receive data from PC with code below.
Sending data from STM32 board to PC is working good.
But receiving from PC has a problem.
The below image , I just prove the PA10 while sending data.
I'm not sure but would you please check this configuration?
void SendCharUSART1(char ch){
// Wait until TXE is setwhile(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET){}USART_SendData(USART1, ch);// Wait until the end of transmitwhile(USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET){}}char GetCharUSART1(void){ char ch; // Wait until the USART1 Receive Data Register is not emptywhile(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET){}ch = (USART_ReceiveData(USART1) & 0xFF);return ch; } 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); GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1); // USART1_TX GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1); // USART1_RX 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);/////////////////////////////////////////////////////////////////////////////////
SYSCFG_EXTILineConfig(0x0,0);
...
SendCharUSART1(0x0D);
SendCharUSART1(0x0A);SendCharUSART1('U');SendCharUSART1('S');SendCharUSART1('A');SendCharUSART1('R');SendCharUSART1('T');SendCharUSART1('1');SendCharUSART1('>');// Get and echo USART1ch = GetCharUSART1();while (ch != 0x0D) {SendCharUSART1(ch);ch = GetCharUSART1();}What am I missing?
Currently, stuck in here while(USART_GetFlagStatus(USART1, USART_FLAG_RXNE) == RESET)
during sending the data from PC to eval board.
2017-09-12 09:31 AM
So you show me a static signal on the USART1_RX and ask why it receives nothing?
Is this pin clashing with the VCP? Did you disconnect the ST-LINK's USART from the STM32F429? Make sure SB15 is *REMOVED*
2017-09-12 09:34 AM
See here, where you were told about removing SB15
https://community.st.com/0D50X00009XkXNtSAN
2017-09-12 09:49 AM
Can check once again please ?
I prove the each pins PA10 and PA9 to PA2 and PA3.
Then I found PA10 is connected with JP4's TX and PA9 is connected with JP4's RX not PA2 and PA3.
I can't find their connection between PA10 and PA2 also PA9 and PA3.
2017-09-12 10:01 AM
>>Can check once again please ?
What am I checking? Are you using the ST-LINK's VCP for these tests, or your external serial dongle from you prior thread?
What exactly have you go wired to what?
A scope trace with a flat-line is not going to result in data reception, if you are sending data why can you not see it?
2017-09-12 10:07 AM
Isn't USART1 connected to the VCP on the DISC1 board? via PA9 and PA10.
As you said, I think I have to look for another free pins for using UART.
BTW If I remove SB15, is there any serious problem?
I think it's connecting with 'uart bootloader'.
2017-09-12 10:14 AM
No, I'm not using uart pin for uploading firmware. I just connect to mini USB cable.
As you can see the scope trace, I think something work as a barrier to prevent received data from external serial dongle
2017-09-12 10:42 AM
Hi Clive,
Can I use uart port as a pair such as
PD5 USART2_TX, PC11 USART3_RX or should I have to make sure the pair such as UART3_TX and UART3_RX?
I separately implemented
PD5 USART2_TX, PC11 USART3_RX but it's working.good.
void SendCharUSART1(char ch){// Wait until TXE is setwhile(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET){}USART_SendData(USART1, ch);// Wait until the end of transmitwhile(USART_GetFlagStatus(USART2, USART_FLAG_TC) == RESET){}}char GetCharUSART1(void){ char ch; // Wait until the USART1 Receive Data Register is not emptywhile(USART_GetFlagStatus(USART3, USART_FLAG_RXNE) == RESET){}ch = (USART_ReceiveData(USART3) & 0xFF);return ch; }GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOG, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOG, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5; 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); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; 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(GPIOC, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2); // USART1_TX GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3); // USART1_RX 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_Init(USART3, &USART_InitStructure); USART_Cmd(USART3, ENABLE); 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_Tx; USART_Init(USART2, &USART_InitStructure); USART_Cmd(USART2, ENABLE);SendCharUSART1(0x0D);
SendCharUSART1(0x0A);SendCharUSART1('U');SendCharUSART1('S');SendCharUSART1('A');SendCharUSART1('R');SendCharUSART1('T');SendCharUSART1('1');SendCharUSART1('>');// Get and echo USART1ch = GetCharUSART1();while (ch != 0x0D) {SendCharUSART1(ch);ch = GetCharUSART1();}