Fred.Amoson
New Member
Hello,
I am trying to use my PIC16F88 as a slave i2c device. I am using BoostC with the SourceBoost compiler, but I'm not using any proprietary functions, so you should be able to understand it.
When The i2c slave (the PIC) is addressed , it should interrupt. BoostC uses the interrupt function for this. When the interrupt happens my testing LED should change from on to off. When I connect the PIC to the master I2C, the led never turns off. I'm sure the master is working correctly and the address is correct.
I have tested the interrupt/LED by setting up an external interrupt. Using that the LED does what it should when the external interrupt pin is brought high, so the interrupt function works properly.
Any ideas?
My code is as follows:
I am trying to use my PIC16F88 as a slave i2c device. I am using BoostC with the SourceBoost compiler, but I'm not using any proprietary functions, so you should be able to understand it.
When The i2c slave (the PIC) is addressed , it should interrupt. BoostC uses the interrupt function for this. When the interrupt happens my testing LED should change from on to off. When I connect the PIC to the master I2C, the led never turns off. I'm sure the master is working correctly and the address is correct.
I have tested the interrupt/LED by setting up an external interrupt. Using that the LED does what it should when the external interrupt pin is brought high, so the interrupt function works properly.
Any ideas?
My code is as follows:
Code:
#include <system.h>
#pragma CLOCK_FREQ 8000000
#pragma DATA 0x2007, 0b0001111100010000
volatile bit led1 @ PORTB.3;
void init_i2c_slave();
void interrupt();
void main()
{
//*********************//
// configure I/O ports //
//*********************//
portb = 00000000b;
trisb = 11110111b; //0 = Output, 1 = Input
porta = 00000000b;
trisa = 11111111b; //0 = Output, 1 = Input
osccon = 01110000b; //internal oscillator @ 8MHz
cmcon = 00000111b; //comparators off
ansel = 00000001b; //AN0 on (RA0)
init_i2c_slave();
led1 = 1;
while(1);
}
void interrupt()
{
led1 = 0;
}
void init_i2c_slave()
{
//SSPSTAT
sspstat.7 = 0; // this bit must be maintained clear
sspstat.6 = 0;// this bit must be maintained clear
//SCL and SDA as input
trisb.1 = 1; //SDA
trisb.4 = 1; //SCL
//SSPCON
sspcon = 0x36;
sspadd=0x86;
//SSP IE
pie1.3 = 1;
pir1.3 = 0;
//Interrupt Control
intcon.7=1; //enable global interrupt
intcon.6=1; //enable global interrupt
}