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

PIC16F1824 INT_RDA does not work

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



Joined: 10 Feb 2012
Posts: 7
Location: washington

View user's profile Send private message

PIC16F1824 INT_RDA does not work
PostPosted: Fri Feb 10, 2012 3:18 pm     Reply with quote

I am using a PIC16F1824 with compiler Version 4.128. I cannot get the INT_RDA routine to fire when data arrives on the RS232 line. I am using a PC to communicate through a MAX3232. I am able to communicate over the RS232 in both directions....but the INT_RDA never fires.

Here is the code that I am testing.

Code:
#include <16F1824.h>
#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES WDT_SW                   //No Watch Dog Timer, enabled in Software
#FUSES NOBROWNOUT               //No brownout reset
#FUSES PLL_SW                   //4X HW PLL disabled, 4X PLL enabled/disabled in software
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(int=16000000)

//#use rs232(baud=9600,parity=N,xmit=PIN_A0,rcv=PIN_A1,bits=8,stream=PORT1) GENERATED BY COMPILER
//#use rs232(baud=9600,parity=N,UART1,bits=8,stream=PORT1) //doesn't work
#use rs232(baud=9600,parity=N,UART1,bits=8,stream=PORT1,ERRORS) //doesn't work

#int_RDA
void  RDA_isr(void)
{
   fputc('Z',PORT1);
}



void main()
{
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_16MHZ|OSC_INTRC|OSC_PLL_OFF,0);
   
   for(;;)
   {
      output_bit(PIN_C4,1); //this flashes an LED to verify the chip is alive
      delay_ms(500);
      output_bit(PIN_C4,0);
      delay_ms(500);
   }
   
}



most of this code has been generated by the compiler through the wizard.

fputc(fgetc()) works for any of the #useRS232 statements above.

other interrupts on this chip seem to work ok....INT_EXT works for instance.

I have tried most of the advice given in this forum...stumped
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 10, 2012 3:33 pm     Reply with quote

You have to call fgetc() inside the #int_rda routine. You have to read the
char to prevent the PIC from interrupting over and over again. Add an
fgetc() statement at the start of the isr.
Beowulf



Joined: 10 Feb 2012
Posts: 7
Location: washington

View user's profile Send private message

PostPosted: Fri Feb 10, 2012 3:39 pm     Reply with quote

I have tried various version of this

Code:

#int_RDA
void  RDA_isr(void)
{
   char temp;
   temp = fgetc(PORT1);
   fputc('Z',PORT1);
}


the processor doesn't appear enter this block.....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 10, 2012 4:02 pm     Reply with quote

What pins are you using for Tx and Rx ? This PIC has default and alternate
pins for those signals.
Beowulf



Joined: 10 Feb 2012
Posts: 7
Location: washington

View user's profile Send private message

PostPosted: Fri Feb 10, 2012 5:46 pm     Reply with quote

If I give the command

Code:

#use rs232(baud=9600,UART1,ERRORS)


the compiler chooses A0 for tx and A1 for rx...so that would seem to be the default. The data sheet allows C4 for tx and C5 for rx to be selected through APFCON as well. The chip only has one UART.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 10, 2012 6:01 pm     Reply with quote

I don't think it defaults to A0 and A1 (for Tx and Rx). I made the
following program and tested it just now in hardware, and I see pulses
on pin C4. Also, in the Overview section of the 16F1824 data sheet,
where it lists the pins, it says for pins C4 and C5:
Quote:

2: Default function location.

I think you probably need to use APFCON if you want to use A0 and A1.

The program below outputs a signal on pin C4:
Code:

#include <16F1824.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PLL_SW, NOLVP
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

//========================================
void main()
{

while(1)
  {
   putc(0x55);
  }
   
}
Beowulf



Joined: 10 Feb 2012
Posts: 7
Location: washington

View user's profile Send private message

PostPosted: Fri Feb 10, 2012 6:41 pm     Reply with quote

after compiling your code ...the LST file shows

Code:

0056:  MOVLB  02
0057:  BSF    1D.2
0058:  BSF    1D.7


bank 2 offset 0x1D is the APFCON0 register
setting these bits selects A0 and A1.


Adding this
Code:

#byte APFCON0 = getenv("SFR:APFCON0")

#bit TXSTA = APFCON0.2
#bit RXSTA = APFCON0.7

 TXSTA =0;
  RXSTA =0;



compiles to a LST file that has

Code:

....................    TXSTA =0;
0065:  BCF    1D.2
....................    RXSTA =0;
0066:  BCF    1D.7



which clears the bits in APFCON0

but I still get RS232 on A0 & A1 with no INT_RDA
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 10, 2012 7:34 pm     Reply with quote

The PIC data sheet says you have to set the APFCON0 bits to 1,
in order to select the alternate pins. I did that and it works:
Code:

#include <16F1824.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PLL_SW, NOLVP
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)


#byte APFCON0 = getenv("SFR:APFCON0") 

#bit TXSEL = APFCON0.2
#bit RXSEL = APFCON0.7

#int_RDA
void  RDA_isr(void)
{
char c;

c = getc();
putc(c);
}



//========================================
void main()
{
TXSEL = 1;
RXSEL = 1;

clear_interrupt(INT_RDA);
enable_interrupts(INT_RDA);
enable_interrupts(GLOBAL);
   
while(1);
}
Beowulf



Joined: 10 Feb 2012
Posts: 7
Location: washington

View user's profile Send private message

PostPosted: Fri Feb 10, 2012 8:53 pm     Reply with quote

just updated to the 4.129 software version.

this no longer appears in the LST file in the default case(tx=C4,rx=C5)
Code:

0056:  MOVLB  02
0057:  BSF    1D.2
0058:  BSF    1D.7


I am no longer at my work bench ...so I can't load this onto the PIC to be sure...but It seems as though the 4.128 version has a bug when compiling for this processor. If I have time this weekend I will try this out to see if it works on the PIC.
Beowulf



Joined: 10 Feb 2012
Posts: 7
Location: washington

View user's profile Send private message

(Solved)
PostPosted: Mon Feb 13, 2012 9:15 am     Reply with quote

I listed my compiler version incorrectly in the problem statement. The version that has this issue is:
Code:

CCS PCM C Compiler, Version 4.124


I am convinced that this was a compiler bug. I upgraded to 4.129 and the problem has gone away. Th tx/rx pins are correctly assigned now and the interrupts occur as expected.

**always check for updates**
Ttelmah



Joined: 11 Mar 2010
Posts: 19369

View user's profile Send private message

Re: (Solved)
PostPosted: Mon Feb 13, 2012 9:23 am     Reply with quote

Beowulf wrote:
I listed my compiler version incorrectly in the problem statement. The version that has this issue is:
Code:

CCS PCM C Compiler, Version 4.124


I am convinced that this was a compiler bug. I upgraded to 4.129 and the problem has gone away. Th tx/rx pins are correctly assigned now and the interrupts occur as expected.

**always check for updates**

No!.
Not if the compiler works for what you want.....

Key here is that the 1824 is a pretty new chip, and it always seems to take CCS perhaps a dozen versions to get these working.
However CCS's 'updates', generally are not reliable till they have been tested for a while, so rule has to be 'check for updates _if_ you have something not working right'. Otherwise you may well be asking for problems.....

Best Wishes
Beowulf



Joined: 10 Feb 2012
Posts: 7
Location: washington

View user's profile Send private message

PostPosted: Mon Feb 13, 2012 11:27 am     Reply with quote

you are correct....updates are only useful when there is an actual problem to solve...
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