CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Baud Rates and modes

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
rwskinner



Joined: 08 Dec 2006
Posts: 125
Location: Texas

View user's profile Send private message

Baud Rates and modes
PostPosted: Fri Feb 15, 2008 7:03 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Feb 15, 2008 8:25 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Feb 15, 2008 5:05 pm     Reply with quote

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







PostPosted: Sat Feb 16, 2008 5:27 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Feb 16, 2008 4:33 pm     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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