2017-05-15 01:40 AM
Hi Forum,
I'm using the stm32f091RCt6, (LQFP64) to set up USART4
Kind Regards
Bob
USART_InitTypeDef USART_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; // Enable GPIOC clock RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); // Enable USART3 APB clock RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART4, ENABLE); // Connect pin to Periph GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_0); // USART4 TX GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_0); // USART4 RX // Configure pins as AF pushpull GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; 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_DOWN; GPIO_Init(GPIOC, &GPIO_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(USART4, &USART_InitStructure); USART_Cmd(USART4, ENABLE); // Enable the COM4 Receive interrupt: this interrupt is generated when the// COM4 receive data register is not empty USART_ITConfig(USART4, USART_IT_RXNE, ENABLE);// USART4 IRQ Channel configuration
NVIC_InitStructure.NVIC_IRQChannel = USART3_8_IRQn;NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure);Although I can receive data I cannot get any TX at all. I have usart1 and usart2 working fine. not sure what is is. I've buzzed out all the board connections and they are fine. Looking at the clock tree on page16 of the datasheet, I notice PCLK only goes to usart1, usart2 and usart3. Does usart4 need some aqlternative form of clocking? The datasheet really doesnt say to much about usarts4 to 8 and there are no app notes out there to refer to so i'm stuck at this point.
Thanks for any help.
Regards Bob
Solved! Go to Solution.
2017-05-16 04:05 AM
Sounds all reasonable to me as well.
Have you ruled out a short to a neighboring pin ?
Or something else connected to it ?
2017-05-16 07:02 AM
I checked for a short and it looks OK. The TX pin from the micro is connected to DI on a ST485 part. I wondering if the ST485 was loading the TX pin, but the datasheet only specs a few microamp.
2017-05-16 07:26 AM
If you deal with a custom board or prototype, the schematics/layout could be wrong, or the RS485 driver populated wrong (reverse). I would check without.
Have you considered/connected the DE pin (driver enable) of the ST485 ?
2017-05-16 08:17 AM
I drive DE high during TX. I see it pulsing high on ST485 pin, but the uart tx pin, connected to DI of 485 always.remains low. I'll snip the DI pin input on the ST485 and see what happens
2017-05-16 08:58 AM
I hope you have checked for a proper connection as well (TX --> DI).
With a prototype board, take nothing for granted. Hardware guys can make mistakes, too ...
2017-05-16 10:40 AM
The code looks to be Ok, the chip docs suggest USART4 is available, AF mapping looks right, and you have the RX working. Not a chip I'm using, no mag ic wand I can wave from this end.
Stupid forum! Why is this going to moderation!
2017-05-16 11:30 PM
The ST485 requires VCC = 5 V ± 5 %. Are you powering it from 5V?
2017-05-17 07:05 AM
Will get back to this later today and let you know.
2017-05-17 09:35 AM
>>Stupid forum! Why is this going to moderation!
Apparently word that rhymes with tragic..
2017-05-18 12:26 AM
The 485 pin is powered from 5V. I swapped the usart pins using the
USART_SWAPPinCmd function and TX is now looking fine. Thought the orientation of the ST485 part might be incorrect, but it is fine. Same problem on another board as well, so going to remove 485 parts to see what uart TX and RX signals look like in their normal configuration.