
AN428
36 Rev. 0.6
// Parameters :
// 1) unsigned char addr - address to read data from the device
// range is full range of character: 0 to 255
//
// This function returns a single byte from location <addr> in the device then
// polls the <SMB_BUSY> flag until the read is complete.
//
U8 I2C_ByteRead (U8 addr)
{
U8 return_val; // Holds the return value
while (SMB_BUSY); // Wait for SMBus to be free.
SMB_BUSY = 1; // Claim SMBus (set to busy)
// Set SMBus ISR parameters
TARGET = SLAVE_ADDR<<1; // Set target slave address
SMB_RW = WRITE; // A random read starts as a write
// then changes to a read after
// the repeated start is sent. The
// ISR handles this switchover if
// the <SMB_RANDOMREAD> bit is set.
SMB_SENDWORDADDR = 1; // Send Word Address after Slave Address
SMB_RANDOMREAD = 1; // Send a START after the word address
SMB_ACKPOLL = 1; // Enable Acknowledge Polling
// Specify the Incoming Data
WORD_ADDR = addr; // Set the target address in the
// devices's internal memory space
pSMB_DATA_IN = &return_val; // The incoming data pointer points to
// the <retval> variable.
SMB_DATA_LEN = 1; // Specify to ISR that the next transfer
// will contain one data byte
Kommentare zu diesen Handbüchern