CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

SSP Interrupt Not Always Getting Serviced

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

SSP Interrupt Not Always Getting Serviced
PostPosted: Sat Jul 23, 2011 7:33 am     Reply with quote

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,
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jul 24, 2011 5:48 pm     Reply with quote

The following text and example code are in the CCS manual in the section
on the i2c_isr_state() function. Try adding the code shown in bold to your isr.
Quote:

i2c_isr_state()

If 0x00 or 0x80 is returned, an i2C_read( ) needs to be performed to read the I2C address that was sent (it will match the address configured by #USE I2C so this value can be ignored).


Example:

#INT_SSP
void i2c_isr() {

state = i2c_isr_state();

if((state== 0 ) || (state== 0x80))
i2c_read();

.
.
.
}


I haven't tested this.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group