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 Ex_slave (receiving of data problem)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
[email protected]



Joined: 07 Feb 2012
Posts: 19
Location: pakistan

View user's profile Send private message Send e-mail Yahoo Messenger

I2c Ex_slave (receiving of data problem)
PostPosted: Mon Feb 20, 2012 1:19 am     Reply with quote

I want to communicate 2 pic 18f452 controllers but these are not working correctly. I think there must be problem at slave side. The interrupt is not generating. I'm posting photos and code.
Pull-up resistors are 4.7k
Compiler ccs 4.084
I have to submit on Wednesday. Plz help me to resolve the problem.
Tell me about FORCE_HW & FORCE_SW.
Slave address is 0x60. By adding high bit at most least significant bit for writing from master to slave becomes 0xc0.

The master side is working correctly.

Master:
Code:

#include<18F452.h>
#use delay(clock = 4000000)
#use I2C(MASTER,SLOW, SDA=PIN_B7, SCL=PIN_B6,FORCE_SW)
#fuses NOWDT,NOPROTECT,NOLVP,XT


void main ()
{
   
while(1)
{
 output_a(0xff);
 delay_ms(2000);

 i2c_start(); 
 //while(i2c_write(0xc0));
 i2c_write(0xC0);
 output_a(0xC0);
 delay_ms(1000);

 i2c_write(0x1);
 output_a(0x01);
 delay_ms(1000);

 i2c_write(0x02);
 output_a(0x02);
 delay_ms(1000);

 i2c_write(0x03);
 output_a(0x03);
 delay_ms(1000);

 i2c_write(0x04);
 output_a(0x04);
 delay_ms(1000);

 i2c_write(0x05);
 output_a(0x05);
 delay_ms(1000);

 i2c_stop();
}
}

Slave :
Code:

#include <18F452.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)

#use i2c(SLAVE, SDA=PIN_B7, SCL=PIN_B6, address=0x60,FORCE_SW)

BYTE address, buffer[0x10];

#INT_SSP
void ssp_interupt ()
{
   BYTE incoming, state;

   state = i2c_isr_state();

   if(state < 0x80)                     //Master is sending data
   {
      incoming = i2c_read();
      if(state == 1)                     //First received byte is address
         address = incoming;
      if(state == 2)                     //Second received byte is data
      {
         buffer[address] = incoming;
          output_a(incoming);
       }
}
   if(state == 0x80)                     //Master is requesting data
   {
      i2c_write(buffer[address]);
   }
}

void main ()
{
   enable_interrupts(GLOBAL);
   enable_interrupts(INT_SSP);

   while (TRUE) {}
}   













PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 20, 2012 2:27 pm     Reply with quote

Quote:
#include <18F452.h>
#fuses XT,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)

#use i2c(SLAVE, SDA=PIN_B7, SCL=PIN_B6, address=0x60,FORCE_SW)

There is no support for a software i2c slave. You must use the hardware
pins for an i2c slave. For an 18F452, this is pin C4 for SDA, and pin C3 for SCL.
[email protected]



Joined: 07 Feb 2012
Posts: 19
Location: pakistan

View user's profile Send private message Send e-mail Yahoo Messenger

thanks
PostPosted: Tue Feb 21, 2012 5:36 am     Reply with quote

I have done it Razz
wasimakhlaq



Joined: 07 Feb 2012
Posts: 5
Location: Pakistan

View user's profile Send private message Send e-mail

Thanks
PostPosted: Tue Feb 21, 2012 8:04 am     Reply with quote

Thanks all of you for your posts and helping us, we're done I2C communication using two PICs..

regards,

wasim
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