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

int_rda problem

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



Joined: 19 Oct 2004
Posts: 40

View user's profile Send private message

int_rda problem
PostPosted: Thu Jun 18, 2009 3:55 am     Reply with quote

hi
I am using an int_rda in my program.
I am sending data to de pic.
After a data has reached the PIC there is un answer from the PIC: OK
The problem is I can't send the quantity of data I want... I would like to send data up to 16 kb. But sometimes only I can 600 bytes, 300 bytes... it changes....
I don't know what happen... I was wondering if it is necessary to remove something because it seems that a kind of memory is full (in the pic reception) and the PIC is not able to get more bytes... thanks for your help.
The program of the int_rda is:
Code:

#int_rda
void serial_isr() {

cc=fgetc(C67);
buffer[next_in]=cc;
........................
........................
fprintf(C67,"OK\r\n");//OK
}

-> buffer is: char buffer[512]; when the PIC gets 512 bytes, next_in is again 0.
-> and next_in is : unsigned long int next_in=0;
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Thu Jun 18, 2009 8:23 am     Reply with quote

First of all, it is best to place ERRORS in your #use statement.

Second, if you look close at your interrupt routine you're trying to send two characters, OK, out for every ONE character received. There's a awful lot of overhead used to print a character. Your routine is going to choke because it can't service the characters coming in fast enough while you're trying to print. Printing inside of an interrupt is not a good idea. Same goes with placing delays in one, just FYI. Try removing the printf() statement and add ERRORS and see how it goes.

If you do require some sort of confirmation that a character has been received then try simply echoing the character that was received by using a putc() in the isr. I've done that with success.

Ronald
PROCRASTINATORS UNITE!........ tomorrow
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Thu Jun 18, 2009 9:23 am     Reply with quote

actually i count FOUR chars out - when you include the CR/LINEFEED escapes.

what is the PURPOSE of this little bit o messed up code ?
Ttelmah
Guest







PostPosted: Thu Jun 18, 2009 9:23 am     Reply with quote

Actually, he is trying to send four.....
Even worse.

Best Wishes
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Jun 18, 2009 9:34 am     Reply with quote

16K of data ?
Where are you storing this ?

Also " char buffer[512];" isn't there an array size limitation ?
What PIC are you using ?
Are you using external storage eeprom or ram ?

What happens when it goes wrong ?
You say you can only send 300 bytes or 600 bytes, how do you know this ?

Does your PC check for OK response everytime it sends a char ?
Does the PIC stop responding ?

Could you post a small example program that runs and displays the problem.

Cheers. Smile
angel



Joined: 19 Oct 2004
Posts: 40

View user's profile Send private message

thanks
PostPosted: Fri Jun 19, 2009 1:22 am     Reply with quote

Hi everybody
Thanks for your help and suggestions.
Rnielsen suggestions have been good. The program works well but I have now to improve speed.

What was sending using the printf command, was only an example. The most important is the pic replays and then the PC knows when the interrupt int_rda has finished before sending more data. You are right, the only best option is to replay only a byte.

I don't try to save data into the PIC, but the program has the option to save data in a SD card.

The pic I am using is 18F2685. It has enough memory for a buffer of 512 bytes. No problem for that!!!

Question: PC check for OK response everytime it sends a char ?
Now it checks only a byte for every char. The next step would be to implement for example a first response when for example the buffer is full because I need a little of time to process it, and a second response when processing is finish. But it is only an example.

Thanks
angel



Joined: 19 Oct 2004
Posts: 40

View user's profile Send private message

new question
PostPosted: Fri Jun 19, 2009 2:15 am     Reply with quote

I was wondering if it is possible to get several data using one int_rda.
I mean instead of sending a byte, then to start the int_rda, get the data, ....and repeat the process again for the next data...
Is it possible to send for example 512 bytes for one action of the int_rda?
Possibly using kbhit inside int_rda?
Thanks
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Fri Jun 19, 2009 12:22 pm     Reply with quote

Whenever the receive buffer has received all 8 bits of data the ISR will be entered. You need to 'read' that data from the buffer and stuff the data somewhere. You can 'echo' the character back out the TXD pin but make things as short as possible. You are only able to receive one byte at a time. If too many bytes are being stuffed into the buffer then you will have an overrun and the port will lock up, unless you have ERRORS in your #use statement. But then you could lose data if this happens.

It's, usually, best to read the buffer with something like a getc() and stuff the character in an array of some kind and then exit the isr. If you need to manipulate that array, do it in the main body of your code. This won't cause the ISR to spend time moving data around when it really should be receiving data for you.

You can receive as much data as your PIC has room to store. But, you can only receive one byte at a time in the ISR.

Ronald
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