Geps
 
 
  Joined: 05 Jul 2010 Posts: 129
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| SSP Interrupt Not Always Getting Serviced | 
			 
			
				 Posted: Sat Jul 23, 2011 7:33 am     | 
				     | 
			 
			
				
  | 
			 
			
				Hi,
 
 
Compiler: 4.087
 
 
I'm trying to code a master/slave I2C based system on two PIC18F4520.
 
 
Using this topic as an example:
 
 
http://www.ccsinfo.com/forum/viewtopic.php?t=44686
 
 
I have the following code:
 
 
 	  | Code: | 	 		  #include <18f4520.h>
 
#fuses INTRC_IO, PUT, NOMCLR, NOWDT, NOPROTECT, NOLVP
 
#use delay(internal=8Mhz, clock=32Mhz)
 
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS) 
 
 
 
#use i2c(Master, sda=PIN_C4, scl=PIN_C3)
 
    
 
#define SLAVE1_WRT_ADDR   0x12
 
#define SLAVE1_READ_ADDR  0x13
 
 
 
//==================================== 
 
void main() 
 
{ 
 
int8 data1, data2;
 
 
   delay_ms(1000);
 
 
   printf("Starting!");
 
 
while(TRUE) 
 
  { 
 
   i2c_start();
 
   i2c_write(SLAVE1_WRT_ADDR);
 
   delay_us(100);
 
   i2c_write(3);
 
   delay_us(100);
 
   i2c_write(3);
 
   delay_us(100);
 
   i2c_write(3);
 
   delay_us(100);
 
   i2c_write(3);
 
   delay_us(100);
 
   i2c_write(3);
 
   delay_us(100);
 
   i2c_stop();
 
 
 
   delay_ms(50);
 
 
  } 
 
 
}
 
 | 	  
 
 
Slave code:
 
 
 	  | Code: | 	 		  #include <18f4520.h>
 
#fuses INTRC_IO, NOPUT, NOMCLR, NOWDT, NOLVP
 
#use delay(internal=8Mhz, clock=32Mhz)
 
 
 
#use i2c(SLAVE, SDA=PIN_C4, SCL=PIN_C3, address=0x12)
 
 
#define REDLED PIN_C0
 
#define SCL PIN_C3
 
 
 
int8 incoming =0;
 
int1 ProcessDataFlag = 0;
 
 
 
 
 
 
 
#INT_SSP
 
void ssp_interrupt() {
 
int8 state= 0;
 
   output_high(REDLED);
 
   state = i2c_isr_state();
 
   if(state < 0x80)     // Master is sending data 
 
      { 
 
         incoming = i2c_read();
 
      } 
 
 
if(state >= 0x80)   // Master is requesting data from slave 
 
  { 
 
  
 
  }
 
output_low(REDLED);
 
} 
 
 
 
//====================================== 
 
void main () 
 
{
 
delay_ms(500);
 
output_high(PIN_A7);
 
enable_interrupts(INT_SSP); 
 
enable_interrupts(GLOBAL); 
 
while(TRUE) 
 
{ }
 
}
 
 
 | 	  
 
 
 
The problem I'm getting is that the interrupt isn't getting serviced on receipt of every byte - only the first two bytes.
 
 
Where am I going wrong?
 
 
Cheers, | 
			 
		  |