AnsweredAssumed Answered

STM32F0- RS485 communication problem

Question asked by aruns06 on Jul 9, 2014
Latest reply on Jul 14, 2014 by aruns06
Hi,
I am trying to connect STM32F0 board with an energy meter. The Energy meter supports RS485 protocol. I have connected USART 2 to MAX 485 and the o/p of the MAX485 is connected to a level shifter 74ls25 and then to energy meter. But I'm ot getting reply from energy meter.
Following is the code section.  don't know whether any change in configuration of STM32 rs485 initialization.

void init_rs485(COM_TypeDef com, USART_InitTypeDef* USART_InitStructure)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  USART_ClockInitTypeDef USART_ClockInitStructure;
  //USART_DeInit(USART2);
 
    /* Configure gpio pin for DE to control data flow of max485  */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
   
  /* Configure USART Tx as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
  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_3;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed =  GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
   
  /* Enable GPIO clock */
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOA, ENABLE);
 
  /* Enable USART 1 clock */
  //if(com == COM1)
 // RCC_APB2PeriphClockCmd(COM_USART_CLK[com], ENABLE);     ///commented by DTS for usart1
 // else if(com == COM2)
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);       /// for USART2 DTS
  /* Connect PXx to USARTx_Tx */
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_1);
 
  /* Connect PXx to USARTx_Rx */
  GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_1);
   
 //  GPIOA->BSRR = GPIO_Pin_8;
   
  USART_InitStructure->USART_BaudRate = 9600;
  USART_InitStructure->USART_WordLength = USART_WordLength_9b;    // previously it was USART_WordLength_8b
  USART_InitStructure->USART_StopBits = USART_StopBits_1;
  USART_InitStructure->USART_Parity = USART_Parity_Even;         // vriable parameter. Based on the data to be sent.
  USART_InitStructure->USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
  USART_InitStructure->USART_HardwareFlowControl = USART_HardwareFlowControl_None;
  /* USART configuration */
  USART_Init(USART2, USART_InitStructure);
  // USART_ClockInit(USART2,&USART_ClockInitStructure);
 
  /* Enable USART */
  USART_Cmd(USART2, ENABLE);
   
   
}
 After the initialization, I have started sending data via usart1 and then a small is given and receive function starts....
Is there any problem in usart 1????
Regards,
Arun.S

Outcomes