cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F207 Usart TX-RX with Parity_even

momede
Associate II
Posted on May 01, 2012 at 15:20

Dear all,

I'm in trouble with usart to communicate with a peripheral that use parity even.

I'm working with STM32F207 and I have an RS485 transceiver

I have configured the usart as below:

void USART3_Config (void)

{

  USART_InitTypeDef USART_InitStructure;

  GPIO_InitTypeDef GPIO_InitStructure;

  NVIC_InitTypeDef NVIC_InitStructure;

    /* Enable GPIO clock */

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);

 

  /* Enable UART clock */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);

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

  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;

  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;

  /* Connect PXx to USARTx_Tx*/

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3);

  /* Connect PXx to USARTx_Rx*/

  GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);

  /* Configure USART Tx as alternate function  */

  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOC, &GPIO_InitStructure);

 

  /* Configure USART Rx as alternate function  */

   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;

   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;

   GPIO_Init(GPIOC, &GPIO_InitStructure);

 

  /* Enable the USARTx Interrupt */

  NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;

  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

  /* USART configuration */

  USART_Init(USART3, &USART_InitStructure);

    

  /* Enable USART */

  USART_Cmd(USART3, ENABLE);

  USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);

  ENABLE_RX_3();

}

______________________________________________________________________

in the main code I wrote an example to send a string to the pc.

  sprintf(TxCommand,''99ms\r'');

  USART_ITConfig(USART3, USART_IT_RXNE, DISABLE);   

  ENABLE_TX_3();

  USART_ITConfig(USART3, USART_IT_TXE, ENABLE);

  while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET)

  {}

  ENABLE_RX_3();

  USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);

______________________________________________________________________

in the interrupt code:

void USART3_IRQHandler(void)

{

  if (USART_GetITStatus(USART3, USART_IT_TXE) == SET)

  {    

    USART_SendData(USART3, TxCommand[IndexTx++]);

    if(IndexTx > CHARCMD - 1)

    {    

      /* Disable the USART3 transmit data register empty interrupt */

      USART_ITConfig(USART3, USART_IT_TXE, DISABLE);   

    }

  }

........

What I see is that the characters that I have on the pc aren't the right characters that I sent, if I send the character from the pc to the microcontroller it read properly of microcontroller.

If I remouve the parity control also from Micro to the pc the communication works properly

Someone can help me to understand where I'm in wrong.

Many thanks for your help.

Best regards.
2 REPLIES 2
oskari
Associate
Posted on May 04, 2012 at 12:20

Have you tried to use USART_WordLength_9b? When you use parity you have 8 data bits + 1 parity bit.

oskari
Associate
Posted on May 04, 2012 at 12:21

Have you tried to use USART_WordLength_9b? When you use parity you have 8 data bits + 1 parity bit.