cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple UART Problem ! !

kapilsinghi123
Associate II
Posted on August 14, 2014 at 12:43

The original post was too long to process during our migration. Please click on the attachment to read the original post.
4 REPLIES 4
Posted on August 14, 2014 at 13:43

its really frustrating.....

Coding is a detail orientated task.

You need to enable the clocks on the right APB.

You need to enable the clocks on the peripherals and GPIO you are using.

You need to configure both pins together as AF, this is not an STM32F1.

You need to make sure the pins are not conflicted.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on August 14, 2014 at 13:55

Try this

void USART_SETUP(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_USART6, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOG, ENABLE);
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_2MHz;
// Configure USART1 Rx (PA10) and USART1 Tx (PA9) as alternate function
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
GPIO_Init(GPIOA, &GPIO_InitStructure); 
GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_USART1);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_USART1);
// Configure UART4 Rx (PA1) and UART4 Tx (PA0) as alternate function
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_0;
GPIO_Init(GPIOA, &GPIO_InitStructure); 
GPIO_PinAFConfig(GPIOA,GPIO_PinSource0 ,GPIO_AF_UART4);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource1 ,GPIO_AF_UART4);
// Configure USART6 Rx (PG9) and USART6 Tx (PG14) as alternate function 
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14 | GPIO_Pin_9;
GPIO_Init(GPIOG, &GPIO_InitStructure); 
GPIO_PinAFConfig(GPIOG,GPIO_PinSource9 ,GPIO_AF_USART6);
GPIO_PinAFConfig(GPIOG,GPIO_PinSource14,GPIO_AF_USART6);
/* 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_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_InitStruct.USART_BaudRate = 57600;
USART_Init(USART1, &USART_InitStruct); // 57600 8N1
USART_Cmd(USART1, ENABLE);
USART_InitStruct.USART_BaudRate = 9600;
USART_Init(UART4, &USART_InitStruct); // 9600 8N1
USART_Cmd(UART4, ENABLE);
USART_Init(USART6, &USART_InitStruct); // 9600 8N1
USART_Cmd(USART6, ENABLE);
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
kapilsinghi123
Associate II
Posted on August 14, 2014 at 20:41

I lost patience a bit earlier... was able to resolve the issue for USART 6 and yes you were bang on on that.... 

will try Your Suggestions for port 4 

Its really nice to get support when you feel lost :) Thanks

kapilsinghi123
Associate II
Posted on August 17, 2014 at 15:24

UART 4 is not working

Tried what you suggested but still code hanges at this line on while()

while(USART_GetFlagStatus(UART4,USART_FLAG_TXE)==RESET);USART_SendData(UART4,0x30);

Tried swapping the Pins connected to USB to UART but still same result. Regards, KS