|
|
View previous topic :: View next topic |
Author |
Message |
rwskinner
Joined: 08 Dec 2006 Posts: 125 Location: Texas
|
Baud Rates and modes |
Posted: Fri Feb 15, 2008 7:03 am |
|
|
I have a project that requires 9600,7,N,1 (Modbus ASCII Slave).
From what I understand the Pic USART will not handle 7 data bits, so does this mean when (7,N,1) is chosen that the program will use a software USART and simply bit bang it and interrupts can't be used? |
|
|
SET
Joined: 15 Nov 2005 Posts: 161 Location: Glasgow, UK
|
|
Posted: Fri Feb 15, 2008 8:25 am |
|
|
If you use 8 bits, then on receive your Ok - you'll simply have an extra bit (least significant if I remember right?), so you can right shift the result by one place. For transmit, left shift and make the LSB a 1, the MODBUS kit should then handle that Ok. |
|
|
rwskinner
Joined: 08 Dec 2006 Posts: 125 Location: Texas
|
|
Posted: Fri Feb 15, 2008 5:05 pm |
|
|
SET wrote: | If you use 8 bits, then on receive your Ok - you'll simply have an extra bit (least significant if I remember right?), so you can right shift the result by one place. For transmit, left shift and make the LSB a 1, the MODBUS kit should then handle that Ok. |
This was my exact, original idea until I was told the bits would still be off since there is no parity bit. I'm not real familiar so please jump in and correct me.
If I shift the data, then the data itself will be contain in 7 bits. We agree.
But if I'm sending it in a 8,N,1 format aren't I still sending 1 too many bits to the 7,N,1 system, or will the extra bit just be interpreted as an extra stop and be ignored.
7,N, 1
1 Start
7 Data
1 Stop
(9 bit times)
8,N,1
1 Start
8 data (even though the last bit is zero)
1 Stop
(10 bit times)
Just curious, and willing to learn. |
|
|
Ttelmah Guest
|
|
Posted: Sat Feb 16, 2008 5:27 am |
|
|
What you have to do, is make sure that the last bit of your 8bit data, is always a '1'. This then gives the effect of an extra 'stop' bit (which is unimportant, since 'stops' can be of indefinate length in RS232).
So:
Code: |
void send8(int8 chr) {
chr != 0x80;
putc(chr);
}
|
Obviously, if using streams, use 'fputc;' to the required stream, and then either just call this with the individual characters, or use this as the 'target' function for printf.
Best Wishes |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Sat Feb 16, 2008 4:33 pm |
|
|
Ttelmah wrote: | What you have to do, is make sure that the last bit of your 8bit data, is always a '1'. This then gives the effect of an extra 'stop' bit (which is unimportant, since 'stops' can be of indefinate length in RS232).
So:
Code: |
void send8(int8 chr) {
chr != 0x80;
putc(chr);
}
|
Obviously, if using streams, use 'fputc;' to the required stream, and then either just call this with the individual characters, or use this as the 'target' function for printf.
Best Wishes |
That would in effect be 7,N,2 or 7,N,1 with an extra bit time between each byte. MODBUS specification regarding time between bytes in a packet allows for this. It would be different for data going in the other direction. You cant receive 7,N,1 data with a USART set for 8,N,1. You could however receive data sent as 7,N,2 using the USART set as 8,N,1 with no problems. I would expect almost every implementation of MODBUS ASCII to allow 8,N,1, the PI–MBUS–300 specification requires it.
The format for each byte in ASCII mode is:
Coding System: Hexadecimal, ASCII characters 0–9, A–F
One hexadecimal character contained in each
ASCII character of the message
Bits per Byte: 1 start bit
7 data bits, least significant bit sent first
1 bit for even/odd parity; no bit for no parity
1 stop bit if parity is used; 2 bits if no parity
Error Check Field: Longitudinal Redundancy Check (LRC)
The important part is 2 stop bits if no parity. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|