cancel
Showing results for 
Search instead for 
Did you mean: 

UART initialisation

fabricepeden
Associate II
Posted on February 22, 2013 at 09:24

Hi everybody,

I'm using a STM32F205VE and something that I don't understand.

I do this :

  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_Mode = USART_Mode_Rx | USART_Mode_Tx;

  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

  USART_Init(USART6,&USART_InitStructure);

and I can see the configuration into the USART6 register.

I do the same thing for USART3 and nothing happen, no registers are configurated.

Have you some ideas about this problem ? Must I do something special for this USART ?

Thank you in advance,

5 REPLIES 5
Posted on February 22, 2013 at 09:33

 *          ===================================================================

  *                                 How to use this driver

  *          ===================================================================

  *          1. Enable peripheral clock using the follwoing functions

  *             RCC_APB2PeriphClockCmd(RCC_APB2Periph_USARTx, ENABLE) for USART1 and USART6

  *             RCC_APB1PeriphClockCmd(RCC_APB1Periph_USARTx, ENABLE) for USART2, USART3, UART4 or UART5.

Posted on February 22, 2013 at 09:43

For synchronous designs, Rule#1 : Enable the clock.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
fabricepeden
Associate II
Posted on February 22, 2013 at 09:50

Sorry, I think I will post all my code, it would be easier for everybody.

 /* COM1 - NETWORK OUT */

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE);

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC,ENABLE);

  

  GPIO_PinAFConfig(EVAL_COM1_TX_GPIO_PORT,EVAL_COM1_TX_SOURCE,EVAL_COM1_TX_AF);

  GPIO_PinAFConfig(EVAL_COM1_RX_GPIO_PORT,EVAL_COM1_RX_SOURCE,EVAL_COM1_RX_AF);

  

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

  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_InitStructure.GPIO_Pin = EVAL_COM1_TX_PIN;

  GPIO_Init(EVAL_COM1_TX_GPIO_PORT, &GPIO_InitStructure);

  

  GPIO_InitStructure.GPIO_Pin = EVAL_COM1_RX_PIN;

  GPIO_Init(EVAL_COM1_RX_GPIO_PORT, &GPIO_InitStructure);

  

  /* Configuration : 115200 bauds, 8 N 1 */

  USART_InitStructure.USART_BaudRate = 115200;

  USART_InitStructure.USART_WordLength = USART_WordLength_8b;

  USART_InitStructure.USART_StopBits = USART_StopBits_1;

  USART_InitStructure.USART_Parity = USART_Parity_No;

  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

  

  /*USART_OverSampling8Cmd(EVAL_COM1,ENABLE);*/

  

  USART_Init(EVAL_COM1,&USART_InitStructure);

 

  /* Enable the USARTx Interrupt */

  NVIC_InitStructure.NVIC_IRQChannel = EVAL_COM1_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

  

  USART_ITConfig(EVAL_COM1, USART_IT_TXE, DISABLE);

  USART_ITConfig(EVAL_COM1, USART_IT_RXNE, ENABLE);

  

  /* Enable USART */

  USART_Cmd(EVAL_COM1, ENABLE);

  

  /* Configuration de la PIN REDE */

  COMRDInit(COM1);

  

  /* COM2 - NETWORK IN */

  /* COM1 - NETWORK OUT */

  RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD,ENABLE);

  

  GPIO_PinAFConfig(EVAL_COM2_TX_GPIO_PORT,EVAL_COM2_TX_SOURCE,EVAL_COM2_TX_AF);

  GPIO_PinAFConfig(EVAL_COM2_RX_GPIO_PORT,EVAL_COM2_RX_SOURCE,EVAL_COM2_RX_AF);

  

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

  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_InitStructure.GPIO_Pin = EVAL_COM2_TX_PIN;

  GPIO_Init(EVAL_COM2_TX_GPIO_PORT, &GPIO_InitStructure);

  

  GPIO_InitStructure.GPIO_Pin = EVAL_COM2_RX_PIN;

  GPIO_Init(EVAL_COM2_RX_GPIO_PORT, &GPIO_InitStructure);

  

  /* Configuration : 115200 bauds, 8 N 1 */

  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_Mode = USART_Mode_Rx | USART_Mode_Tx;

  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

  USART_Init(EVAL_COM2,&USART_InitStructure);

 

  /* Enable the USARTx Interrupt */

  NVIC_InitStructure.NVIC_IRQChannel = EVAL_COM2_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

  

  USART_ITConfig(EVAL_COM2, USART_IT_TC, ENABLE);

  USART_ITConfig(EVAL_COM2, USART_IT_RXNE, ENABLE); 

  

  /* Enable USART */

  USART_Cmd(EVAL_COM2, ENABLE);

  

  /* Configuration de la PIN REDE */

  COMRDInit(COM2);
Posted on February 22, 2013 at 11:04

>   RCC_APB2PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

 *          ===================================================================

  *                                 How to use this driver

  *          ===================================================================

  *          1. Enable peripheral clock using the follwoing functions

  *             RCC_APB2PeriphClockCmd(RCC_APB2Periph_USARTx, ENABLE) for USART1 and USART6

  *             RCC_APB1PeriphClockCmd(RCC_APB1Periph_USARTx, ENABLE) for USART2, USART3, UART4 or UART5.

JW

fabricepeden
Associate II
Posted on February 22, 2013 at 15:24

Thank you for your answer.

Now my registers are well configured.

I'll see if my UART is working !