View previous topic :: View next topic |
Author |
Message |
angel
Joined: 19 Oct 2004 Posts: 40
|
int_rda problem |
Posted: Thu Jun 18, 2009 3:55 am |
|
|
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
|
|
Posted: Thu Jun 18, 2009 8:23 am |
|
|
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
|
|
Posted: Thu Jun 18, 2009 9:23 am |
|
|
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
|
|
Posted: Thu Jun 18, 2009 9:23 am |
|
|
Actually, he is trying to send four.....
Even worse.
Best Wishes |
|
|
Wayne_
Joined: 10 Oct 2007 Posts: 681
|
|
Posted: Thu Jun 18, 2009 9:34 am |
|
|
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. |
|
|
angel
Joined: 19 Oct 2004 Posts: 40
|
thanks |
Posted: Fri Jun 19, 2009 1:22 am |
|
|
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
|
new question |
Posted: Fri Jun 19, 2009 2:15 am |
|
|
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
|
|
Posted: Fri Jun 19, 2009 12:22 pm |
|
|
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 |
|
|
|