| #define | I2C_MASTER 8 |
| #define | I2C_SLAVE_10 7 |
| #define | I2C_SLAVE_7 6 |
| #define | I2C_SLEW_OFF 0xC0 |
| #define | I2C_SLEW_ON 0x00 |
Defines | |
| #define | i2cBusCollision() PIR2_BCLIF |
| #define | i2cClose() (SSPCON1 &= 0xDF) |
| #define | i2cDataRdy() (SSPSTAT_BF) |
| #define | i2cIsIdle() (((SSPCON2 & 0x1F) | (SSPSTAT_R_W)) ? FALSE : TRUE) |
| #define | i2cPutAck() {SSPCON2_ACKDT=0; SSPCON2_ACKEN=1;} |
| #define | i2cPutNack() {SSPCON2_ACKDT=1; SSPCON2_ACKEN=1;} |
| #define | i2cPutStart() (SSPCON2_SEN=1) |
| #define | i2cPutStartAndWait() {SSPCON2_SEN=1; while ( SSPCON2_SEN );} |
| #define | i2cPutStop() (SSPCON2_PEN=1) |
| #define | i2cPutStopAndWait() {SSPCON2_PEN=1; while(SSPCON2_PEN);} |
| #define | i2cRestart() (SSPCON2_RSEN=1) |
| #define | i2cWaitForIdle() while ((SSPCON2 & 0x1F) | (SSPSTAT_R_W)) |
| #define | i2cWasAckReceived() (!SSPCON2_ACKSTAT) |
| #define | SSPENB 0x20 |
Functions | |
| unsigned char | i2cGetByte (void) |
| void | i2cOpen (unsigned char mode, unsigned char slew, unsigned char baud) |
| unsigned char | i2cPutByte (unsigned char data_out) |
|
|
|
|
|
|
|
|
The following defines are used for the mode parameter in the i2cOpen() function:
|
|
|
The following defines are used for the slew parameter in the i2cOpen() function:
|
|
|
|
|
|
Test if a bus collision has occured. Return TRUE if it did, else FALSE |
|
|
Disable I2C module |
|
|
Checks if the SSP buffer contains any data that can be read. Example: if (i2cDataRdy()) { var = i2cGetByte(); }
|
|
|
Checks if the I2C bus is IDLE, and available to be used. The i2cIsIdle() function is required since the hardware I2C peripheral does not allow for spooling of bus sequences. The I2C peripheral must be in an IDLE state before an I2C operation can be initiated or a write collision will be generated.
|
|
|
Generate bus ACK condition |
|
|
Generate bus Not ACK condition. |
|
|
Generate bus start condition |
|
|
Generate bus start condition, and waits until it is finished |
|
|
Generate bus stop condition |
|
|
Generate bus stop condition, and waits until it is finished |
|
|
Generate bus restart condition |
|
|
Waits until the I2C bus is IDLE, and available to be used. The i2cWaitForIdle() function is required since the hardware I2C peripheral does not allow for spooling of bus sequences. The I2C peripheral must be in an IDLE state before an I2C operation can be initiated or a write collision will be generated. |
|
|
Tests if an ACK was received from the slave. Returns true if it was, else false. |
|
|
Enable serial port and configures SCK, SDO, SDI |
|
|
Read single byte from I2C bus
|
|
||||||||||||||||
|
This function resets the SSP module to the POR state and then configures the module for Master/Slave mode and the selected slew rate.
|
|
|
This routine writes a single byte to the I2C bus.
|
1.4.5