• AVR Freaks

How to configure PIC18 as I2C slave

Author
alagappan_nachu
Junior Member
  • Total Posts : 106
  • Reward points : 0
  • Joined: 2014/11/28 00:22:25
  • Location: 0
  • Status: offline
2016/04/19 06:06:24 (permalink)
0

How to configure PIC18 as I2C slave

Hi,
 
I am using MPLAB IDE v8.92 and C18 compiler. I need to use PIC 18F as i2c slave device talking arduino i2c master. 
 
my slave code is
//////  code part here  
void main()
{
TRISB = 0;
TRISE = 0;
TRISC = 0;
TRISD = 0;
ANCON0 = ANCON0 & 0xE0; // config RA0-4 as digital pin
TRISA = 0;
SSPADD = 0xB0; //SSPADD contains I2C device address in SLAVE mode
OpenI2C( SLAVE_7, SLEW_OFF);
while(1)
{
while ( !DataRdyI2C1() )
{
addr = ReadI2C1();
AckI2C1();
IdleI2C1();
data = ReadI2C1();
NotAckI2C1()
IdleI2C1();
if(data = 7)
{
LATB = 0x55;
}else
{
LATB = 0x0F;
}
}
}
}
 
Hi anyone tell me any example code for configuring pic18 as i2c slave. Any example code would be helpful.
communication between two pic one as master and other as slave example would be helpful.
 
Thanks
 
Alagappan
#1

5 Replies Related Threads

    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: How to configure PIC18 as I2C slave 2016/04/19 07:21:34 (permalink)
    0
    Which PIC18?
    Generally, peripheral pins will need to be set as input, not output.

    GENOVA :D :D ! GODO
    #2
    alagappan_nachu
    Junior Member
    • Total Posts : 106
    • Reward points : 0
    • Joined: 2014/11/28 00:22:25
    • Location: 0
    • Status: offline
    Re: How to configure PIC18 as I2C slave 2016/04/19 21:20:22 (permalink)
    0
    pic18f66k22 SDA1/SCL1
    #3
    jtemples
    عُضْوٌ جَدِيد
    • Total Posts : 11286
    • Reward points : 0
    • Joined: 2004/02/13 12:31:19
    • Location: Southern California
    • Status: offline
    Re: How to configure PIC18 as I2C slave 2016/04/19 23:18:42 (permalink)
    +1 (1)
    You'll want to read AN734 (DS00734B) which talks about I2C slave mode in detail.  I'm doubtful you can implement a slave with those library functions.  And "if(data = 7)" doesn't do what you want.
    #4
    alagappan_nachu
    Junior Member
    • Total Posts : 106
    • Reward points : 0
    • Joined: 2014/11/28 00:22:25
    • Location: 0
    • Status: offline
    Re: How to configure PIC18 as I2C slave 2016/04/20 02:27:00 (permalink)
    0
    sorry it was "if(data == 7)". Even i changed that code is not working!
    any example code for i2c slave ??
    #5
    DarioG
    Allmächtig.
    • Total Posts : 54081
    • Reward points : 0
    • Joined: 2006/02/25 08:58:22
    • Location: Oesterreich
    • Status: offline
    Re: How to configure PIC18 as I2C slave 2016/04/20 02:41:33 (permalink)
    0
    AN734 (DS00734B)
    as John said

    GENOVA :D :D ! GODO
    #6
    Jump to:
    © 2019 APG vNext Commercial Version 4.5