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

I2C & INTERRUPT

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







I2C & INTERRUPT
PostPosted: Mon Jul 16, 2007 4:55 pm     Reply with quote

Hi at all.
I'm using an i2c rtc and the program stop after the execution of initialization routine because the translation of instruction i2c_start() is the seguent:
.................... i2c_start();
064E: BSF 29.4
064F: MOVF 29,W
0650: BSF 03.5
0651: MOVWF 07
0652: MOVLW 04
0653: MOVWF 77
0654: DECFSZ 77,F
0655: GOTO 654
0656: BCF 03.5
0657: BSF 29.3
0658: MOVF 29,W
0659: BSF 03.5
065A: MOVWF 07
065B: MOVLW 03
065C: MOVWF 77
065D: DECFSZ 77,F
065E: GOTO 65D
065F: BCF 03.5
0660: BCF 07.4
0661: BCF 29.4
0662: MOVF 29,W
0663: BSF 03.5
0664: MOVWF 07
0665: MOVLW 04
0666: MOVWF 77
0667: DECFSZ 77,F
0668: GOTO 667
0669: BCF 03.5
066A: BCF 07.3
066B: BCF 29.3
066C: MOVF 29,W
066D: BSF 03.5
066E: MOVWF 07
066F: BCF 03.5
0670: CLRF 28
0671: BTFSC 0B.7
0672: BSF 28.7
0673: BCF 0B.7

In the last line, bit 7 in register 0B (INTCON) is cleared, so global interrupt id disabled( and never enabled after in the code).
It is correct this kind of translation?
I'm using pch 4.032
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 16, 2007 8:17 pm     Reply with quote

Post a really short little test program that shows the problem. Limit the
code to 10 lines. Post all #include, #fuses, and #use statements.
The program should be compilable without errors. (i.e., post all variable
declarations as well).
hexfet13
Guest







PostPosted: Tue Jul 17, 2007 3:43 am     Reply with quote

I've compiled my project now, and the compiler output is the seguent:

>>> Warning 216 "C:\Programmi\PICC\Projects\18F452-RS232.c" Line 174(0,1): Interrupts disabled during call to prevent re-entrancy: (@I2C_WRITE_1)
>>> Warning 216 "C:\Programmi\PICC\Projects\18F452-RS232.c" Line 174(0,1): Interrupts disabled during call to prevent re-entrancy: (@I2C_READ_1)
>>> Warning 216 "C:\Programmi\PICC\Projects\18F452-RS232.c" Line 174(0,1): Interrupts disabled during call to prevent re-entrancy: (glcd_WriteCmd2)
>>> Warning 216 "C:\Programmi\PICC\Projects\18F452-RS232.c" Line 174(0,1): Interrupts disabled during call to prevent re-entrancy: (glcd_WriteByte)

Interrupt occur every 10 ms(programmed on tmr0).
Actually i call adc_read()( that read adc value) every 30ms and refresh_clk() every 1s, both from interrupt routine.Could be this the cause of disabled Interrupts?
How i can modify my code to read adc every 30ms and refresh time on lcd every 1s (should i call both out of interrupt routine)?
a piece of code is the seguent

#include <16F877A.h>
#device ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP

#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#define CONTRAST 50


#define DS1337_SDA PIN_C4
#define DS1337_SCL PIN_C3


#use i2c(master, sda=DS1337_SDA, scl=DS1337_SCL)

#include <default_param.h>
#include <inizialize.h>
#include <interface.h>


int con=CONTRAST; //lcd contrast
int i_clk=0;

//**** test
char mis_string[4];
//****

#int_rtcc //
void timer_zero() { // interrupt every 10ms
set_tmr0(); // set correct tmro value

key=get_key(); // reading keys
get_adc(); /* read adc value (the value is stored in a variable measure
defined as int16 in inizialize.h */

if(i_clk++==100){ // every 1000ms
refresh_clk(); // this procedure read time from RTC and update it on lcd
i_clk=0;
}
if (!(i_clk%33)){
glcd_gotoxy(1,0,0x00);
glcd_putc("Measure:");
sprintf(mis_string,"%4lu",measure);
glcd_putstr(mis_string); // display a strung on lcd
}

}
void main()
{
:loop
goto loop;
}
rnielsen



Joined: 23 Sep 2003
Posts: 852
Location: Utah

View user's profile Send private message

PostPosted: Tue Jul 17, 2007 8:33 am     Reply with quote

Quote:
Actually i call adc_read()( that read adc value) every 30ms and refresh_clk() every 1s, both from interrupt routine.Could be this the cause of disabled Interrupts?
How i can modify my code to read adc every 30ms and refresh time on lcd every 1s (should i call both out of interrupt routine)?
a piece of code is the seguent


It's not a good idea to call a function from inside an ISR(Interrupt). ISR's should be short and simple. Have one of the timers set a flag every 30ms and another flag at 1s. Then, have each flag serviced from within the main() body. I believe calling these routines, from within the ISR, is causing your problem.

Ronald
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