Bootloader Code Listing (V3.0)
// The remaining reserved words are read and discarded
// and then program execution returns to the main routine.
//-------------------------------------------------
inline void I2C_ReservedFn(void)
{
Uint16 I2CPrescaler;
Uint16 I2cClkHData;
Uint16 I2cClkLData;
Uint16 I;
// Get I2CPSC, I2CCLKH, and I2CCLKL values
I2CPrescaler = I2C_GetWord();
I2cClkHData = I2C_GetWord();
I2cClkLData = I2C_GetWord();
// Store I2C clock prescalers
I2caRegs.I2CMDR.bit.IRS = 0;
I2caRegs.I2CCLKL = I2cClkLData;
I2caRegs.I2CCLKH = I2cClkHData;
I2caRegs.I2CPSC.all = I2CPrescaler;
I2caRegs.I2CMDR.bit.IRS = 1;
// Read and discard the next 5 reserved words
for (I=1; I<=5; I++)
{
I2cClkHData = I2C_GetWord();
}
return;
}
//#################################################
// Uint16 I2C_GetWord(void)
//-----------------------------------------------
// This routine fetches two bytes from the I2C-A
// port and puts them together little endian style
// to form a single 16-bit value.
//-----------------------------------------------
Uint16 I2C_GetWord(void)
{
Uint16 LowByte;
I2caRegs.I2CCNT = 2; // Setup how many bytes to expect
I2caRegs.I2CMDR.all = 0x2C20; // Send start as master receiver
// Wait until communication done
while (I2caRegs.I2CMDR.bit.STP == 1) {}
// Combine two bytes to one word & return
LowByte = I2caRegs.I2CDRR;
return (LowByte | (I2caRegs.I2CDRR<<8));
}
//===========================================================================
// No more.
//===========================================================================
SPRU722C – November 2004 – Revised October 2006 Bootloader Code Overview 81
Submit Documentation Feedback