Hello, I am rather new to the embedded programming land and I was using an interrupt to handle my I2C interface.
I am using: uVision 5 - ide and debugger R8051CX2 - chip C51 - compiler windows 7 professional - OS
I initialize everything with:
void init_i2c(void) { I2CADR = SLAVE_ADDRESS & 0xFF; // slave address (1011010_0) last bit is "general call" bit I2CCON |= 0x44; // enable I2C TMOD |= 0x01; // timer 0 mode 1 IEN0 = 0x82; // enable all interupts and timer 0 overflow IEN1 |= 0x01; // enable external interrupt 7 (for I2C) //S1CON = 0x10; // enable serial comm. (port 1) - no acknowledgements will be generated //IEN2 = 0x01; // enable serial port 1 interrupts //ES1 = 1; // enable serial port 1 interrupts //May or may not need pin code below //P1 ^= 0x40; //P1 ^= 0x80; }
The beginning of my ISR is: (My device is running as a slave receiver)
void i2c_isr(void) interrupt 7 // EX7 is the SI (i2c) interrupt port { switch(I2CSTA) { // RECEIVED ADDRESS AND RETURNED ACK (ASSUMED SLAVE) case 0x60: start_timer(); // start timer 0 to start measuring the timeout period break;
And the problem I see after running the debugger and using the I2C peripheral tool (when the SI bit triggers the interrupt) is:
C:0x003B 020800 LJMP i2c_isr(C:0800) C:0x003E 00 NOP C:0x003F 00 NOP C:0x0040 00 NOP C:0x0041 00 NOP C:0x0042 00 NOP C:0x0043 00 NOP
In the data sheet, you will notice the interrupt vector for I2C is ORed with the Interrupt 7 module which is located at 0x0043, so it seems the simulator is working, but I am not quite sure why the handle function is placed at 0x003B?
If you need it my main looks like:
void main(void) { init_i2c(); while(!TF0 || i2c_status != I2C_ERROR); // run I2C and program dump until timeout occurs // Timeout could be from failed comm. or end of transmission EAL = 0; // disable all interupts if(i2c_status == I2C_ERROR) { write_byte_to_progmem(NOP); } // set pointer to initial spot for OTP // blahblah = PROGRAM_MEM_START; }
NOTE: I am using the provided register header file "REG51CX2.H" from the uVision website for the respective chip. Also, my full code does compile, no errors.