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

Re: Unable to read all receive bytes

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







Re: Unable to read all receive bytes
PostPosted: Wed Aug 20, 2003 8:07 am     Reply with quote

I'm no expert at all, so I could be wrong... I know there's a buffer on the receiver of 3 characters. You might just be reading the 1st two chars when the int_rda fires indicating more than that in the buffer and leaving the other 3 behind (does int_rda stay set after the isr until the buffer is emptied?). You'd see no hangup/error as #use rs232 has the errors option set. As a quick hack, stick a few ms delay in the PC code between sending chars to the PIC. Also look at the RS232_ERRORS variable.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517108
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

Re: Unable to read all receive bytes
PostPosted: Wed Aug 20, 2003 10:25 am     Reply with quote

:=I'm trying to do a simple test to illustrate the timer and rda interrupts.
:=Each time the timer interrupt is called it serially sends a 5-byte message. If the PC sends a 5-byte message i.e. 0xB2, 0x07, 0x02, 0x01, 0x01, the test program below is meant to echo it back. However, it seems that the serial interrupt is only called twice because it only echoes back the first 2 bytes.
:=
:=There is hardly any code in the rda interrupt.
:=
:=Why is this so? I must be missing something here. I'm using the #use rs232(baud =19200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
:=
:=
:=int array[10];
:=short int flag_fifo = 0;
short int flag_timer2 = 0;
:=int a = 0;
:=
:=
:=test_tx( int x1, int x2, int x3, int x4, int x5)
:={
:= putc(x1);
:= putc(x2);
:= putc(x3);
:= putc(x4);
:= putc(x5);
:=}
:=
:=
:=#int_rda
:=serial_isr()
:={
:= array[a] = getc();
:= a++;
if(a >= 4)
{flag_fifo = 1;}
:= disable_interrupts(INT_TIMER2);
:=}
:=
:=
:=
:=#int_timer2
:=timer2_isr()
{
flag_timer2 = 1;
}
Note: keep your isr routine as short as possible
//:={
//:= test_tx(0xB1, 0x53, 0x08, 0x07, 0x01);
//:=}
:=
:=
:=
:=main()
:={
int b;

:= while(1)
:= {
:= enable_interrupts(INT_TIMER2);
:= enable_interrupts(INT_RDA);
:= enable_interrupts(GLOBAL);
:=
:= //do something here
:=
:= if(flag_fifo)
:= {
disable_interrupts(GLOBAL);
for(b = 0; b <= a; b++)
:= {
putc( array[b] );
:= }
:= flag_fifo = 0;
:= a = 0;
enable_interrupts(GLOBAL);
:= }

if(flag_timer2)
{
disable_interrupts(GLOBAL);
test_tx(0xB1, 0x53, 0x08, 0x07, 0x01);
enable_interrupts(GLOBAL);
flag_timer2 = 0;
}
:= }
:=
:=}

Hope this help.

rgds

Humberto
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517109
_________________
Humber
R.J.Hamlett
Guest







Re: Unable to read all receive bytes
PostPosted: Wed Aug 20, 2003 10:53 am     Reply with quote

:=I'm trying to do a simple test to illustrate the timer and rda interrupts.
:=Each time the timer interrupt is called it serially sends a 5-byte message. If the PC sends a 5-byte message i.e. 0xB2, 0x07, 0x02, 0x01, 0x01, the test program below is meant to echo it back. However, it seems that the serial interrupt is only called twice because it only echoes back the first 2 bytes.
:=
:=There is hardly any code in the rda interrupt.
:=
:=Why is this so? I must be missing something here. I'm using the #use rs232(baud =19200, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
:=
:=
:=int array[10];
:=short int flag_fifo = 0;
:=int a = 0;
:=
:=
:=test_tx( int x1, int x2, int x3, int x4, int x5)
:={
:= putc(x1);
:= putc(x2);
:= putc(x3);
:= putc(x4);
:= putc(x5);
:=}
:=
:=
:=#int_rda
:=serial_isr()
:={
:= array[a] = getc();
:= a++;
:= flag_fifo = 1;
:= disable_interrupts(INT_TIMER2);
:=}
:=
:=
:=
:=#int_timer2
:=timer2_isr()
:={
:= test_tx(0xB1, 0x53, 0x08, 0x07, 0x01);
:=}
Start here.
Avoid using any routine, inside, and outside an ISR. You are now doing this with 'putc', which will mean that the main code will automatically attempt to disable interrupts around the putc call. Though it _should_ test the status of the interrupt, and only disable it if it is enabled, and re-enable it, only if it was enabled, you are making the compiler have to do a lot of work. Also 'putc', will wait till the character has sent. Hence it is possible that timer2, could re-interrupt, before two characters have been sent (there are potentially three characters of RS232 output buffering), and things could get very messy here. Use an interrupt driven transmit as well, and your own 'putc', that just transfers characters to the buffer, or do the transfer from 'main', once the flag is set.

:=
:=
:=main()
:={
:= while(1)
:= {
:= enable_interrupts(INT_TIMER2);
You have not setup the divisor, or timeout values for the timer. The defaults may be OK, but don't rely on them...

:= enable_interrupts(INT_RDA);
:= enable_interrupts(GLOBAL);
:=
:= //do something here
:=
:= if(flag_fifo)
:= {
:= int b;
:= for(b = 0; b < a; b++)
:= {
:= putc( array[b] );
:= }
So, if one character only has been received at this point, only one character will be echoed back. You then go into the timer based handler, and behaviour then depends on the timer settings, and how the interrupts will interact...

:= flag_fifo = 0;
:= a = 0;
:= enable_interrupts(INT_TIMER2);
:= }
:=
:= }
:=
:=}

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144517111
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