MX026 - RS485 using the EB062 E-Block

Forum to discuss articles which have been published in Matrix Multimedia's article zone. If you have any comments or questions regarding the articles please post them here.

Moderators: Benj, Mods

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Contact:

MX026 - RS485 using the EB062 E-Block

Post by Sean »

Article: http://www.matrixmultimedia.com/resourc ... php?id=437

Please discuss this article here.

Ron
Posts: 225
Joined: Wed Apr 11, 2007 6:15 pm
Contact:

Re: RS485 using the EB062 E-Block

Post by Ron »

Hello,

This is great! I just started working with RS485.

I have downloaded the samples but they do not load into my Flowcode. The error messages said something to the effect that my Flowcode is to old. Can you provide these examples for those of us that are using V3.

Also, I am using MAX3085 and MAX3075 chip sets. These are capable of handling up to 500K baud. Will Flowcode allow me to try these higher baud rates?

Thank you,

Ron

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Contact:

Re: RS485 using the EB062 E-Block

Post by Sean »

The drivers on the EB062 are also capable of operating at 500K baud (a requirement of the electrical specification). This is a theoretical maximum rate under ideal conditions which reduces with distance, loading, and cable quality.

Unfortunately we can not always provide examples for Flowcode V3. In this case the V3 RS232 component does not support the 9-bit data mode used to differentiate addresses from data in network applications.

If RS485 is being used as a high speed, long distance replacement for an RS232 link, existing RS232 programs can probably be used with almost no modification: Flow control is not used.
In Half Duplex mode a direction control signal is required.

The RS232 component allows custom Baud rates to be defined, so any rate that is supported by the microcontroller can be used.

kleberzeitounian
Posts: 5
Joined: Thu May 24, 2012 4:46 pm
Location: itapevi,sp,brasil
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by kleberzeitounian »

Boa tarde a todos, estou com problemas para utilizar os exemplos para rede RS485 que está disponível para download http://www.matrixmultimedia.com/article.php?a=419, o exemplo master e escravo disponivel está pronto para ser utilizado como exemplo, eles se comunica entre si, estou testanto no meus kit de desenvolvimento mas não existe respota do escravo, quando fico monitorando os dados enviados pelo mestre, recebo as informações corretamente no meu pc, quando coloco o master e escrava para se comunicar não existe comunicação de retorno do escravo, mesmo no simulador do flowcode5, percebo que ele não opera adequadamente, pode me ajudar.
Kleber Zeitounian
Zeitounian Tecnologia Ltda
Tel.: (11) 4773-5569
Cel.:(11) 9-8336-7655
e-mail.: kleber@zeitounian.com.br
HTTP://www.zeitounian.com.br
Skype = kleberzeitounian

kleberzeitounian
Posts: 5
Joined: Thu May 24, 2012 4:46 pm
Location: itapevi,sp,brasil
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by kleberzeitounian »

Boa tarde, efetuei teste utilizando os exemplos de mestre e escravo no flowcode5, meus testes foram efetuados em bancada com kits de desenvolvimento e através do simulador utilizando o VNET para testar o envio de dados através dos nós, porém o mestre fica enviando os dados, o escravo recebe mas não responde ao pedido de mestre, o que pode está errado neste exemplo, o endereçamento ou a codificação do comando, podem me ajudar.
Kleber Zeitounian
Zeitounian Tecnologia Ltda
Tel.: (11) 4773-5569
Cel.:(11) 9-8336-7655
e-mail.: kleber@zeitounian.com.br
HTTP://www.zeitounian.com.br
Skype = kleberzeitounian

kleberzeitounian
Posts: 5
Joined: Thu May 24, 2012 4:46 pm
Location: itapevi,sp,brasil
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by kleberzeitounian »

boa tarde preciso de melhores explicação de como faço o endereçamento de varios modulos utilizando os exemplos MASTER SLAVE que existe para download neste link. http://www.matrixmultimedia.com/article.php?a=419
Attachments
RS485.png
Poderia me explicar melhor como funciona as duas decisão da imagem em anexo.
(68.76 KiB) Downloaded 13537 times
Kleber Zeitounian
Zeitounian Tecnologia Ltda
Tel.: (11) 4773-5569
Cel.:(11) 9-8336-7655
e-mail.: kleber@zeitounian.com.br
HTTP://www.zeitounian.com.br
Skype = kleberzeitounian

