cancel
Showing results for 
Search instead for 
Did you mean: 

Problem on routing of uart signals

michele239955_stm1_st
Associate II
Posted on January 13, 2014 at 19:48

Hi,

I have the stn32f4 discovery kit, and I tried to run the following code to send chracters to the uart :

-------------------------------------------------------

#include ''stm32f4xx.h''

 

/**************************************************************************************/

 

void RCC_Configuration(void)

{

  /* Enable GPIO clock */

  RCC_AHB1PeriphClockCmd (RCC_AHB1Periph_GPIOA, ENABLE);

 

  /* Enable USART clock */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE);

}

 

/**************************************************************************************/

 

void GPIO_Configuration(void)

{

  GPIO_InitTypeDef GPIO_InitStructure;

 

  /* Connect PA9 or PA1 to USART1_Tx */

//GPIO_PinAFConfig(GPIOA, GPIO_PinSource9,  GPIO_AF_USART1);

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource1,  GPIO_AF_USART1);

 

  /* Connect PA10 or PA2 to USART1_Rx */

//GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1);

  GPIO_PinAFConfig(GPIOA, GPIO_PinSource2,  GPIO_AF_USART1);

 

  /* Configure USART Tx as alternate function push-pull */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; // GPIO_Pin_1 or GPIO_Pin_9

  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(GPIOA, &GPIO_InitStructure);

 

  /* Configure USART Rx as alternate function push-pull */

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2; // GPIO_Pin_2 or GPIO_Pin_10

  GPIO_Init(GPIOA, &GPIO_InitStructure);

}

 

/**************************************************************************************/

 

void USART1_Configuration(void)

{

  USART_InitTypeDef USART_InitStructure;

 

  /* USART resources configuration (Clock, GPIO pins and USART registers) ----*/

  USART_InitStructure.USART_BaudRate = 1200;

  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 configuration */

  USART_Init(USART1, &USART_InitStructure);

 

  /* Enable USART */

  USART_Cmd(USART1, ENABLE);

}

 

/**************************************************************************************/

 

int main(void)

{

  RCC_Configuration();

 

  GPIO_Configuration();

 

  USART1_Configuration();

 

  while(1)

  {

    while(USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET); // Wait for Empty

 

    USART_SendData(USART1, 0x49); // Send 'I'

  }

 

  while(1); // Don't want to exit

}

 

/**************************************************************************************/

 

#ifdef  USE_FULL_ASSERT

 

/**

  * @brief  Reports the name of the source file and the source line number

  *         where the assert_param error has occurred.

  * @param  file: pointer to the source file name

  * @param  line: assert_param error line source number

  * @retval None

  */

void assert_failed(uint8_t* file, uint32_t line)

{

  /* User can add his own implementation to report the file name and line number,

     ex: printf(''Wrong parameters value: file %s on line %d\r\n'', file, line) */

 

  /* Infinite loop */

  while (1)

  {

  }

}

#endif

-------------------------------------------------------

This code runs well if I assign uart TX to pin PA9 and RX to PA10, but if I try to assign pins PA1 and PA2 for TX and RX, I cannot see the output signal (both signals stuck to Vcc).

Can you help me?

Thank you in advance

regards,

Michele
2 REPLIES 2
Posted on January 13, 2014 at 20:14

This code runs well if I assign uart TX to pin PA9 and RX to PA10, but if I try to assign pins PA1 and PA2 for TX and RX, I cannot see the output signal (both signals stuck to Vcc).

 

Indeed, the problem is you can't make magical pin assignment for the peripherals and expect them to work, you have to pick options described in the

http://www.st.com/st-web-ui/static/active/en/resource/technical/document/datasheet/DM00037051.pdf

. See Pg 60
Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
michele239955_stm1_st
Associate II
Posted on January 14, 2014 at 11:26

Thank you very much, cleve1, your replies are always very appreciated!

michele