I have developed a Modbus slave which uses ATMega8A and MAX485. In a new lot of the devices, while testing them on my PC using QModMaster, the response that I get has one byte in front of it, and cuts-off at 8 bytes. The rest of it doesn't come, and therefore I get a CRC error.
Sample request and response:
[RTU]>Tx > 12:52:13:603 - 04 03 00 03 00 1B F5 94
[RTU]>Rx > 12:52:13:603 - 00 04 03 36 00 00 00 00
Sys > 12:52:13:603 - Error : Invalid CRC
[RTU]>Tx > 12:52:14:596 - 04 03 00 03 00 1B F5 94
[RTU]>Rx > 12:52:14:597 - 00 04 03 36 00 00 00 00
Sys > 12:52:14:597 - Error : Invalid CRC
Correct response looks like this:
[RTU]>Tx > 14:12:02:251 - 04 03 00 03 00 1B F5 94
[RTU]>Rx > 14:12:02:466 - 04 03 36 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 7F 8D
The funny thing is.. this happens only sometimes. At other times, the device sends data continously without error. I've also never observed the issue in a session when it sends the data. That is, if it sends the data correctly it sends it forever. If it doesn't, it doesn't. I've tried left and right to find out what might be causing the issue by checking the hardware. I can't even reliably recreate the issue.
J3 is shorted on the board.
I've done obvious things like:
- Changing the RS485 to serial converter
- Changing the laptop and master software used for testing I've also:
- Run the ATMega8a from a different 5V power supply (the device is given 24V, and uses LM2576 to generate 5V)
The issue occurs by chance under all these conditions.
Some points:
- There are no pull-ups or pull-downs on the controller side of MAX485
- I've given a 100ms delay after toggling the DE pin before and after transmitting data.
Could this be a problem with one batch of ICs? If it's an IC problem does it present itself intermittently? I was under the impression that if it's an IC problem, it should just not work, or send garbled data atleast.
I've put the same pair of MAX485 and ATMega on a different device, and it has been working fine. Although I wouldn't say that I have extensively tested it to the generate the issue.
Need to find the issue, and I don't have much time. I'm left with trying things trial and error, but I would like some good suggestions.