[BBB/BBG] RS485 read after write problem by linux 485 serial system call

Hi all

I’m useing debian 7.11(kernel 3.8) version image.
I’m trying to use rs485 cape on BBB or BBG. Below are the cape I use.
485 CAN CAPE
http://www.waveshare.com/wiki/RS485_CAN_CAPE
485 CLICK BOARD
http://www.mikroe.com/click/rs485-3.3v/

As I know these boards don’t have capability to auto handle read/write mode switching.
I try to use linux rs485 mode to auto handle switching problem.
The attached file is my sample code.

My problem is if I read data after writing, the receiving data will add a redundant data(0x00) at the beginning of the buffer.
Below is the result.
This is modbus command, that due to the redundant data, the modbus command will be failed.
So I use raw command to get data.

send: 01 04 00 00 00 01 31 CA
receive: 00 01 04 02 01 3E 39 70

send: 01 04 00 01 00 01 60 0A
receive: 00 01 04 02 00 E2 39 79

send: 02 04 00 00 00 01 31 F9
receive: 00 02 04 02 00 BA 7C 83

send: 02 04 00 01 00 01 60 39
receive: 00 02 04 02 00 FA 7D 73

send: 03 04 00 00 00 01 30 28
receive: 00 03 04 02 03 11 00 0C

send: 03 04 00 01 00 01 61 E8
receive: 00 03 04 02 00 DE 40 A8

This redundant data is not read data from modbus device. I use another rs485 cable to monitor the data will not have this redundant data.
Like this:
send: 01 04 00 00 00 01 31 CA
receive: 01 04 02 01 3E 39 70

If I only use receive mode, there will not be any redundant data in the buffer.

As I tried, kernel 4.4 cannot work 485 system call.

I’m not familiar in kernel, does anyone could give me some advice?

Many thanks,
Harvey

click_mod_sensor.py (4.35 KB)

Greetings— I have experienced this problem before. It is likely an issue with the physical interface, not software. Basically the issue is that the receiver is still receiving when the line goes to an idle undefined state, and receives “garbage” data. Search for RS 485 failsafe bias for more background. You will need some kind of biasing resistor to pull the line(s) up to a true idle state.

Hi Craig Markwardt

Thanks for your reply. I search some of this kind of article, and it seems doesn’t easy to understand the architecture.
Like this link: http://passive-components.eu/understanding-rs-485-passive-fail-safe-biasing/
Do you have any use case for me to reference? It will be very useful for me to design on our board.

Thanks a lot,
Harvey

Craig Markwardt於 2016年12月14日星期三 UTC+8上午12時33分03秒寫道: