F1 Evaluation Platform User’s Guide
DS41401B-page 22 2010 Microchip Technology Inc.
5.6 USING THE I
2
C™ DRIVER
The supplied software includes an I
2
C Master mode driver with the following features:
1. Interrupt driven or polled
2. Queued requests
3. Minimum memory requirements
4. Uses Restart to maximize bus bandwidth
5. Multiple atomic I
2
C transactions allowed at each queue entry
6. Completion flag for each queued block of I
2
C commands.
5.6.1 I
2
C Data Structures
Two data structures are defined to simplify interactions with the I
2
C driver.
5.6.1.1 I2C_RESULTS_T
The I2C_RESULTS_T is an enumerated type with the following enumerations:
The data completion flag for an I
2
C request is of type I2C_RESULTS_T. This flag will
be I2C_REQUEST_PENDING until the request is complete. If the request completed
without errors, the value will be I2C_REQUEST_COMPLETE. If there were errors, the
value will reflect one of the other 4 error conditions.
5.6.1.2 I2C_T
The I2C_T is a structure representing one transaction on the I
2
C bus. A transaction
contains the following elements:
1. A 7- or 10-bit address. Address type is determined automatically by the driver.
R/W mode is implicit in the address and specified by bit 0.
2. An 8-bit baud rate. This is the value placed in SPADD. Predefined constants are
included that compute the SPADD value given an FOSC value. Set FOSC with
a #define before #including the I2C.h file.
3. A buffer_length. This is the number of bytes available for reading or writing
at the supplied data buffer.
4. A Buffer Pointer. Your application will allocate a block of memory for an I
2
C
transaction. Pass a pointer to this block via the Buffer Pointer. The block must
remain valid until the transaction is complete (i.e., if you allocate the block as a
non-static array within a function, you must not leave the function until the I
2
C
transaction is complete or the array may be reused by a different function).
TABLE 5-1: I2C_RESULTS_T
I2C_REQUEST_PENDING Request is in the queue or in process but it is not
done.
I2C_REQUEST_COMPLETE The request is finished successfully.
I2C_REQUEST_STUCK_START The request was aborted. The start condition did
not clear correctly.
I2C_REQUEST_ADDRESS_NO_ACK The request was aborted. No ACK occurred on
the address, so the target device must not exist
or is not functioning.
I2C_REQUEST_DATA_NO_ACK The request was aborted. Not all of the data
could be sent because the device did not ACK a
byte.
I2C_REQUEST_LOST_STATE The I
2
C state machine had a RAM corruption
and the default case caught the failure. This will
infinite loop so you should never see it.