PIC18F4520 with I2C Mode (PICDEM2 Plus Board)

Thread Starter

symphony888

Joined May 5, 2014
13
OK, so the problem right now is in the master.

Simplest thing first: do you have the I2C pull up resistors? 5K is typical. An unprogrammed (just bulk erase it) PIC should show these 2 pins as a high.

Next, your code master does one write to the slave then stops. It's much easier to see a periodic repeating signal. I would make my test master as such:

Rich (BB code):
#include <p18f4520.h>
#include <delays.h>
#include <i2c.h>
unsigned char i2cPutByteAndWait(unsigned char);
char clearData = 0;
void main(void)
{
    char address_w = 0x98, result = 0, temp = 0;
    SSPSTAT = 0xC0;
    SSPCON1 = 0x28;
    SSPCON2 = 0x00;
    SSPADD = 0x09;
    TRISC = 0b00000000;     // afaik the ports should be set as inputs
                            // but OpenI2C does this for you.
    while(1)    
    {
        OpenI2C(MASTER, SLEW_OFF);
        StartI2C();
        IdleI2C();
        WriteI2C(address_w & 0xFE);
        IdleI2C();
        WriteI2C(0x01);
        IdleI2C();
 
        SSPBUF = address_w;
        while(SSPSTATbits.BF);
        while((SSPCON2 & 0x1F) || (SSPSTAT & 0x04));
 
        SSPCON2bits.PEN = 1;        // StopI2C
        // add a delay here to break up transmissions on your scope
    }    
//    while(SSPCON2bits.PEN == 1);
}
Toggling an unused pin while transmitting gives your scope a synch to use. It's also a nice sanity test.

(BTW, leaving the EEPROM would give you a 2nd slave to test the master's START/ADDR/STOP against. So it may have helped to have left it in.)
Thanks for the reply man . I'll give this a try and see how it goes.
 
Top