View previous topic :: View next topic |
Author |
Message |
grasspuddle
Joined: 15 Jun 2006 Posts: 66
|
CCS Bootloader and Interrupts |
Posted: Wed Aug 23, 2006 12:51 pm |
|
|
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
|
|
Posted: Wed Aug 23, 2006 3:44 pm |
|
|
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
|
|
Posted: Thu Aug 24, 2006 6:12 am |
|
|
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
|
|
Posted: Thu Aug 24, 2006 8:00 am |
|
|
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
|
|
Posted: Thu Aug 24, 2006 8:05 am |
|
|
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
|
|
Posted: Thu Aug 24, 2006 8:47 am |
|
|
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
|
|
Posted: Thu Aug 24, 2006 11:03 am |
|
|
Last post. Its fixed and I just want to let everyone know what was wrong.
The chip was bad...
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. |
|
|
|