Subversion Repositories Code-Repo

Rev

Rev 128 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 128 Rev 129
Line 31... Line 31...
31
 
31
 
32
// Setup the PIC to operate as a master.
32
// Setup the PIC to operate as a master.
33
void I2C_Configure_Master(unsigned char speed) {
33
void I2C_Configure_Master(unsigned char speed) {
34
    i2c_data_p->operating_mode = I2C_MODE_MASTER;
34
    i2c_data_p->operating_mode = I2C_MODE_MASTER;
35
 
35
 
36
    TRISCbits.TRISC3 = 1;
36
    I2C_CLK_TRIS = 1;
37
    TRISCbits.TRISC4 = 1;
37
    I2C_DAT_TRIS = 1;
38
 
38
 
39
    SSPSTAT = 0x0;
39
    SSPSTAT = 0x0;
40
    SSPCON1 = 0x0;
40
    SSPCON1 = 0x0;
41
    SSPCON2 = 0x0;
41
    SSPCON2 = 0x0;
42
    SSPCON1bits.SSPM = 0x8; // I2C Master Mode
42
    SSPCON1bits.SSPM = 0x8; // I2C Master Mode
Line 118... Line 118...
118
// Setup the PIC to operate as a slave. The address must not include the R/W bit
118
// Setup the PIC to operate as a slave. The address must not include the R/W bit
119
void I2C_Configure_Slave(unsigned char addr) {
119
void I2C_Configure_Slave(unsigned char addr) {
120
    i2c_data_p->operating_mode = I2C_MODE_SLAVE;
120
    i2c_data_p->operating_mode = I2C_MODE_SLAVE;
121
 
121
 
122
    // Ensure the two lines are set for input (we are a slave)
122
    // Ensure the two lines are set for input (we are a slave)
123
    TRISCbits.TRISC3 = 1;
123
    I2C_CLK_TRIS = 1;
124
    TRISCbits.TRISC4 = 1;
124
    I2C_DAT_TRIS = 1;
125
 
125
 
126
    SSPADD = addr << 1;     // Set the slave address
126
    SSPADD = addr << 1;     // Set the slave address
127
 
127
 
128
    SSPSTAT = 0x0;
128
    SSPSTAT = 0x0;
129
    SSPCON1 = 0x0;
129
    SSPCON1 = 0x0;