kleberzeitounian
Posts: 5
Joined: Thu May 24, 2012 4:46 pm
Location: itapevi,sp,brasil
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by kleberzeitounian »

Bom dia, com base nos exemplos MASTER SLAVE para RS485 disponível em http://www.matrixmultimedia.com/article.php?a=419 como posso fazer a mudança de endereço, efetuei a mudança no MASTER para 02 e no SLAVE para 02, porém ele não comunica, qual o procedimento correto.
Kleber Zeitounian
Zeitounian Tecnologia Ltda
Tel.: (11) 4773-5569
Cel.:(11) 9-8336-7655
e-mail.: kleber@zeitounian.com.br
HTTP://www.zeitounian.com.br
Skype = kleberzeitounian

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Mantas »

Hello Sean,

Nice article, very informative, thank you.

A few questions:

1. If I use a RS485 interface via EB062 to transmit MODBUS RTU protocol which uses 8 data bits instead of 9 databits mentioned in this article it should be ok, I just have to set the databits to 8 in the properties window, right? And to reach every node (max 32) first I am sending the slave address, then function code, and so on...according to protocol structure.
2. What determines the max node count of 32 in RS485 interface?

Best regards,
Mantas
Science is my true religion.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Enamul »

Hi,
If I use a RS485 interface via EB062 to transmit MODBUS RTU protocol which uses 8 data bits instead of 9 databits mentioned in this article it should be ok, I just have to set the databits to 8 in the properties window, right?
You have to set as follows...
RS485.png
(59.55 KiB) Downloaded 23341 times
where the 9-bits will be..
9th bit = 1, 8 bits = node address
9th bit = 0, 8 bits = data
Therefore data is 8-bit not 9-bit so compatible with your requirement.
And to reach every node (max 32) first I am sending the slave address, then function code, and so on...according to protocol structure.
Yes. You will send slave address first with Addr_L = slave 8-bit address and Addr_H = 0x01 which will be combined likewise

Code: Select all

data_send=(Addr_H<<8) OR Addr_L
But for function code, Addr_L = function code and Addr_H = 0x00 which will be combined similarly

Code: Select all

data_send=(Addr_H<<8) OR Addr_L
What determines the max node count of 32 in RS485 interface?
Although it is mentioned in Sean's article but I could not find any limitation why not 256 as it is mentioned in EB062 datasheet. Theoretically it should be 2^8=256 as address bits are 8 bits.
Enamul
University of Nottingham
enamul4mm@gmail.com

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Sean »

The 32 node limit is an electrical restriction indicated in data sheets for the SN75176 and compatible devices.

The transmitter circuits are capable of driving 32 parallel 'unit loads' of 12K each (standard node input impedance). Special measures need to be taken to reach the theoretical software limit of 256 nodes.

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Mantas »

Thank you Enamul,

I was thinking of how to manage this 9th bit together with modbus protocol, and now you cleared my confusion so I can move on with my project :)

Best regards,
Mantas
Science is my true religion.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Enamul »

Hi Sean,
Thanks for the information. I had a quick look at the datasheet yesterday before posting my last post. But seems that I have missed that somehow..I found that today. You are absolutely right. I am posting screen shot from datasheet to avoid confusion.
Attachments
75176.png
(43.58 KiB) Downloaded 23321 times
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Mantas »

Hi Enamul,

One correction to your post:

Code: Select all

data_send=(Addr_H<<8) ^ Addr_L
Otherwise I was always sending 1 and 0. And Now I am simulating it via Vnet and it works perfectly.

Best regards,
Mantas
Science is my true religion.

User avatar
Benj
Matrix Staff
Posts: 15148
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Benj »

Hello,

I think it should really be like this.

Code: Select all

data_send=(Addr_H<<8) | Addr_L

This version is doing a logical or and will return 1 if either Addr_H or Addr_L has a bit that is set.

Code: Select all

data_send=(Addr_H<<8) || Addr_L
This versions is raising (Addr_H * 256) to the Power of whatever is in Addr_L.

Code: Select all

data_send=(Addr_H<<8) ^ Addr_L

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Enamul »

Hi,
Another thing I want to add with Ben, don't forget to declare data_send as INT. I forgot to mention in my post that. I always use OR in my codes. I just moved from that in the post you see made a mistake. :oops:
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Mantas »

