cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F105RC UART problem

andycc.wei9
Associate
Posted on October 05, 2015 at 03:26

Hi, I'm currently working with STM32F105RC chip and trying to use UART4 (PC10 and PC11), which connects to a USB to UART module to a computer. The problem is, I'm not getting any readings from PC using hyperterminal.

/******** Declare USART�?GPIO structure ********/
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/******** Activate GPIOC�?UART4 RCC clock ********/
//RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC|RCC_APB2Periph_USART1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE); //clock a PORTC
RCC_APB2PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE); //clock alla UART4!
/******** Setup PC10 for Tx ********/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure); // Initialize PC10
/******** Setup PC11 for Rx ********/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(GPIOC, &GPIO_InitStructure); // Initialize PC11
/******** USART parameter ********/
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(UART4, &USART_InitStructure); // Initialize UART4
USART_Cmd(UART4, ENABLE); // Activate USART4
USART_SendData(UART4, 'a'); // Send data

#uart #stm32f105rc
4 REPLIES 4
Posted on October 05, 2015 at 04:33

Dupe?

So get a scope and check out the signal, and confirm you can see the symbol, and confirm the bit timing.

You want to check for TXE to assert before outputting each character. I'd suggest a 'U' character.

Make sure you haven't mixed the TX and RX sense. The TX on STM32 side is the output, but make sure you don't connect it to another output.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 05, 2015 at 04:35

RCC_APB2PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);

// APB2 != APB1
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
andycc.wei9
Associate
Posted on October 05, 2015 at 07:49

Thank you clive1, stupid of me to make this mistake. I'm getting a reading now, although the received data is gibberish. I've read somewhere this is due to the external oscillator setting problem? Currently the default is

#if !defined HSE_VALUE
#ifdef STM32F10X_CL 
#define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
#else 
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
#endif /* STM32F10X_CL */
#endif /* HSE_VALUE */

What should I change this to? EDIT: Strangely, I can get the correct reading if I change the baud rate on my PC terminal ONLY to 4800 (the baud rate in the chip is still set to 9600)
Posted on October 05, 2015 at 14:44

What should I change this to?

Well what frequency source do you have on your board? Remember I know nothing about it.

Is it a 50 MHz source? Do you need to use BYPASS mode? ie a source rather than a crystal across the pins.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..