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

18F23K20 I2C slave not working

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



Joined: 31 Dec 2010
Posts: 39

View user's profile Send private message

18F23K20 I2C slave not working
PostPosted: Sun Sep 11, 2011 12:33 am     Reply with quote

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);
      }
   }
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19506

View user's profile Send private message

PostPosted: Sun Sep 11, 2011 2:45 am     Reply with quote

Global interrupt not enabled....

Best Wishes
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