cancel
Showing results for 
Search instead for 
Did you mean: 

STM32f405RGT6 UART4 and USART3 TX problems

tylere
Associate II
Posted on October 31, 2014 at 12:11

I'm at wits end trying to figure out why exactly I can't transmit on UART4 or USART3.

The RX works, and i can receive data, however the TX pin is not working at all. Below is my configure code for UART4.

void init_usart4(uint32_t baudrate) {

  GPIO_InitTypeDef GPIO_InitStructure;

  USART_InitTypeDef USART_InitStructure;

  NVIC_InitTypeDef NVIC_InitStructure;

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_UART4, ENABLE);

  /* GPIOA clock enable */

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

  /* GPIOA Configuration:  USART2 */

  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_UP;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

  /* Connect USART1 pins*/

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_UART4);

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_UART4);

  USART_InitStructure.USART_BaudRate = baudrate;

  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_Mode_Rx;

  USART_Init(UART4, &USART_InitStructure);

  USART_Cmd(UART4, ENABLE);  // enable USART2

}

and in main i just loop and use ''USART_SendData(UART4, 'h');'' with a delay

I've scoped the pin and nothing is coming out of it either I've changed out MCU's completely thinking I might've got a bad one but that hasn't fixed it either
5 REPLIES 5
chen
Associate II
Posted on October 31, 2014 at 12:19

Hi

The only difference I can see between what you have and what I have in a project is :

''    USART_Cmd( USART3, DISABLE );'' before the USART configuration

Interrupts (NVIC) is configured for USART recieve

I am using PortB same Portbits (10 & 11)

and it works.

Also, I have not found it but the USART peripheral probably needs to be taken out of reset (bit in RCC register somewhere)

tylere
Associate II
Posted on October 31, 2014 at 13:00

I've added in the disable as well as a deinit as well, still nothing.. this is getting frustrating

Posted on October 31, 2014 at 14:11

Should wait on TXE before writing out data. Write a constant stream of characters, look at the signal with a scope. Consider what circuitry you have connected to PC10.

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

I've added in waiting for the txe flag, still nothing, and i've already looked at it with a scope, nothing is coming out of the pin, the only thing attached to that pin is the RX of a rn-41 bluetooth module

and yes there is continuity between the Rx pin of the stm and the tx pin of the bluetooth module

and yes i've removed the bluetooth and scoped the pin, still no output

Posted on October 31, 2014 at 21:21

Code looks fine, the fact it doesn't work with either USART/UART configurations suggests you're not looking at the right pin, or the pin is shorted. Perhaps you can drive the pin high/low as a GPIO and confirm you can see that.

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