cancel
Showing results for 
Search instead for 
Did you mean: 

UART stm32f4

boris23
Associate
Posted on September 25, 2015 at 10:47

Hello, I'm trying to run rs485 using transceiver sn65hvd11, and two 2 stm32f4. The first is a master, second is a slave. The problem is that I cant run the communication between the two devices. This is the code

while (!(GPIO_PIN_RESET == HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0))); // While I didnt press the button comunication didnt start
while (1)
{
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_12); // LED is blink
HAL_Delay(200);
strln = sprintf(temp_msg,''\n-----------------------------------------------------------------\n\n'');
HAL_UART_Transmit(&huart1,(uint8_t *)&temp_msg,strln,200); // transmit to PC if there is a problem with transmiting
/*=================================
Slave
===================================*/
//RESET = 0; SET=1;
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_RESET );//DE
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET );//RE
while (HAL_OK == HAL_UART_Receive(&huart3,(uint8_t *)&transmite_msg_translator,sizeof(transmite_msg_translator),200))
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_SET );
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET );
HAL_UART_Transmit(&huart3,(uint8_t *)&transmite_msg_translator,sizeof(transmite_msg_translator),200);
break;
}
/*=================================
END Slave
===================================*/ 
/*=================================
Master
===================================*/
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_SET );
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET );
HAL_UART_Transmit(&huart3,(uint8_t *)&transmite_msg_translator,sizeof(transmite_msg_translator),200);
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_RESET );
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_RESET );
if (HAL_OK == HAL_UART_Receive(&huart3,(uint8_t *)&transmite_msg_translator,sizeof(transmite_msg_translator),200))
{
HAL_GPIO_WritePin(GPIOA,GPIO_PIN_7,GPIO_PIN_SET );
HAL_GPIO_WritePin(GPIOC,GPIO_PIN_7,GPIO_PIN_SET );
HAL_UART_Transmit(&huart3,(uint8_t *)&transmite_msg_translator,sizeof(transmite_msg_translator),200);
}
else
{ 
HAL_UART_Transmit(&huart1,(uint8_t *)&warning_msg_translator,sizeof(warning_msg_translator),200);
}
/*=================================
END Master
===================================*/
}}

1 REPLY 1
Amel NASRI
ST Employee
Posted on October 01, 2015 at 10:48

Hi s.b.004,

To try to identify you problem root cause:

1- Do you have any error flag set?

2- Is the execution stuck at a given level? where exactly?

3- you may compare your code with the one provided in CubeF4 package (Ex: STM32Cube_FW_F4_V1.8.0\Projects\STM32F4-Discovery\Examples\UART\UART_TwoBoards_ComPolling).

-Mayla-

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.