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-29 03:51 PM
Hi Forum,
Finally found the issue. It turned out to be a manufacturing problem. A solder ball short was present on some boards and not on others between a via under the ST part and pin. It looks as if there wasn't enough clearance between them and occurred during solder reflow. If the board was shaken, then it sometimes moved, and everything looked good.
So many thanks to everyone who replied. All of you were pointing in the correct direction. The Nucleo board proved that the TX pin worked so that gave me a good baseline so start with. I also understand now why swapping the pins allowed the TX to work. Many thanks to you all.
Kind Regards
Bob.
2017-05-15 07:20 AM
Check VDDIO2 pin
2017-05-15 07:45 AM
Check also your reference manual, it may help you on your USART configuration.
2017-05-15 10:38 AM
Not sure that's terribly helpful, on the surface of things the code doesn't appear unreasonable, is there some specific insight you can share?
2017-05-15 10:39 AM
Don't enable the IRQ, write a simple demo that tightly loops outputting a 'U' character. Double check the board, pin connectivity, etc. Not familiar with the board in question.
2017-05-15 02:25 PM
VDDIO is at 3.3V. The following is my test code. I scope PC10 but see absolutely no activity at all. Changed boards but made no difference.
send_test_string('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa');
int send_test_string(unsigned char * byte)
{ for (;*byte;++byte) { send_char (*byte); } return 1; }void send_char (uint8_t ch)
{USART_SendData(USART4, (uint8_t) ch);
/* Loop until the end of transmission */
while (USART_GetFlagStatus(USART4, USART_FLAG_TC) == RESET) {} }2017-05-15 05:27 PM
Perhaps there is a design issue, I have neither the board nor the chip.
2017-05-15 07:38 PM
I would front check TXE rather than back check TC
2017-05-16 02:20 AM
Hi Clive,
Yeah, I did try checking TXE before sending characters. it made no difference. Also disabled the RX IRQ, but again no difference. Will talk to H/W designer today to get a second opinion. This code was ported from a STM32f051 so possibly a conflict there.However, it compiles fine and everything else runs fine.
2017-05-16 03:18 AM
Hi Clive,
Also tried driving PC10 High and Low. That works fine...I can see pulses on the scope.