|
|
View previous topic :: View next topic |
Author |
Message |
mdstinnett
Joined: 16 Nov 2012 Posts: 1
|
16F876A serial read input |
Posted: Fri Nov 16, 2012 12:58 pm |
|
|
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
|
|
Posted: Fri Nov 16, 2012 1:03 pm |
|
|
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: 19537
|
|
Posted: Fri Nov 16, 2012 3:08 pm |
|
|
and, what limits the size of rxcount?. As shown it has the potential to overwrite memory...
Best Wishes |
|
|
|
|
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
|