Wio-E5 RS485 port doesn't work (LoRa-E5 dev kit)

Hello everyone.
I’m testing the RS485 port on this board by connecting two of them and sending a message via UART2, which according to the schematic is connected to the RS485 connector.

I’ve verified that the UART2 communication between the two boards works properly if I connect the TX2, RX2 pins, but when I switch to RS485 it stops working.

What could be causing this?
The jumpers to activate RS485 are properly connected in both boards, so it’s not that they’re disabled.

Hello! Which module do you mean? Is this one: https://www.seeedstudio.com/Wio-Terminal-Chassis-Battery-650mAh-p-4756.html?
Cessarr

No, I’m using the LoRa-E5 development board (https://www.seeedstudio.com/LoRa-E5-Dev-Kit-p-4868.html).

Hi, could you tell us how to connect the RS485 between the two board? such as the wire you are using, have you connect the GND line and so on?

I am using two boards, one that only sends UART messages via UART2 and one that receives them, and then re-sends them through UART1 to my PC to verify that the whole thing is working.

According to the board schematic, the RS485 port is controlled by the IC shown in the image below.

So, the first thing I tried was to check that the RS485 enable jumper (J17 in the image) was connected, which it was out of the box. Then, I set the ENRS485 pin (PB4) as a GPIO output, which I set high before calling HAL_UART_Transmit on UART2 and then back to low. On the receiving board, this pin is always low.

This didn’t work, so I looked into the HAL_UARTEx.c file (found within Drivers > STM32WLxx_HAL_Driver > Src) inside my STM32CubeIDE project. In there i found this function:

HAL_StatusTypeDef HAL_RS485Ex_Init(UART_HandleTypeDef *huart, uint32_t Polarity, uint32_t AssertionTime, uint32_t DeassertionTime);

I assumed that I had to use this instead of the HAL_UART_Init function that was automatically generated by the IDE:

static void MX_USART2_UART_Init(void)
{
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 9600;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  if (HAL_UART_Init(&huart2) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK)
  {
    Error_Handler();
  }
}

So, I slighty modified the above function to use the RS485 initializer:

static void MX_USART2_UART_RS485_Init(void)
{
  huart2.Instance = USART2;
  huart2.Init.BaudRate = 9600;
  huart2.Init.WordLength = UART_WORDLENGTH_8B;
  huart2.Init.StopBits = UART_STOPBITS_1;
  huart2.Init.Parity = UART_PARITY_NONE;
  huart2.Init.Mode = UART_MODE_TX_RX;
  huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
  huart2.Init.ClockPrescaler = UART_PRESCALER_DIV1;
  huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
  if (HAL_RS485Ex_Init(&huart2, UART_DE_POLARITY_HIGH, 8, 8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetTxFifoThreshold(&huart2, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_SetRxFifoThreshold(&huart2, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
  {
    Error_Handler();
  }
  if (HAL_UARTEx_DisableFifoMode(&huart2) != HAL_OK)
  {
    Error_Handler();
  }
}

Notice that the only change is in line 14. I figured out the parameters from this application note.

Still, it doesn’t work, and I think it’s because this initializer was made by STM for one of their boards, not the one I’m using. The IDE probably doesn’t even know that my board has an RS485 port, since when I created the project I only specified the MCU, not the board model itself.

My third solution was to enable the Hardware Flow Control (RS485) option for UART2 in the project’s .ioc file, which in turn enabled the PA1 pin.

image

This didn’t solve anything, but it changed the default MX_USART2_UART_Init function to use HAL_RS485Ex_Init(&huart2, UART_DE_POLARITY_HIGH, 0, 0) as an initializer, like I did before but with slightly different parameters.

Then I tried to set the PA1 pin high before transmitting, then PB4 pin I’d tried before, and finally both pins. Nothing yet.

I connected to the first board’s A pin to the second’s A, same for the B and GND pins. I’m using solid AWG 22 wire for the connections, which I just insert into the ports and then fix in place with the screws (see the green port at the bottom right of the board).

The 485 chip has an enable pin (DE/RE) that needs to be enabled before it can be sent. Please note that when reading and writing, this IC’s level is different.
企业微信截图_fd17ca29-de34-40fc-befe-c26c23dc63de

My understanding is that the enable pin you mention (ENRX/TX) is just routed to the ENRS485 pin (PB4) as long as the J17 jumper is connected, which I made sure it was. I don’t see any more references to ENRX/TX on the schematic, so I suppose there´s no other way to drive it directly, only via PB4.

So, all I would need to do is to set the PB4 high for receiving and low for sending, which I’m already doing, yet it doesn’t work. (I’ve also tried the opposite polarity just in case)

Am I wrong? Is there another pin I need to control, or do I need to configure the PB4 pin in some way in the project´s .ioc file?

Hi There ajs00,
So from what I gleaned the interrupt also controls the PIN? and resets it?
also what’s the rs-485 a terminal port ie.HALF duplex (2-wire) the timing is tight at Higher baud rates, You may want to add some delay in looking for the line turn-around or data.
So are You wired

| PC<--USB-->LoRa-E5 <RS-485>----<RS-485>LoRa-E5 <UART> (message TTL) ? or 3.3v

It would make sense that code and configured for the other jumper setting (TX/RX) the fullduplex is built in.
I like these boards but don’t have one (it’s on the list, LOL)
HTH
GL :slight_smile: PJ