I have strange problem with LRAE bootloader. To example code from AN2546 I add a few lines which send by SCI the string: "LRAE\n". Code:
if (*(tU16 *)APPLICATION_START == ERASED)
{
/* ensure interrupts are disabled */
asm sei;
/* initialise the system clock. Fbus = 8MHz. Assumes 4MHz Oscillator */
CRG.synr.byte = 0x3; /* configure the PLL */
CRG.refdv.byte = 0x40;
CRG.postdiv.byte = 0x1;
while(!CRG.crgflg.bit.lock) /* wait for PLL to lock */
{
}
CRG.clksel.bit.pllsel = 1; /*select the PLL as the clock source */
/* continue with the LRAE routines */
asm lds #$4000;
//Initialize();
Delay(500);
SCI0.scibdh.byte = 0;
SCI0.scibdl.byte = SCI_Prescaler[0];
/* enable SCI0 to receive */
SCI0.scicr2.bit.re = 1;
SCI0.scicr2.bit.te = 1;
while (SCI_Ptr->scisr1.bit.tdre == 0){}; // Wait until Transmit Data Register is empty.
SCI_Ptr->scicr2.bit.te = 1;
SCI_Ptr->scidrl.byte = 'L';
while (SCI_Ptr->scisr1.bit.tdre == 0){}; // Wait until Transmit Data Register is empty.
SCI_Ptr->scicr2.bit.te = 1;
SCI_Ptr->scidrl.byte = 'R';
while (SCI_Ptr->scisr1.bit.tdre == 0){}; // Wait until Transmit Data Register is empty.
SCI_Ptr->scicr2.bit.te = 1;
SCI_Ptr->scidrl.byte = 'A';
while (SCI_Ptr->scisr1.bit.tdre == 0){}; // Wait until Transmit Data Register is empty.
SCI_Ptr->scicr2.bit.te = 1;
SCI_Ptr->scidrl.byte = 'E';
while (SCI_Ptr->scisr1.bit.tdre == 0){}; // Wait until Transmit Data Register is empty.
SCI_Ptr->scicr2.bit.te = 1;
SCI_Ptr->scidrl.byte = '\n';
......................................................
Problem is showing as follows:
- LRAE starts,
- *(tU16 *)APPLICATION_START is empty so LRAE is configuring PLL, SCI
- "LRAE\n" string is sending, but not always. Usually < 50% of resets causes sending of this string. But when I turn on debug and put a breakpoint on first line:
while (SCI_Ptr->scisr1.bit.tdre == 0){};
I see the all instructions below are executed! However I dont receive any bytes on PC. I check register SCI0 and all is ok.
I dont now where the problem is. Please help me.
Best regards
Lukasz