2021-07-13 01:19 AM
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.
2021-07-14 08:33 PM
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.
2021-08-06 06:06 AM
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.
2022-02-14 06:49 AM
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.
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?
2022-02-14 08:34 AM
>>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.
2022-02-17 05:37 AM
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.
2022-02-17 07:51 AM
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.
2022-02-17 09:00 AM
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.