|
|
View previous topic :: View next topic |
Author |
Message |
Aamir
Joined: 11 Apr 2010 Posts: 13
|
Serial interrupt problem |
Posted: Sat Nov 12, 2011 10:42 am |
|
|
I am using a wireless transceiver, at the receiver end my code does not work. Although i did the same logic in PIC16F877, but now while doing so in PIc16F873A, it does work. Probably i am doing some mistake for this type, but by datasheet and notes, these both PICs seems to be similar. Here is the code at receiver side.
Code: | #include <16F873A.H>
#fuses XT, NOWDT, BROWNOUT,
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7,stream=ami)
int q=0,a=0,b=0;
char Rcv;
ser(){
if (Rcv=='Q'){
if(q==0){
output_high(pin_b6);
a=1;}
else {
output_low(pin_b6);
b=1;
}
}
if(a==1){
q=1;a=0;}
if(b==1){
q=0;b=0;}
}
#INT_RDA
void SerialInt()
{
Rcv=getchar();
output_low(pin_a0);delay_ms(200);output_high(pin_a0);
delay_ms(1000);
ser();
}
void main (){
enable_interrupts(global);
enable_interrupts(int_rda);
printf("hello");
output_low(pin_b6);
while(1){
output_high(pin_a0);
}
}
|
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Sat Nov 12, 2011 11:01 am |
|
|
1) add 'errors' to the use rs232(.....) options.
2) Get RID of the delays in the serial ISR !!!!!!!!!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Sat Nov 12, 2011 11:19 am |
|
|
Seriously, get rid of the delays in the interrupt.
Look at the EX_SISR code, and do your processing in a loop in the main.
As it stands, this code _will_ hang the chip's UART, if there is a character received in the 1.2seconds of delay time.
Possibly even a little noise on the receiver, and a fractional difference in what the chips accept as a 'high', however you are just being 'lucky' with the 873....
Add the keyword ERRORS to the RS232 declaration (will stop the code from actually getting hung), but fix the problem as well.
Generally, any ISR, should _just_ handle the hardware event that has been signaled (in this case, get one character that has been received), and get out again ASAP. Doing anything much else, is potentially asking for trouble.....
Best Wishes |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Sat Nov 12, 2011 11:20 am |
|
|
I see Temtronic has made the same comment while I was posting.
Best Wishes |
|
|
Aamir
Joined: 11 Apr 2010 Posts: 13
|
|
Posted: Fri Nov 18, 2011 3:36 pm |
|
|
Thanks guys, will certainly try it.
As for the delay, actually I put it just because I don't need 2 3 entries at a moment....so I thought this might work.
As for errors...can anyone tell me how it is done? mind my question, I am little beginner to C. |
|
|
Aamir
Joined: 11 Apr 2010 Posts: 13
|
|
Posted: Fri Nov 18, 2011 3:37 pm |
|
|
By the way, has anyone ever face any problem with 20MHz crystal in pic16f873? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Fri Nov 18, 2011 3:55 pm |
|
|
Not really.
Generally, provided HS is selected (for the 20MHz you ask about), and the crystal is a parallel resonant, fundamental mode type, the PIC oscillator is pretty reliable.
Crystals with low drive levels, may require a series resistor. This is particularly the case on some of the 'first generation' 18 chips with PLL modules, which tended to lock onto an overtone, if the crystal is overdriven. However on older chips like the 16F873, this was rare.
Generally good design round the oscillator pins though is always critical. Short runs, don't have the ground plane round the oscillator pins (have a small ring round this area, and exclude the ground plane).
Microchip do several application notes about board layout, and crystal selection, follow these, and the oscillators work.
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
|