Hi Mr Taylor:
I agree with you about the difficult task of introducing interrupts on a big program, but I think the problem isn't there.
Following your recommendations I have extract the core lines of my program, just to test the interrupts, so my lite-version is that:
DEFINE LOADER_USED 1
iNCLUDE "cfgvtol-MIXER_18f2685_40mhz.bas"
INCLUDE "DT_INTS-18.bas"
INCLUDE "ReEnterPBP-18.bas"
DEC_MICRO:
DEFINE I2C_HOLD 1
ADCON1 = %00001111
PORTA = 0
TRISA = %111101
PORTB = 0
TRISB = %00000001
PORTC = 0
TRISC = %10000100
PORTE = 0
I2C_RDR_SCL VAR PORTC.3 ' I2C Reader clock
I2C_RDR_SDA VAR PORTC.4 ' I2C Reader data
RDR_I2C_DIR_SLAVE con $24
RDR_I2C_BUFFER_SIZE con 32
RDR_I2C_BUFFER var byte[RDR_I2C_BUFFER_SIZE]
RDR_FLAG VAR BIT
RDR_AUX VAR Byte
RDR_VALUE VAR WORD
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler INT0_INT, _INT_READER, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE INT0_INT ; enable external (INT) interrupts
RDR_FLAG=0
LOOP:
if rdr_flag then
for RDR_AUX=0 to RDR_I2C_BUFFER_SIZE-1 step 2
RDR_VALUE.lowbyte = RDR_I2C_BUFFER[RDR_AUX]
RDR_VALUE.highbyte = RDR_I2C_BUFFER[RDR_AUX+1]
hserout[dec RDR_VALUE, tab]
next RDR_AUX
hserout [cr, lf]
rdr_flag=0
endif
GOTO LOOP
INT_READER:
I2CREAD i2c_rdr_SDA, i2c_rdr_SCL, rdr_I2C_DIR_SLAVE , [str RDR_I2C_BUFFER\RDR_I2C_BUFFER_SIZE], INT_READER_ERR
RDR_FLAG = 1
INT_READER_ERR:
@ INT_RETURN
This program only waits for an interrupt in the RB0 port and then performs an I2CREAD. If the I2CREAD has success a flag is activated.
In the main loop, we just look for the flag to change, and then the data received is sent through the serial port.
As you said, defining a new variable on your code, makes no changes (my mistake), but restoring FLAG var still is the clue. If FLAG var is restored, the i2cread is only executed properly the first time, and if I delete that line (I know that isn't right, but is used to investigate) I2CREAD is executed every 20ms (the right frame)
Following that trail, I have introduced some dummy vars to obtain FLAGS var status in different moments of the interrupt:
FLAGS=00100000 When being saved for the first time.
FLAGS=01100000 After I2CREAD has being executed.
FLAGS_SaveH=00000100 Line before restoring FLAG, is a little strange because FLAGS was 00100000 when was saved (When was FLAGS_SaveH modified?????)
FLAGS=00000100 After restoring
If that value is restored, I2CREAD don't work any more.
As I have said, if we don't restore the FLAGS var I2CREAD keeps working, leaving FLAGS=01100000
I hope you can help me with this reduced program that shows something strange happening.
Maybe is a nonsense, but value of FLAGS_SaveH when saved (00100000) and when restored (00000100) is the same value with inverted alignment, ?????
Thanks in advance,
dcorraliza
Bookmarks