www.ti.com
Bootloader Code Listing (V3.0)
// Initialize I2C in master transmitter mode
I2caRegs.I2CSAR = 0x0050;
// Slave address - EEPROM control code
I2caRegs.I2CPSC.all = 0x0;
// I2C clock should be between 7Mhz-12Mhz
I2caRegs.I2CCLKL = 0x0035;
// Prescalers set for 100kHz bit rate
I2caRegs.I2CCLKH = 0x0035;
//
at a 12Mhz I2C clock
I2caRegs.I2CMDR.all = 0x0620;
// Master transmitter
// Take I2C out of reset
// Stop when suspended
I2caRegs.I2CFFTX.all = 0x6000;
// Enable FIFO mode and TXFIFO
I2caRegs.I2CFFRX.all = 0x2000;
// Enable RXFIFO
return;
}
//#################################################
// Uint16 I2C_CheckKeyVal(void)
//-----------------------------------------------
// This routine sets up the starting address in the
// EEPROM by writing two bytes (0x0000) via the
// I2C-A port to slave address 0x50. Without
// sending a stop bit, the communication is then
// restarted and two bytes are read from the EEPROM.
// If these two bytes read do not equal 0x08AA
// (little endian), an error is returned.
//-----------------------------------------------
inline Uint16 I2C_CheckKeyVal(void)
{
// To read a word from the EEPROM, an address must be given first in
// master transmitter mode. Then a restart is performed and data can
// be read back in master receiver mode.
I2caRegs.I2CCNT = 0x02;
// Setup how many bytes to send
I2caRegs.I2CDXR = 0x00;
// Configure fifo data for byte
I2caRegs.I2CDXR = 0x00;
//
address of 0x0000
I2caRegs.I2CMDR.all = 0x2620;
// Send data to setup EEPROM address
while (I2caRegs.I2CSTR.bit.ARDY == 0) // Wait until communication
{
//
complete and registers ready
}
if (I2caRegs.I2CSTR.bit.NACK == 1)
// Set stop bit & return error if
{
//
NACK received
I2caRegs.I2CMDR.bit.STP = 1;
return ERROR;
}
// Check to make sure key value received is correct
if (I2C_GetWord() != 0x08AA) {return ERROR;}
return NO_ERROR;
}
//#################################################
// void I2C_ReservedFn(void)
//-------------------------------------------------
// This function reads 8 reserved words in the header.
//
1st word - parameters for I2CPSC register
//
2nd word - parameters for I2CCLKH register
//
3rd word - parameters for I2CCLKL register
//
80
Bootloader Code Overview
SPRU722C – November 2004 – Revised October 2006