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

interrupt for serial 232 not work

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



Joined: 06 Apr 2009
Posts: 5

View user's profile Send private message

interrupt for serial 232 not work
PostPosted: Mon Dec 21, 2009 10:13 am     Reply with quote

Hi to everyone.

I am trying to run interrupt (#int_rda2) for serial 2 for pic18F6722.
when I sending '$' to serial 2 (PC) the interrupt not work....
Here's my code:
Code:

#include "18f6722.h"

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC                            //Internal RC Osc
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES LPT1OSC                  //Timer1 configured for low-power oration
#FUSES NOMCLR                     //NO Master Clear pin enabled

#use delay (clock=32000000)

#USE RS232(UART2,baud=9600,stream=PC)   // HW serial 2 pin(4,5)

#int_rda2
void read_rf_data(void){
char ch;
ch=getc(PC);
if (ch=='$'){
            puts("Hi I'm interrupt\n\r",PC);
      }
}

void main(void)
{
setup_oscillator(OSC_32MHZ); //internal oscillator
enable_interrupts(int_rda2); // interrupt
enable_interrupts(GLOBAL);

for(;;){}

}
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

Re: interrupt for serial 232 not work
PostPosted: Mon Dec 21, 2009 10:21 am     Reply with quote

muneer wrote:
Hi to everyone.

I am trying to run interrupt (#int_rda2) for serial 2 for pic18F6722 .
when i sending '$' to serial 2 (PC) the interrupt not work....

The code is expecting a '$' from the PC, not sending a '$' to the PC.

And what are you using to generate the RS232 level needed by the PC from the CMOS/TTL level from the PIC? Something like the MAX3221 level translator I hope.
muneer



Joined: 06 Apr 2009
Posts: 5

View user's profile Send private message

PostPosted: Mon Dec 21, 2009 10:34 am     Reply with quote

dear mkuang
1- I am using MAX to convert serial232 to TTL.
2- I am trying to run interrupt (#int_rda2) for serial 2.
I am sending any character to serial 2 (PC). The interrupt still not work....
Code:

#int_rda2
void read_rf_data(void){
            puts("Hi I'm interrupt\n\r",PC);
}
void main(void)
{
setup_oscillator(OSC_32MHZ); //internal oscillator
enable_interrupts(int_rda2); // interrupt
enable_interrupts(GLOBAL);

for(;;){}

}
Ttelmah
Guest







PostPosted: Mon Dec 21, 2009 10:43 am     Reply with quote

1) Add 'errors' to your RS232 setup statement. As it stands, the code risks hanging the UART, if '$' is received.
2) Add a getc, to the second example.
Then prove that the UART is working, without using the interrupt. Simply echo received characters. If you get something back, but not what you expect, the problem is in the oscillator, rather than in the interrupt.
Post your compiler version.

Best Wishes
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

PostPosted: Mon Dec 21, 2009 10:43 am     Reply with quote

muneer wrote:
dear mkuang
I am sending any character to serial 2 (PC). The interrupt still not work....


}

I will say this again, your code is for receiving a '$' from the PC, NOT for sending a '$' to the PC.
Guest








PostPosted: Mon Dec 21, 2009 10:46 am     Reply with quote

Try 8Mhz. and this #use delay(internal=8Mhz)

Drop:
setup_oscillator(OSC_32MHZ); or change to
setup_oscillator(OSC_8MHZ|OSC_INTRC);

Can you receive anything on the pc?
muneer



Joined: 06 Apr 2009
Posts: 5

View user's profile Send private message

PostPosted: Mon Dec 21, 2009 10:59 am     Reply with quote

Dear Ttelmah
1- I am using compiler PCWH V4.093.
2- The serial 2 is working without interrupt.
Code:

#include "18f6722.h"

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC                    //Internal RC Osc
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES NOMCLR                   //NO Master Clear pin enabled

#use delay (clock=32000000)

#USE RS232(UART2,baud=9600,stream=PC)  // HW serial 2 pin(4,5)

char ch;
void main(void)
{
setup_oscillator(OSC_32MHZ); //internal oscillator

for(;;){
ch=getc(PC);
putc(ch,PC);
}

}
mkuang



Joined: 14 Dec 2007
Posts: 257

View user's profile Send private message Send e-mail

Re: interrupt for serial 232 not work
PostPosted: Mon Dec 21, 2009 12:09 pm     Reply with quote

muneer wrote:
Hi to everyone.

Code:

#include "18f6722.h"

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC                            //Internal RC Osc
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOBROWNOUT               //No brownout reset
#FUSES LPT1OSC                  //Timer1 configured for low-power oration
#FUSES NOMCLR                     //NO Master Clear pin enabled

#use delay (clock=32000000)

#USE RS232(UART2,baud=9600,stream=PC)   // HW serial 2 pin(4,5)

#int_rda2
void read_rf_data(void){
char ch;
ch=getc(PC);
if (ch=='$'){
            puts("Hi I'm interrupt\n\r",PC);   }
}

void main(void)
{
setup_oscillator(OSC_32MHZ); //internal oscillator
enable_interrupts(int_rda2); // interrupt
enable_interrupts(GLOBAL);

for(;;){}

}


Puts does not need a stream. Try just
Code:

puts("Hi I'm interrupt\n\r");
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