RS232 timing on 16F628

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
pmcquail
Posts: 5
Joined: Thu Feb 16, 2006 11:44 am
Contact:

RS232 timing on 16F628

Post by pmcquail »

I have a problem using the RS232 component with the 16F627/8 chips.

If I set the line speed to 9600 and the clock speed to 20MHz all seems OK.

If I use a 4MHz crystal and set the clock speed to match I get an output line rate of around 2000 instead of 9600 baud. Any suggestions please?

Also how do you set parity/data bits/stop bits with the RS232 component?

User avatar
Steve
Matrix Staff
Posts: 3418
Joined: Tue Jan 03, 2006 3:59 pm
Has thanked: 114 times
Been thanked: 422 times
Contact:

Post by Steve »

To answer your second question first, the RS232 component uses the PICmicro's inbuilt USART in asynchronous (low speed) mode to send and receive data. To quote the datasheet of the PICmicro:
"In this mode, the USART uses standard non-return to zero (NRZ) format (one START bit, eight or nine data bits and one STOP bit)."
You could potentially use the optional 9th data bit as a parity, but you would need to calculate this yourself. You may also be able to use it as a second stop bit, but I'm not sure about this. Either way, you would need to do this with your own embedded 'C' code because the component itself will not allow you to do this.

As for your first question, the RS232 component within FlowCode assumes that the clock frequency of the micro is 19.6608MHz, which explain why you are getting an appropriate reading at 20MHz, but not at 4MHz. This is something we will look at changing in v3.

To get around this problem, you could look at the 'C' code generated by you program and embed a modified version of it into your FlowCode program to suit your clock speed / BAUD rate requirements. Unfortunately, you may not be able to get 9600 BAUD from a 4MHz crystal because of limitations of the PICmicro itself - unless you also use the high-speed asynchronous mode.

If you went down this route, I'd suggest using the "#defines" component containing your own C-code functions which you will then be able to call from anywhere within your program. Here's a simple example of such an embedded function that adds two numbers together...

1) Add a "#defines" component and put in the following code:

Code: Select all

//function prototype
char my_function(char var1, char var2);

//function implementation
char my_function(char var1, char var2)
{
    //adds two numbers together
    return (var1 + var2);
}
2) Call the "AddDefines" macro at the start of your flowchart.

3) Whenever you want to call this function, insert a 'C' icon with the following code inside (this will add 5 to the FlowCode variable "X" and store it in the variable "TOTAL"):

Code: Select all

FCV_TOTAL = my_function(FCV_X, 5);

pmcquail
Posts: 5
Joined: Thu Feb 16, 2006 11:44 am
Contact:

Post by pmcquail »

Many thanks.

Post Reply