When I set breakpoints in this routine, the EEPROM programs correctly. When this routine is allowed to run without interference, the EEPROM fails to program. Please tell me where and how I can improve on this to make it work.
/* Enable the LED driver and wait for ready */
IO_SetOutputLevel(PCR_LED_ENABLE, IO_OUTPUT_LEVEL_HIGH);
while ( IsLedEepromReady() == 0)
{
/* just wait a bit */
}
/* make ready with the unlock */
spiMsg = (UNS16)((LP_EEPROM_UNLOCK_ADDR + 1) << 8) | LOCK1;
(void) SPI1_Send2Bytes( &spiMsg);
spiMsg = (UNS16)((LP_EEPROM_UNLOCK_ADDR + 1) << 8) | LOCK2;
(void) SPI1_Send2Bytes( &spiMsg);
spiMsg = (UNS16)((LP_EEPROM_UNLOCK_ADDR + 1) << 8) | LOCK3;
(void) SPI1_Send2Bytes( &spiMsg);
/* blaze in the 25 byte configs */
for (idx = 0; idx < eeSize; idx++ )
{
spiMsg = (UNS16)((((LP_EEPROM_START + idx)<<1) + 1)<<8) | LEDDRV_EE.LedDriverEepromDef[idx];
(void) SPI1_Send2Bytes( &spiMsg);
}
/* burn the EEPROM */
spiMsg = (UNS16)((LP_EEPROM_CONTROL_ADDR + 1)<<8) | 0x02; /* start the burn */
spiReply = SPI1_Send2Bytes( &spiMsg);
while ( IsLedEepromReady() == 0)
{
/* just wait a bit */
}
spiMsg = (UNS16)((LP_EEPROM_CONTROL_ADDR + 1)<<8) | 0x00; /* stop the burn */
spiReply = SPI1_Send2Bytes( &spiMsg);
spiMsg = (UNS16)((LP_EEPROM_UNLOCK_ADDR + 1)<<8) | 0x00; /* lock the door */
spiReply = SPI1_Send2Bytes( &spiMsg);
This routine starts by setting the VDDIO/EN pin high and then polling the EEPROM_CONTROL_REG to see when the READY_BIT gets set. Next the process unlocks the EEPROM.. The FOR loop controls writing all 25 bytes with the required values. We then write the bit to do the EEPROM burn. While the burn is happening we are polling the CONTROL register for the READY_BIT once again. The next step turns off the burn bit and locks the EEPROM.
The Send2Bytes sub writes two bytes into the SPI registers and waits for the returning two bytes. So there is no overrun possible in the SPI.