View previous topic :: View next topic |
Author |
Message |
muneer
Joined: 06 Apr 2009 Posts: 5
|
interrupt for serial 232 not work |
Posted: Mon Dec 21, 2009 10:13 am |
|
|
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
|
Re: interrupt for serial 232 not work |
Posted: Mon Dec 21, 2009 10:21 am |
|
|
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
|
|
Posted: Mon Dec 21, 2009 10:34 am |
|
|
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
|
|
Posted: Mon Dec 21, 2009 10:43 am |
|
|
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
|
|
Posted: Mon Dec 21, 2009 10:43 am |
|
|
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
|
|
Posted: Mon Dec 21, 2009 10:46 am |
|
|
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
|
|
Posted: Mon Dec 21, 2009 10:59 am |
|
|
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
|
Re: interrupt for serial 232 not work |
Posted: Mon Dec 21, 2009 12:09 pm |
|
|
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");
|
|
|
|
|