Hello again,

OK, now I am really confused. First of all according to modbus.org documentation over a serial line it should be as follows:

The format for each byte ( 11 bits ) in RTU mode is :
Coding System: 8–bit binary
Bits per Byte: 1 start bit <---------------------------------this is done by RS232 component
8 data bits, least significant bit sent first <------------this is the data byte that has to be sent
1 bit for parity completion <------------------------------this is the 9th bit reserved for parity
1 stop bit <--------------------------------------------------this is done by RS232 component

Even parity is required, other modes ( odd parity, no parity ) may also be used. In order to ensure a maximum compatibility with
other products, it is recommended to support also No parity mode. The default parity mode must be even parity.
Remark : the use of no parity requires 2 stop bits.

I have read the forum here and Ben you have posted the following:
Flowcode v4 and v5 for PICs supports 9-bit data mode for sending and receiving 9-bits through the UART. This extra bit could easily be used for parity. The 9-th bit is enabled through the RS232 component properties window.
That means that 9th bit is reserved for parity by default parity mode. So where goes the bit 9 implementation for RS485??? :?
And I don't understand why would you need the 9th bit set to 1 if you are sending the address and 0 if you are sending the function code, then n*data, then 2 bytes of CRC? The Modbus RTU message frame is constructed in such a way that receiver noes when the message is started and which byte is the address byte, in this case the first one, so if the first byte sent matches the slave address it accepts the rest of the bytes until it notices a silent delay of 3.5 char or more and ends the reception process and continues with parity checking and CRC, unless If a silent interval of more than 1.5 character times occurs between two characters, the message frame is declared incomplete and should be discarded by the receiver.

So please correct me if I am wrong and clear my confusion.

And one more thing, the implementation of RTU reception driver may imply the management of a lot of interruptions due to the t1.5 and t3.5 timers. With high communication baud rates, this leads to a heavy CPU load. Consequently these two timers must be strictly respected when the baud rate is equal or lower than 19200 Bps. For baud rates greater than 19200 Bps, fixed values for the 2 timers should be used: it is recommended to use a value of 750μs for the inter-character time-out (t1.5) and a value of 1.750ms for inter-frame delay (t3.5). So I have build a master and slave programs to test this via Vnet server but I am getting frustrated with the timings. The thing is that when receiving I loop the receive char RS232 macro and make an array, with the if declarations to check for timeouts. So the RS232 is set to time out of 0 milliseconds, and after that I use a delay of 1us and if the data received is =255 I increment the counter. The receive loop is looped until the end condition is reached, which is count > 3.5c || count = 3.5c. the 3.5c and 1.5 c conditions are calculated as follows:

Code: Select all

boud_rate = 9600.0
c35 = (((11.0 / boud_rate) * 3.5) * 1000000.0) ////// number of bits set to 11.
c15 = (((11.0 / boud_rate) * 1.5) * 1000000.0)
this is in microseconds. So it ends up to be 3.5c = 4011 us, and 1719 us. So theoretically when the master sends a message it frames it like this: 3.5c delay [message] 3.5c delay. So the receiver should count up to 4011 or more to jump out of the receive routine and continue with the message processing. But when I simulate this on Vnet it is always stuck in the receive delay because it never counts to more than 4011. Is it some kind of simulation imperfection? How accurately is it representing the real hardware? Because It only works if I set the delay after the message to 1s with is too long and unacceptable to me.

I attach those two programs to make it more easier to understand it and troubleshoot it quicker:
MODBUS_RTU_CRC16_RS485.zip
MODBUS RTU CRC16 RS485
(14.74 KiB) Downloaded 612 times
Note that this has no parity bit implemented yet, so it is a rough sketch of what I think it should be.

I hope you are still reading the message, so thank you :)

Best regards,
Mantas
Science is my true religion.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Enamul »

Hi Mantas,
About all of your questions I would recommend you to read this pdf carefully first, then come again..this is very good point to start RS232 and RS485..also clears lots of issues..
http://www.eti.pg.gda.pl/katedry/ksg/dy ... /usart.pdf
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Mantas »

Thanks once again Enamul, I will get back to you once I've read it with even more questions :D

By the way I found a mistake in command macro, rs232 char there should not be any delay set to c15. after this the transmission end delay can get as low as 5ms, and Vnet simulation works.

