pebbert9
Joined: 31 Dec 2010 Posts: 39
|
18F23K20 I2C slave not working |
Posted: Sun Sep 11, 2011 12:33 am |
|
|
Hello,
I was prototyping with a PIC24H chip and everything was working fine, but now that I've moved over to production hardware, I can't get the I2C slave to work.
I have 4.7K pullups to 3.3V and I can see the I2C signals at C3 and C4, but the interrupt never triggers.
Does anyone see any issues with the following code?
EDIT: I am using 4.124
Code: | #include <18F23K20.h>
#device ICD=TRUE
#fuses INTRC_IO,NOWDT,NOPROTECT,PUT,DEBUG
#use delay(internal=16Mhz)
#use rs232(debugger)
#use I2C(slave,sda=PIN_C4,scl=PIN_C3,address=0xA0)
#define BUFFER_SIZE 16
byte cmd_buffer[BUFFER_SIZE];
byte data_buffer[BUFFER_SIZE];
unsigned int8 next_in = 0;
unsigned int8 next_out = 0;
#INT_SSP
void mssp_interrupt (void)
{
byte incoming, state;
state = i2c_isr_state();
if(state < 0x80) // Master is sending data
{
incoming = i2c_read();
if(state == 1)
cmd_buffer[next_in] = incoming; // Command
if(state == 2)
{
data_buffer[next_in] = incoming; // Data
if (++next_in==(BUFFER_SIZE)) next_in=0;
}
}
}
void main()
{
byte data;
setup_oscillator (OSC_16MHZ);
enable_interrupts(INT_SSP);
printf("Running....\r\n");
While (1) {
if ( next_in != next_out )
{
data = data_buffer[next_out++];
if (next_out==BUFFER_SIZE) next_out=0;
printf("%X", data);
}
}
} |
|
|