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 CCS Technical Support

rs232 [and other] problems

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



Joined: 04 Nov 2003
Posts: 1

View user's profile Send private message

rs232 [and other] problems
PostPosted: Wed Jan 28, 2004 6:07 am     Reply with quote

Hello all,

Ive got problems.
Im working on a little device that converts a (nearly) continuous input data stream through the rs232 port at 9600bps, and outputs a transformed version of the data at 500bps.

I am using the built in rs232 controller on the PIC to handle the incoming data, and i have written a function to output data on a particular pin in an rs232 format.

Code:

void soft232(int k)
{
    int i;
    int a[10];
    a[0] = 0;   // start bit
    a[9] = 1;   // stop bit

    // fill packet with data
    a[1] =  k & 0b00000001;
    a[2] = (k & 0b00000010) >> 1;
    a[3] = (k & 0b00000100) >> 2;
    a[4] = (k & 0b00001000) >> 3;
    a[5] = (k & 0b00010000) >> 4;
    a[6] = (k & 0b00100000) >> 5;
    a[7] = (k & 0b01000000) >> 6;
    a[8] = (k & 0b10000000) >> 7;

    // output rs232 packet.
    for(i=0;i<9;++i){
        output_bit(soft232_Xmit, a[i]);
      
        ************************************************
        delay_us(2000);  // this delay sets the output pulse width.
        ************************************************
    }
}

The PIC I am using is a 16F877.

Now the problem i have is that you cannot transmit AND receive data at any one time. In its current state if I try to make my program work it accepts about 3 input characters and then crashes, which i assume would be the input rs232s' hardware buffer overflowing. If i reduce the delay
in the software232 then the program works just fine, so the delay must be holding up the processor in some way such that it is causing the input buffer to overflow.

So how on earth do i get around this????
BTW I dont have the luxuary of data streams as i have an old compiler.
_________________
there are only 10 types of people. those who understand binary and those who dont.
Jos



Joined: 15 Sep 2003
Posts: 4

View user's profile Send private message MSN Messenger

PostPosted: Wed Jan 28, 2004 6:44 am     Reply with quote

Try to use a software receive buffer. I use the example below. The isr will overwrite the last byte of rs232buffer[] if the sofware buffer is full. You should do the buffer reading in your "main" code! You will get hardware buffer overruns if your isr is to long.

#int_rda
void rda_isr(void)
{
byte tmpByte;

rs232buffer[nextByteIn] = getc();
tmpByte = nextByteIn;

nextByteIn = (nextByteIn + 1) % RS232_BUFFER_SIZE;

if(nextByteIn == nextByteOut)
{
nextByteIn = tmpByte; //Buffer full!
}
}

Greetz
Justy



Joined: 28 Jan 2004
Posts: 6
Location: Montr�al

View user's profile Send private message

PostPosted: Wed Jan 28, 2004 1:45 pm     Reply with quote

I'm programing right now throught rs232 and i've notice that you might be missing an instruction. I'm programing with Mplab system. So try this thing.

put on the top on your program

#use rs232 (baud=9600, xmit=pin_(pic pin out number), rcv=pin_(pic pin in number) )
Justy



Joined: 28 Jan 2004
Posts: 6
Location: Montr�al

View user's profile Send private message

PostPosted: Wed Jan 28, 2004 1:48 pm     Reply with quote

sorry i've just notice that you are using the same pic as I do

so like i've said in your declaration ...not in your program right that

#include "16F877.h"
#use rs232 (baud=9600, xmit=pin_c6, rcv=pin_c7)


that should work
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