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 support@ccsinfo.com

I2C Problem in PIC24

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



Joined: 14 Jan 2009
Posts: 1

View user's profile Send private message

I2C Problem in PIC24
PostPosted: Mon Feb 09, 2009 3:06 am     Reply with quote

I have problem in I2C communication using PIC24FJ64GA002 as my slave.

I used LED to verify if my code is OK. To validate my code, I add "output_high(PIN_B7);" And I observed that the LED will not be high after the line "if (state >= 0x80)".

1. Why is it my code will not output high after the "if (state >= 0x80)"?
2. Is my i2c_isr_state correct?
Slave Code:
Code:
#include <24FJ64GA002.h>
#fuses HS,NOWDT,NOPROTECT
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_B13, rcv=PIN_B12)
#define  I2C_Address  0x60

#INT_SI2C
void SI2C_interupt()
{
   //There is no point in using poll. If the ISR is called, a byte _is_ waiting
   indata = 0;
   indata = i2c_read();
   state = i2c_isr_state();
     if (state <0x80)
    { //Here read from master is required
      switch (state)
      {
      case 0:
         Caldata[0] = indata; //address
         break;
      case 1:
         Caldata[1] = indata; //constant
         break;
      case 2: 
         Caldata[2] = indata; //constant
         break;
      case 3:
         Caldata[3] = indata; //counter
         break;
      case 4:
         Caldata[4] = indata; //command
         break;
      case 5:
         Caldata[5] = indata; //checksum
         break;
     
      default: //extend states here, if more than two writes are needed
         //Here master has tried to write more than two bytes
         //Just ignore the data
         break;
      }
         
    }
       I2C1STAT_COV = 0; //0x208.6 - Receive Overflow Flag in I2CxRSR
       I2C1_IWCOL = 0; // 0x208.7 - Write Collision Detect-> 1=Collision 06102008RA
       I2C1_TBF = 0; //0x208.0 - Transmit Full Status Bit-> 1=full 06102008RA       
       I2C1_RBF = 0; //0x208.1 - Receive Full Status Bit -> 1=Full 06102008RA
       
 
 if (state >= 0x80)
     {
      data = 0xff;
      switch (state)
     
      {
      case 0x80:
        i2c_write(0);
        checksum = 0;
        break;
      case 0x81:
         data = 0x30;
         transmit[state] = data;
         i2c_write(transmit[state]);
         
         break;
      case 0x82:
         data = 0x35;
         transmit[state] = data;
         i2c_write(transmit[state]);
         break;
      case 0x83:
         data = 0;
         transmit[state] = data;
         i2c_write(transmit[state]);
         break;
      case 0x84:
         data = 0;
         transmit[state] = data;
         i2c_write(transmit[state]);
         break;
      case 0x85:
         data = speed_settingA & 0x0f;
         {
         if (input(sense) == 0)
           data |= 0x20;
         if (input(sense1) == 0)
           data |= 0x40;
         if (input(error) == 1)
           data |= 0x80;
         if (input(error) || input(error1) == 1)
           data |= 0x80;
         }
         transmit[state] = data;
         i2c_write(transmit[state]);
         break;
      case 0x86:
         break;
      case 0xB9:   
         transmit[state] = checksum;
         i2c_write(transmit[state]);
         break;
         
      default:
         break;
      }
        checksum += transmit[state];

    }
}



Can anyone help me?
Thank you very much.
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