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

UART for non standard baud rate

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



Joined: 24 Aug 2010
Posts: 3

View user's profile Send private message

UART for non standard baud rate
PostPosted: Wed Aug 25, 2010 12:05 am     Reply with quote

Hi

Can I use uart for non standard baud rate?
Code:

#include <18F458.H>
#fuses HS, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=20000000)
#use rs232(baud=10400, xmit=PIN_C6, rcv=PIN_C7, ERRORS) 

Or do I need to create non standard function by myself ?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Aug 25, 2010 1:23 am     Reply with quote

The PIC processors can generate many non standard baud rates. The possible baud rates depend on your clock frequency and processor model. See the datasheet for examples.

The CCS compiler will generate an error message on compilation when the nearest possible frequency is more than 3% off. So, short answer, if the compiler doesn't complain your baud rate is possible.

P.S.: for a PIC18 at 20MHZ it most likely will generate a baud rate of 10417, an error of +0.16%
jbmiller



Joined: 07 Oct 2006
Posts: 73
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Aug 25, 2010 5:09 am     Reply with quote

Sure can ! Work 'backwards',do the math to find a crystal and dividers to get what YOU need.
I've done it for years as an 'antihacker' ploy. real hard to lock onto serial data at 8003 baud !
Just remember that basic timing won't be 'standard'( ie 4Mhz xtal= 1 us/cycle).
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Aug 25, 2010 7:37 am     Reply with quote

Hmm.... so acording to all previous posts, i can assume that i can implement MIDI !!!! its got a "wierd" baud rate as well (31250 bps)....

using a 1Mhz crystal / div 32? .... i dont really know how my pic's uart goes from 20Mhz to 9600bps

@jbmiller: if its not to much trouble could you explain a bit more on the math part?

sorry to parachute my way into this post Confused
_________________
CCS PCM 5.078 & CCS PCH 5.093
Gabriel



Joined: 03 Aug 2009
Posts: 1067
Location: Panama

View user's profile Send private message

PostPosted: Wed Aug 25, 2010 8:57 am     Reply with quote

never mind.....

PCM had a previous post on this....

thanks anyways...
_________________
CCS PCM 5.078 & CCS PCH 5.093
tumrobot



Joined: 24 Aug 2010
Posts: 3

View user's profile Send private message

PostPosted: Sun Aug 29, 2010 10:51 am     Reply with quote

I try to interface MCU to PC by use RS-232 baudrate 10400 at MCU and use Docklight Scripting V1.8 ser baudrate 10400 also.

I think it not working Crying or Very sad

Here is my code
Code:

#include <18F458.h>               // Standard Header file
#fuses HS,NOWDT,NOPROTECT,NOLVP      // Configuration word
#use delay(clock=20000000)           // oscillator
#use rs232(baud=10400 ,xmit=pin_c5,rcv=pin_c4,stream=HOSTPC,errors)

void main(void)



    while (TRUE)                  // Loop  nothing
   {

      fprintf(HOSTPC,"\r\n*** Test UART ***\r\n");
   }
}


So somebody have non standard baudrate function for RS-232?


Last edited by tumrobot on Sun Aug 29, 2010 10:40 pm; edited 1 time in total
andrewg



Joined: 17 Aug 2005
Posts: 316
Location: Perth, Western Australia

View user's profile Send private message Visit poster's website

PostPosted: Sun Aug 29, 2010 11:01 am     Reply with quote

Is the baud rate 10400 or 104000? Your post mentions both.
_________________
Andrew
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Aug 29, 2010 11:49 am     Reply with quote

Look at PDF page 187 of the datasheet for the PIC. It shows how to calculate the error for the desired bit rate.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
tumrobot



Joined: 24 Aug 2010
Posts: 3

View user's profile Send private message

PostPosted: Sun Aug 29, 2010 10:39 pm     Reply with quote

# andrewg

Quote:
Is the baud rate 10400 or 104000? Your post mentions both.


Sorry i need to use buad rate 10400

#bkamen
Quote:
Look at PDF page 187 of the datasheet for the PIC. It shows how to calculate the error for the desired bit rate.


CALCULATING BAUD RATE ERROR
TABLE 18-1: BAUD RATE FORMULA
TABLE 18-2: REGISTERS ASSOCIATED WITH BAUD RATE GENERATOR
Desired Baud Rate = FOSC/(64 (X + 1))
Solving for X:
X = ((FOSC/Desired Baud Rate)/64) – 1
X = ((20000000/10400)/64) – 1
X = [29.048] = 29
Calculated Baud Rate = 20000000/(64 (29 + 1))
= 10416
Error = (Calculated Baud Rate – Desired Baud Rate)
Desired Baud Rate
= (10416 – 10400)/10400
= 0.001538%

from the calculation should be working but i still can't comunication with 10400 buadrate Rolling Eyes
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Sun Aug 29, 2010 11:53 pm     Reply with quote

do you have an oscilloscope to check the output timing?

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Mon Aug 30, 2010 12:40 am     Reply with quote

Code:
#use rs232(baud=10400 ,xmit=pin_c5,rcv=pin_c4,stream=HOSTPC,errors)
Here you have changed the I/O pins from the hardware UART connections to other I/O pins. Why???

It should still work as the CCS compiler will create a software UART, but this comes with limitations that you should be aware of. For one, the hardware baudrate generator that you still refer to is not being used anymore and you lost the ability to use UART interrupts.

Is the program you posted the exact same program you are testing with?
I recommend you change the pins to the original C6 and C7 so the hardware UART is being used.
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