EmbeddedRelated.com
Forums

listening to rs485 serial port on BL4S200

Started by "yan...@omniverter.com [rabbit-semi]" August 10, 2016
Hi Ya
Hi Yang,

I've just uploaded this morning my code for the Modbus master. Hopefully you can get some inspiration from my ISR and modify it for a slave implementation.

Cheers,
Mircea
Hi Mircea,

With any reason I could not get your code of modbudbus_master.c, from the yahoo group, Could you send the file to me if you do not mind.. Thanks

Regards,

Henry Huynh
[ADI_Logo_small]
Analog Devices, Inc.
Wilmington Manufacturing Division
804 Woburn Street
Wilmington, MA 01887
Email: H...@analog.com
Phone: (781) 937-2320
Fax: (781) 937-2011

From: r... [mailto:r...]
Sent: Wednesday, August 10, 2016 11:04 PM
To: r...
Subject: RE: [rabbit-semi] listening to rs485 serial port on BL4S200

Hi Yang,

Sorry I have to disagree with Tom but Modbus is quite sensitive to timing issues: You have the 1.5 characters maximum delay between characters and the 3.5 characters spacing at the end of each message. Even parsing messages becomes complicated if you don't rely on the 3.5 characters gap between messages.

Not too long ago I had to implement a Modbus master on a a Rabbit module and pretty much I had to start from scratch. There is a Digi library for Modbus but exactly this low level part is not very well implemented.

At 115K baudrate (assuming 8-N-1 format which makes for 10 bits per char) the delays you are dealing with are:
- 1.5 chars = 0.13ms You have to send your answer without any gaps larger than that. Make sure you prepare your whole reply before starting to send and don't even dream about not using interrupts to pump out the whole message.

- 3.5 chars = 0.3ms Any receiving gap larger than this must be interpreted as an end of message and you have to parse that message. If the message is not addressed to you, the other slave will probably reply and will see its reply in your receive buffer (that's just the nature of RS485 bus). The only guidance you have to make sense of all that traffic are the 0.3ms gaps that you will see in the data stream.

When I'm talking about the 3.5 characters gap it doesn't mean you have to answer immediately when that delay expires. Most masters will accept a reasonable delay (frequently 1 sec) for a slave to answer. It means only that you must be prepared to correctly interpret the Modbus traffic, even if it is generated by communication with a very fast client.

If you need more explanations let me know. Also if you need my code (sorry, it is for a Modbus master).

Cheers,
Mircea
---In r..., > wrote :

Hello, Tom:

Thank you for your response. Actually, I am using serval “costate” with different loop timing. My current serial port use one of them “costate” with 15 msec loop time. My RS485 port use 115kbps. Do you think how often checking serial port is reasonable according to your experience?

Regards,

Yang

From: r... [mailto:r...]
Sent: Wednesday, August 10, 2016 2:01 PM
To: r...
Subject: Re: [rabbit-semi] listening to rs485 serial port on BL4S200

Your program is the only thing running, and the BL4S200 runs at a fixed speed. A typical program is going to have a big loop where it checks for things to do. The overhead of checking for available data on a serial port is negligible in the overall time it takes that loop to run, so it's probably fine as it is. And in most cases, you're better off processing serial data at a known point in program execution, instead of interrupting some other task to process it.

-Tom

On Aug 10, 2016, at 10:28 AM, yang@... [rabbit-semi] wrote:

I am using BL4S200 for my control project. BL4S200 is a slave device. Other equipment uses Modbus RS485 to communicate BL4S200. Actually, everything is working, but the only thing is I need use loop to check serial port weather I receive any request, is it possible to use some internal interrupt to detect information received on serial port? so I can remove the fast loop to save some resource.