Example #1
0
void portableMasterCloseI2C(I2cBus* i2cBus) {
    if (i2cBus == NULL) {
        CloseI2C1();
    }
    else {
        unsigned portIndex = i2cBus->port;
        if (portIndex == I2C_BUS_PORT_1) {
            CloseI2C1();
        }
    #if defined _I2C2
        else if (portIndex == I2C_BUS_PORT_2) {
            CloseI2C2();
        }
    #endif
    #if defined _I2C3
        else if (portIndex == I2C_BUS_PORT_3) {
            // TODO : Throw Not Implemented
            // I2C3CONCLR = _I2C3CON_ON_MASK,
            // DisableIntSI2C3,
            // DisableIntMI2C3,
            // DisableIntBI2C3
        }
    #endif
    #if defined _I2C4
        else if (portIndex == I2C_BUS_PORT_4) {
            // TODO : Throw Not Implemented
            // I2C4CONCLR = _I2C4CON_ON_MASK,
            // mI2C4SIntEnable(0),
            // mI2C4MIntEnable(0),
            // mI2C1BIntEnable(0)
        }
    }
    #endif
}
Example #2
0
/*
 * configures and starts outgoing data communication
 * The outgoing I2C uses MSSP1
 */
int setupOutgoing() {
    // set pins RC14, RC15 as inputs
    TRISCbits.TRISC3 = 1; // SCL1
    ANSELCbits.ANSC3 = 0;

    TRISCbits.TRISC4 = 1; // SDA1
    ANSELCbits.ANSC4 = 0;

    // configure i2c1 for master mode @ 100 kHz
    CloseI2C1();
    OpenI2C1(MASTER, SLEW_OFF);
    SSPADD = BD_RT;

    return (1);
}
Example #3
0
void InitDisplay()
{
	
	unsigned int config1 = I2C_ON | I2C_7BIT_ADD;
    //unsigned int config2 = 15;		// Works with no pll in use 
    unsigned int config2 = 24;
    
    delay(100); // THIS IS REQUIRED TO ALLOW THE VOLTAGE TO STABILIZE BEFORE INIT-ING THE DISPLAY

	ConfigIntI2C1(MI2C_INT_OFF);  //Disable I2C interrupt

	CloseI2C1();
	OpenI2C1( config1, config2);
	IdleI2C1();
	// Assert a start condition
	StartI2C1();
	while(_SEN);
	// Write the address of the slave 
	MasterWriteI2C1(Slave);
	while(I2C1STATbits.TBF);     //Wait till address is transmitted
   	while(!IFS1bits.MI2C1IF);    //Wait for ninth clock cycle

	MasterWriteI2C1(Comsend);
	IdleI2C1();
	MasterWriteI2C1(0x38);
	IdleI2C1();
	delay(10);
	MasterWriteI2C1(0x39);
	IdleI2C1();
	delay(10);
	MasterWriteI2C1(0x14);
	IdleI2C1();
	MasterWriteI2C1(0x25);
	IdleI2C1();
	MasterWriteI2C1(0x5E);
	IdleI2C1();
	MasterWriteI2C1(0x6D);
	IdleI2C1();
	MasterWriteI2C1(0x0C);
	IdleI2C1();
	MasterWriteI2C1(0x01);
	IdleI2C1();
	MasterWriteI2C1(0x06);
	IdleI2C1();
	delay(10);
	StopI2C1();
	IdleI2C1();
	CGRAM();			//define CGRAM
	
	StartI2C1();
	MasterWriteI2C1(Slave);
	IdleI2C1();
	MasterWriteI2C1(Comsend);
	IdleI2C1();
	MasterWriteI2C1(0x39);	
	IdleI2C1();	
	MasterWriteI2C1(0x01);		//go back Home
	IdleI2C1();
	StopI2C1();
	delay(10);
}