Skip to main content
nanotronicsnss
Associate III
July 13, 2021
Question

STM32H750VB MODBUS Timer Calculation

  • July 13, 2021
  • 3 replies
  • 4758 views

I am developing a project using STM32H750VB and for automation purpose I am in need of MOD BUS protocol. I have referred the code in this weblink (https://github.com/srikanth977/ModbusRTUSlave_RS232 ). I have completed the code and its working fine for the baud rate of 9600. But when I increase the baud rate then i am having a framing error. I do not understand whether the problem is with the code or with the timer calculation. So kindly guide me through the process of timer calculation. I have attached the images of framing error and the timer calculation for 19200 baud rate and 57600 baud rate.If possible suggest me how MOD BUS can be developed with HAL Library.

This topic has been closed for replies.

3 replies

TDK
July 15, 2021

If 9600 works, you should be able to half the prescaler to get 19200 working. If it's not, use a logic analyzer or scope to look at the signal on the line.

Frame error certainly suggests the clock is off from what is expected.

"If you feel a post has answered your question, please click ""Accept as Solution""."
nanotronicsnss
Associate III
August 6, 2021

Sorry for the late reply... I have done as u have said but the problem still exists. Kindly suggest if there is any availability of HAL library for MODBUS.

MAdam.7
Associate
February 14, 2022

I just wrote a basic modbus slave on the STM32F401RE.

I am using a Baudrate of 19200 (tested also with 9600) and with the terminal "hterm" everything is working fine. As you can see in the picture below... I am getting the right frame with its correct data.

0693W00000JPjl8QAD.png 

Usually I am using the program QModMaster which works fine with all of the modbus slave I've worked with in the past. Somehow using this program the last Byte of the crc checksum is not being transmitted. Does anyone have any Idea why?

0693W00000JPjl3QAD.png

Tesla DeLorean
Guru
February 14, 2022

>>Somehow using this program the last Byte of the crc checksum is not being transmitted. Does anyone have any Idea why?

You don't wait for the data to clock out on to the wire? TXE reflects a holding buffer, could perhaps be in the order of 20 baud clock cycles before the stop bit(s) leave via the shift-register.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
MAdam.7
Associate
February 17, 2022

Hello Tesla!

I am using the HAL_Transmit Function to write exactly the length I am writing to the function. My question is, why does the Modbus Master is receiving less bytes than Hterm. It looks o.k. on Hterm.

MAdam.7
Associate
February 17, 2022

That is the way I'm sending out the Data:

for (uint8_t c = 0; c < txBytesToSend; c++)
{
 USART2->DR = tx_Buffer[c]; // Load the Data
 while (!(USART2->SR & (1<<6)));
}

Between the read and the write operations there are no delays inside which could cause problems.

Tesla DeLorean
Guru
February 17, 2022

You should FRONT TEST for TXE, it indicates the DR buffer EMPTY, and can accept data. Don't blindly write to DR.

When all data has been sent you can BACK TEST for TC to indicate the UART has sent things

You should perhaps put a scope on the signal, and confirm that the last CRC bytes has left cleanly. Perhaps use a GPIO to trigger a Logic Analyzer so you can clearly capture the event for diagnostic purposed.

If you've confirmed it has left, then focus on the receiving end, as to why it doesn't receiver that byte. If there's anything going on with the signalling or delays causing that last byte to be missed, or some software side issue where it's not getting received or buffered, or recognized suitably.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..