2018-12-12 07:03 PM
Hi, All
I am using STM32F303CB to build a modbus environment which connected to RS485 bus.
(BTW, MCU as slave side)
I using STM32 HAL lib to setup whole UART & RS485 setting.
I suppose DE pin waveform should be matched to Slave_Tx ( X wrong)
-> The DE pin waveform should be driven to high until Tx send out data.
The DE pin is likely a periodic pulses. (That was strange)
My Schematic is as follow (485_DIR = DE)
Following are initial code ( HAL lib )
void SerialInit( UCHAR ucPORT, ULONG ulBaudRate, UCHAR ucDataBits, eMBParity eParity )
{
huart1.Instance = USART1;
(void)ucPORT;
(void)ucDataBits;
(void)eParity;
huart1.Init.BaudRate = ulBaudRate;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if (HAL_RS485Ex_Init(&huart1, UART_DE_POLARITY_HIGH, 0, 0) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
void HAL_UART_MspInit(UART_HandleTypeDef* huart)
{
GPIO_InitTypeDef GPIO_InitStruct;
if(huart->Instance==USART1)
{
/* USER CODE BEGIN USART1_MspInit 0 */
/* USER CODE END USART1_MspInit 0 */
/* Peripheral clock enable */
__HAL_RCC_USART1_CLK_ENABLE();
/**USART1 GPIO Configuration
PA9 ------> USART1_TX
PA10 ------> USART1_RX
PA12 ------> USART1_DE
*/
GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
/* USART1 interrupt Init */
HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USART1_IRQn);
/* USER CODE BEGIN USART1_MspInit 1 */
/* USER CODE END USART1_MspInit 1 */
}
2018-12-12 09:46 PM
What do you mean by "match" in "DE pin waveform is not matching to salve_Tx waveform"? DE should be active during the whole duration of transmitted frames (transmitted bytes), and it appears to be so. It of course cannot be identical to Tx.
JW
2018-12-12 11:12 PM
@JW Yes, you are right ( DE should be active during the whole duration of transmitted frames), even though, my DE still wrong.
2018-12-13 01:28 AM
I finally got the reason, cause I am using freeModbus lib, it will turn off interrupt when Rx or Tx done.
That will cause this phenomenon.