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

I2C whatever

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



Joined: 14 Dec 2005
Posts: 11
Location: South Africa

View user's profile Send private message ICQ Number

I2C whatever
PostPosted: Mon Jan 23, 2006 4:13 am     Reply with quote

Hi

Since a few days I try to get two 18F242 connected. Here the code.

MASTER:

Code:

BYTE data;
#int_TIMER1
TIMER1_isr()
{
   output_high(PIN_B3);


   i2c_start();
   i2c_write(0xa0);
   i2c_write(0xEE);
   i2c_start();
   i2c_write(0xa1);
   data = i2c_read(0);
   i2c_stop();

   printf("|%x|",data);

   delay_ms(20);
   output_low(PIN_B3);
}


void main()
{
   output_high(PIN_B4);
   delay_ms(2000);
   output_low(PIN_B4);

   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_wdt(WDT_OFF);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_2);
   setup_timer_2(T2_DISABLED,0,1);
   setup_timer_3(T3_DISABLED|T3_DIV_BY_1);

   enable_interrupts(INT_TIMER1);
   enable_interrupts(global);

   while(1)
   {}

}


Slave:
Code:

enum {address,data};
int mode;
BYTE data1 = 0;
BYTE BUFFER;


#int_SSP
SSP_isr()
{
   BYTE ch;
   output_high(PIN_B4);




   if(i2c_poll())
   {
      ch = i2c_read(1);

      if(mode == address)
      {
         mode = data;
      }
      else
      {
         data1 = ch;
         mode = address;
         printf("|%x|", data1);
      }

   }
   else i2c_write(0xEE);



   delay_ms(20);
   output_low(PIN_B4);
}


void main()
{
   output_high(PIN_B4);
   delay_ms(2000);
   output_low(PIN_B4);

   enable_interrupts(INT_SSP);
   enable_interrupts(global);
   mode = address;
   while(1);
}


So.

I check the send values via Hyper Terminal.
And thats my problem:
At the slave output I am getting permanently the address of the PIC |a0||a0|... and so on and not the |EE||EE|....
And at the master output |ff||ff| ....

Is there something wrong with the routines or do I have to clear the input buffer of the slave PIC? Because I think the code "should" work. I also screened the signal on the scope. And till the write command everything looks fine.

It would be very nice if somebody could help me. I tried it now to long without result. Sad Crying or Very sad

BYE
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 23, 2006 10:35 am     Reply with quote

Quote:
It would be very nice if somebody could help me. I tried it now to long without result.

My suggestion is to get the CCS example EX_SLAVE.C, working first.
It's in this folder:
c:\Program Files\Picc\Examples
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