PDA

View Full Version : 9 Bit Transmission



Pesticida
- 3rd August 2007, 11:44
Hi,

I Know that I should use for a RS485 Transmission a 9 Bit Transmission,and that for example the 9th Bit for the Adress must be Set to 1.

But My Question is how can I do this with PicBasicPro.?
Did I Need a Word Variable or I can just use a Byte variable?

I Send The Data from MY PC with a Visual Basic Software !
Did I Need a Binary Transmission for my Visual Basic Software?

Thank You very much for any Answer !

Regard Pesti.

Jerson
- 3rd August 2007, 18:28
I Know that I should use for a RS485 Transmission a 9 Bit Transmission,and that for example the 9th Bit for the Adress must be Set to 1.

Not at all true. Most people use the 9 bit data format to achieve high speed data transfers. You can define your own protocol and use it with normal 8 bit data.

I generally use a protocol having a header like this


Destination address <1 byte> Source address <1 byte>
Command <1 byte> data <n bytes> Checksum <2 bytes>


Advantage of my method, you do not have to juggle VB to get the 9th bit

Jerson

dman776
- 3rd August 2007, 23:28
Jerson,
Can you elaborate on your method? It's sounds interesting since you apparently don't require any manipulation of the stop bit on the PC side.

Darryl

Jerson
- 4th August 2007, 06:04
Darryl

As I showed in the previous post, you build your own protocol. If you are doing ASCII commands, then you need a sync character to know the start of packet.



STX DST SRC CMD DATA.......DATA CS ETX


This can be the format for a typical packet. STX (02H) is the start character you seek to know there is a command / response packet. DST is the slave id which you want to talk to. SRC is the id of the master and can be omitted if there is a single master as in the case of a PC based logger. CMD tells the slave which function is being invoked and DATA passes parameters to the function if they are needed. Finally CS is a checksum to verify that the data packet has arrived without corruption. CS could be as simple as a LRC longitudinal redundancy check or as severe as a CRC16 cyclic redundancy check.

ETX (03H) generally is not needed but can be used to frame the command / response packet.

The slave responds with a message within the alloted time window (fixed by your program). If not, the master times out and understands that the slave is disconnected or not working. I have built many systems using this type of
protocol and it works really well.

You could look at the MODBUS specification if you want to learn more. MODBUS however offers an ASCII mode and a binary RTU mode. PLCs generally use the RTU mode to garner speed. In ASCII mode, you have to send every byte converted to 2 bytes of ASCII. So, a character like 02H will be sent as 30H, 32H. This is also applicable to the protocol I described above.

Jerson

Pesticida
- 4th August 2007, 08:11
Hi,

Thank You !

Yes I think I will use my own Protocoll !

But I dont understand how Can I send a 9 Bit Packet when a Byte have just 8 Bit?

9 Bit is more then 255 and is a Word Size !

Thats mean when I Use 9Th Bit I must send a Word Divided in two Bytes ?

Thanks

Regard Pesti.

Jerson
- 4th August 2007, 09:23
Pesti

You do not have to use 9 bits. Your standard serial UART will do the job just fine. I mentioned this earlier


You can define your own protocol and use it with normal 8 bit data.


When you use the 9 bit packets, you distinguish address and data bytes by the 9th bit alone. So, any byte having the 9th bit set is an 8bit address byte whereas all words with the 9th bit low are data.

Jerson

Pesticida
- 4th August 2007, 09:34
Ok I understand,but where is the 9th bit ?

When I send 1 Byte I have: 1 Start Bit,8 Data Bit,1 Stop Bit.
Where Is here the 9Th Bit? :-)

For example when I use Hyperterminal I can not adjust to 9th Bit I just have 7 or 8 Bit data.

Regard Pesti

Luciano
- 4th August 2007, 12:17
Hi,

The USART module of a PIC has multi-processor communication
capability using 9-bit address detection.

See this document:
http://www.datadog.com/rs485.pdf

Use The PC's UART With 9-Bit Protocols
http://www.elecdesign.com/Articles/Index.cfm?AD=1&ArticleID=6245
(You will have to wait 20 seconds before you see the doc).

See the datasheet of the used chip.

Best regards,

Luciano

Pesticida
- 4th August 2007, 17:48
Mille Grazie Luciano !

:-)

Regard Pesti

Luciano
- 5th August 2007, 11:53
Hi Pesti,

With the VB MScomm control you can set the parity as following:


Setting Description
E Even
M Mark
N (Default) None
O Odd
S Space


If you use MARK parity, then the bit after the data word is a logical 1.
If you use SPACE parity, then the bit after the data word is a logical 0.

With MARK parity the slave device will see the data as a 9-bit transmission. (Last bit = 1)
Use the MARK parity to send the address to the slaves.

With SPACE parity the slave device will see the data as a 9-bit transmission. (Last bit = 0)
Use SPACE parity to send the data to the selected slave.

http://img511.imageshack.us/img511/9220/paritybxx4.th.png (http://img511.imageshack.us/img511/9220/paritybxx4.png)
(Click on the picture to enlarge)

(VB pseudocode)

VB pseudocode
.....
Insert a delay here to ensure that UART FIFO buffer of the PC is
empty before you change the parity. The UART 16550 has up to 16 bytes
for the FIFO transmit buffer.

MSComm.Settings = "9600,M,8,1"
MSComm.Output = (The slave Address)

Insert a delay here to ensure that UART FIFO buffer of the PC is
empty before you change the parity. The UART 16550 has up to 16 bytes
for the FIFO transmit buffer.

MSComm.Settings = "9600,S,8,1"
MSComm.Output = (The data for the selected slave)
.....

From the Windows control panel you can adjust the size of the FIFO buffers of the used serial port.
http://img525.imageshack.us/img525/3177/fifoer2.th.png (http://img525.imageshack.us/img525/3177/fifoer2.png)
(Click on the picture to enlarge)

Best regards,

Luciano

Pesticida
- 5th August 2007, 12:27
Hi,

Thank You!

Thats it !
This is the Answer what I waiting for.

Now I know how to Programming the Software routines.

I use Pic 18f452 and I see on the PDF Datasheet that I can set the 9th Bit Transmission for RX and TX.

Thanks a lot Luciano!

Buona Giornata!


Regard Pesti.