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

Serial ISR problem

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



Joined: 29 Sep 2005
Posts: 7

View user's profile Send private message MSN Messenger

Serial ISR problem
PostPosted: Fri Oct 14, 2005 5:12 am     Reply with quote

Hi,

I've a problem with an interrupt routine for serial communication. When enabling interrupts on INT_RDA, a NUL character is read (ASCII code 0) whithout sending anything to the serial port? I don't understand why?

I'm using PICDEM2 board with CCS compiler latest version (2.236).
Code:

#include <16F877A.h>
#device *=16
#use delay(clock=4000000)
#include "lcd.c"

#fuses HS,NOWDT,NOPUT,NOPROTECT,NOBROWNOUT,NOLVP
#use rs232(baud=4800, xmit=PIN_C6,rcv=PIN_C7,ERRORS)

char c;
BOOLEAN char_ready_flag = FALSE;

#INT_RDA
void serial_isr() {
  c = getc();
  char_ready_flag = TRUE;
}

void main(){
 lcd_init();
 
 enable_interrupts(INT_RDA);
 enable_interrupts(GLOBAL);
 
 while(1){
   if(char_ready_flag){
     // Display ASCII code of read character
     printf(lcd_putc,"%d",c);
     char_ready_flag = FALSE;
   }
 }
}


This code outputs a '0' on LCD without receiving anything, just by enabling interrupts...
Ttelmah
Guest







PostPosted: Fri Oct 14, 2005 5:28 am     Reply with quote

Try clearing the interrupt before enabling it.
Remember that a 'null' is what the chip will see if the logic input is low (the low will be seen as a 'start' bit, followed by all zeros for the data). It is common to find that chips like the MAX232, take a few mSec to fully power up, and garbage can easily be received by the processor in this time. So depending on your external connections, the UART is probably seeing this.
You may have to wait for the input to go high, before clearing the interrupt, and enabling the receive routine.

Best Wishes
sprotch



Joined: 29 Sep 2005
Posts: 7

View user's profile Send private message MSN Messenger

PostPosted: Fri Oct 14, 2005 5:53 am     Reply with quote

Thanks Ttelmah!

I see what you think about and try to modify my code, putting an (exagerated) delay at start and then clearing the interrupt... the result is the same...
Code:

void main(){
  lcd_init();
  delay_ms(1000);
  clear_interrupt(INT_RDA);
  enable_interrupts(INT_RDA);
  enable_interrupts(GLOBAL);
Ttelmah
Guest







PostPosted: Fri Oct 14, 2005 5:57 am     Reply with quote

Have you actually looked at the pin with a scope or logic analyser to see what the voltage level is?. What you show now, most certainly should not show this behaviour, unless the signal really is going low for some reason.

Best Wishes
sprotch



Joined: 29 Sep 2005
Posts: 7

View user's profile Send private message MSN Messenger

PostPosted: Fri Oct 14, 2005 6:31 am     Reply with quote

The problem was that my PIC is bound to a GSM modem which is powered off at start time. It's switched on later in the code so the receive pin was seen as floating which causes my troubles...

Thanks for the help Ttelmah
Ttelmah
Guest







PostPosted: Fri Oct 14, 2005 6:38 am     Reply with quote

As a 'fix', if you haven't already worked out a route round it, consider having a flag called something like 'not_started', then in the main program loop, if this flag is set, poll the input pin. If you see a 'high', clear the flag, and enable the interrupts. This way your PIC code (assuming it has something it can 'do' without the module available), can start working before the unit is seen. :-)

Best Wishes
sprotch



Joined: 29 Sep 2005
Posts: 7

View user's profile Send private message MSN Messenger

PostPosted: Fri Oct 14, 2005 6:48 am     Reply with quote

Thanks for the suggestion Ttelmah but it's the PIC who will power on the modem in my code and as I must catch the AT messages the modem will return me, I'm forced to have the interrupt enabled at once... I'll find a trick to avoid considering this NULL message at start time but was wondering how was that possible (receiving something without having traffic)... Shocked
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