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

CCS Bootloader and Interrupts

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



Joined: 15 Jun 2006
Posts: 66

View user's profile Send private message

CCS Bootloader and Interrupts
PostPosted: Wed Aug 23, 2006 12:51 pm     Reply with quote

Ok, I grabbed my 18f452. Loaded the bootloader onto it. Loaded various programs successfully. I feel great. Then I pressed an external button firing off an interrupt. Program just stops...

Now, I know the interrupts are being stored in the right place because I created a simple blinking program that changes by ext interrupt being fired.

Only reason I can think of is that the interrupt space is too small. so...
My question is how do I make the interrupt space larger?

change a goto? add more nops?

here is sample code that works with ext2 but stops with rda interrupt
Code:
boolean flag2 = false;

#int_rda
void serial_isr() {
   if(flag2)
      flag2=false;
   else
      flag2=true;
}

#int_ext2
void button_isr()
{
   if(flag2)
      flag2=false;
   else
      flag2=true;
}


void main_prog(void)
{
   output_float(PIN_B2);
   ext_int_edge(H_TO_L);
   
   enable_interrupts(INT_EXT2);
   enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   
   output_bit(PIN_D0,1);
   output_bit(PIN_D1,1);
   
   while(1)
   {
      if (flag2==true)
      {
         output_bit(PIN_D0,0);
         delay_ms(500);
         output_bit(PIN_D0,1);
         delay_ms(500);
      }
      else
      {
         output_bit(PIN_D1,0);
         delay_ms(500);
         output_bit(PIN_D1,1);
         delay_ms(500);
      }
      
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 23, 2006 3:44 pm     Reply with quote

Quote:

here is sample code that works with ext2 but stops with rda interrupt

You must clear the RCIF interrupt flag by reading the character inside
the #int_rda routine. You can read the character with the getc() or
fgetc() function.
grasspuddle



Joined: 15 Jun 2006
Posts: 66

View user's profile Send private message

PostPosted: Thu Aug 24, 2006 6:12 am     Reply with quote

Thanks, unfortunately that solves the sample program but not the real program I have.

My main rda interrupt is basically ccs' ex_stisr where it stores incomming data into a buffer.

The code worked by itself, but freezes when using the CCS bootloader.
Freezes as in it doesn't respond to anymore commands.
grasspuddle



Joined: 15 Jun 2006
Posts: 66

View user's profile Send private message

PostPosted: Thu Aug 24, 2006 8:00 am     Reply with quote

Interrupts are working. Thats not the problem. The problem is the read/write to eeprom (I2C) I've been invoking because of the interrupt(a button press). Thats where it freezes.
Ttelmah
Guest







PostPosted: Thu Aug 24, 2006 8:05 am     Reply with quote

Have you got 'errors' set in the RS232 statement?.
An EEPROM 'write', can easily take 4mSec to complete. If your code is 'waiting' on the EEPROM, and interrupts are disabled during this, there is a very good chance the UART input buffer is overflowing. This locks the UART, till the error is cleared.

Best Wishes
grasspuddle



Joined: 15 Jun 2006
Posts: 66

View user's profile Send private message

PostPosted: Thu Aug 24, 2006 8:47 am     Reply with quote

I think i'm confusing everyone with too little info.

thanks to pcm prog i got a simple prog working which blinked LEDs

it used 2 interrupts:

EXT2 (button)
RDA (uart recieved data)

When one of them fires it changes the LEDs, so I must be wrong in saying that the interrupts arent working.

Next I slowly added data from the program I wanted until I got the same error.

It happened when I read/wrote to an external eeprom (I2C).
So I made it that when I push the button, it tries to write to eeprom.
This is when it freezes/waits/stops.

The bootloader is exactly the same as the example, except i changed the pin it checks to 'PIN_B4'. No reason it would act weird there so I must have something wrong with the code I update with over usart.

my #use code:
Code:

#use RS232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,ERRORS,STREAM=LCD_UART)
#use RS232(baud=2400,parity=N,xmit=PIN_B6,rcv=PIN_B7,bits=8,STREAM=SW_UART)
#use i2c(Master, sda=PIN_C4,scl=PIN_C3)


my updated sample prog code:

Code:
boolean flag1=false;
boolean flag2=false;
short int status;
//int eprom;

#int_ext2
void button_isr()
{
   flag1=true;
}

#int_rda
void serial_isr() {
   flag2=true;
   getc();
}
void init(void)
{
   output_float(PIN_B2);
   ext_int_edge(H_TO_L);
   set_timer1(0);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_EXT2);
   enable_interrupts(GLOBAL);
   
      output_float(PIN_C3);
   output_float(PIN_C4);
}

void main_prog(void)
{
   
   
   output_bit(PIN_D0,0);
   output_bit(PIN_D1,1);
   
   init();
   
   while(1)
   {
      if(flag1)
      {
         fprintf(SW_UART,"BUTTON");
               
               i2c_start();
               i2c_write(0xa0);
               i2c_write(0>>8);
               i2c_write(0);
               i2c_write(4);
               i2c_stop();
               i2c_start();
               status=i2c_write(0xa0);
               while(status==1){
                  i2c_start();
                     status=i2c_write(0xa0);
               }
   
         flag1=false;
      }
      if(flag2)
      {
         fprintf(SW_UART,"RCV");
         flag2=false;
      }
      output_toggle(PIN_D0);
   }
}


also: i'm using compiler ver3.223

hope i'm less confusing this time
grasspuddle



Joined: 15 Jun 2006
Posts: 66

View user's profile Send private message

PostPosted: Thu Aug 24, 2006 11:03 am     Reply with quote

Last post. Its fixed and I just want to let everyone know what was wrong.

The chip was bad... Laughing

more specifically the pin C3 which sent the clock sync to eeprom sent nothing at all.

Although I did realize something neat. If I put LEDs inbetween the clock and data wires to my eeprom I could just look to see if data was being sent (although that made it not able to communicate data) and the one wire was dead so switched chips and it works like a charm. What a fun way to spend the morning... I love programming.
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