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

16F876A serial read input

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



Joined: 16 Nov 2012
Posts: 1

View user's profile Send private message

16F876A serial read input
PostPosted: Fri Nov 16, 2012 12:58 pm     Reply with quote

Below is a snippet of my rx serial code. I am sending a message to an instrument ("240_00\r\n" and getting a reply back of 240 Y which is correct response. I have the PIC txing fine but my problem is receiving this message. With below snippet I can see the first returned char of 2 but that's it. I am no expert and hope someone can point me in the right direction. Thanks.
Code:

#use rs232(baud=9600, parity=N, xmit=62, rcv=63, bits=8, ERRORS)

#int_rda
void serial_rx_isr()
{   
   rx_count++;

   if(RCIF == 1 && RCIE == 1)
   {       
      Rx_Buffer[Rx_Wr_Index] = RCREG;
      Rx_Wr_Index++; // increments to next element
      //CREN = 0;
      //rx_count++;

      //TXIE = 1;  // enable transmission bit
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 16, 2012 1:03 pm     Reply with quote

Quote:

#use rs232(baud=9600, parity=N, xmit=62, rcv=63, bits=8, ERRORS)

Don't do this. It makes the code unreadable and not portable between
PICs. Don't use magic numbers. Use the pin constants given in the .h
file for your PIC.


Quote:

if(RCIF == 1 && RCIE == 1)
{
Rx_Buffer[Rx_Wr_Index] = RCREG;

Don't do this. If you got the #int_rda interrupt, you inherently have a
character ready. Just get it with getc().



Quote:
I can see the first returned char of 2 but that's it.

You didn't show enough of your receive code to make a real assessment
of the problem. Ideally you should post a short but complete program
for receiving, that shows the problem. Also post your compiler version.
By complete, I mean it has the #include, #fuses, #use delay, variables,
#define statements, main(), and is compilable.

The following issue may not apply in your case, but at least read this
thread regarding the hidden sleep instruction:
http://www.ccsinfo.com/forum/viewtopic.php?t=49318
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Fri Nov 16, 2012 3:08 pm     Reply with quote

and, what limits the size of rxcount?. As shown it has the potential to overwrite memory...

Best Wishes
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