Microchip Technology DM164130-2 User Manual

Page of 42
Hardware Libraries and Drivers
 2010 Microchip Technology Inc.
DS41401B-page 23
5.6.2
I
2
C Function Interface
5.6.2.1
i2c_init
The function i2c_init configures the I
2
C driver and makes it ready to receive 
transaction in the transaction queue.
FIGURE 5-1:
5.6.2.2
i2c_insert
The function i2c_insert places one complete set of Transaction Request Block 
(TRB’s). TRBs can be bundled into an array of multiple TRBs and inserted as one large 
request. The driver will ensure that all the TRBs in the list will be processed sequentially 
with I
2
C restarts separating them.
FIGURE 5-2:
5.6.2.3
i2c_build_write_trb / i2c_build_read_trb
The i2c_build_write_trb and i2c_build_read_trb functions are helpers to 
assemble the I2C_TRANSACTION_REQUEST_BLOCKS from passed parameters.
FIGURE 5-3:
5.6.2.4
i2c_write_block / i2c_read_block
The i2c_write_block and i2c_read_block functions are helpers that assemble 
a TRB, insert it into the queue and wait for the transaction to complete.
initialize()
{
      i2c_init(I2C_400K);
}
Send_data()
{
I2C_TRANSACTION_REQUEST_BLOCK trb_list[5];
I2C_RESULTS flag;
… populate the trb’s …
i2c_insert(5,trb_list, &flag);
}
Send_one_byte()
{
I2C_TRANSACTION_REQUEST_BLOCK trb_list;
unsigned char data;
I2C_RESULTS flag;
data_block = .. my data byte ..
i2c_build_write_trb(&trb_list,ADDRESS, 1, &data, i2c_200K);
i2c_insert(1,&trb,&flag);
}