Best regards,
Mantas
Last edited by Mantas on Thu Aug 23, 2012 12:26 am, edited 1 time in total.
Science is my true religion.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Enamul »

Hi,
No problem. :D We are ready in your support but want you to be satisfied of your own. Page 6 is very important for you..
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Mantas »

I understand what you mean, that you need a 9th bit to be as an indicator of address byte, but in modbus rtu protocol you have a framing silence delays to indicate the start and end of the frame, and the first byte is always the address.

I think this is what you wanted me to read, right?
Another advantage of having a ninth data bit is that it can be used as an address
indicator. This is commonly implemented on the RS-485 protocol. Each device on a
serial bus is assigned a specific address and monitors the data for transmissions with
the ninth bit set. When the ninth bit is set, the software on the PICmicro compares
the received data to its own address. If the addresses match, the software can enable
reception of the data that follows the address, but if the addresses do not match, the
data that follows is ignored.
So how would you suggest to put a parity bite and a address indicator bite in a 9 bit char if 8 bits are reserved for data transmission?

My gues is that MODBUS RTU RS485 is the same as RS232 just implemented on the RS485 electrical interface.

Best regards,
Mantas
Science is my true religion.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Enamul »

Hi Mantas,
To be straightforward, I should say 9th bit can be used in RS232 for either parity bit or extra stop bit but in RS485 address/data indication bit which keep no room for parity bit. So if you have to use parity bit, two simple solutions of this could be:

1. Avoiding indication bit: As your RS 485 devices already know first byte is address and following byte is function code, you can simply use 9th bit as parity for both address and function code. Although its not a good idea of skipping this indicative bit as that makes your task easier in receiver side to identify the address and function code easily. However, if you use this option in that case I will suggest you to use Addr_H as parity using Jonny's post:

Code: Select all

parity = (data) - ((data >> 1) & 0x55)
parity = (parity & 0x33) + ((parity & 0xCC) >> 2)
parity = (parity + (parity >> 4)) & 0x1
2. Double data: This option enables you to send address indicative bit. You can simply use above method to send parity as 9th bit and send first data_send INT will be 8-bit address and it's parity. Second data_send INT will be address indicative bit in Addr_L (i.e., Addr_L=0x01) and 9th bit will be it's parity. Similarly 3rd data_send will be function code and 4th data_send will be data indication bit (i.e., Addr_L=0x00) and 9th bit will it's parity. In this way you can send all information but I am not sure about your receiver device (RS485 slave)..I guess that's not a PIC..If it's a PIC in that case there is no problem but if it's an RS485 enabled device; you have to go with the communication protocol of that device and you don't have too much flexibility.
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Mantas »

Good morning Enamul,

I think the only way is the first way, as I am making a software to communicate with an RS485 enabled inclinometer, which cost >200$ US, so I wan to really know 100% that my program will work before spending those >200$.

Here are is a document about the inclinometer.

Best regards,
Mantas
Attachments
T7_Modbus_Communication_User_Guide_2.pdf
Datasheets
(192.24 KiB) Downloaded 564 times
Science is my true religion.

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Enamul »

Hi Mantas,
After having a quick look at the data sheet its clear that you can't use second option. But there shouldn't be any problem in using option 1.
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Enamul »

Hi,
I am posting on be-half of steve...
Hello,

I am V4 user so couldn't reply in the v5 forum,

saw that you where working on a modbus rtu interface.

http://www.modbus.pl/node/18

Found this quite usefull

Hope it helps

steve
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Contact:

Re: MX026 - RS485 using the EB062 E-Block

Post by Mantas »

Hi,

This is a little bit different approach, because I2C have the capability to acknowledged the byte receive and it is a synchronous serial communication, where the RS485 is asynchronous. While the protocol has to be implemented by the same standards, the communication interface and data exchange is totally different in I2C and RS485. In I2C the clock can vary, where on RS485 it not acceptable. So in other words, in I2C the data exchange is in sync, while on the RS485 bus it is a lot mote complicated, because devices may be totally out of sync (due to delays on the bus) and the data exchange must still happen successfully, so software wise its more difficult to implement modbus rtu on RS485 than on I2C, that is why the timings are so critical. Anyway, I have finished my software, and it is working well, on the Vnet simulations. Lets hope it will work on the real hardware even better :)

Best regards,
Mantas
Science is my true religion.

Post Reply