I'm trying to read the signature row with `LPM` from my AT90USB647. Of particular interest is the 10-byte "Unique Serial Number" mentioned in section `29.7.10`. This is for a space conscious bootloader and thus all in assembly. Included is an excerpt from my software that matches the following pseudo-code.
The code acts as if the setting of SPMCSR doesn't happen and just reads the bytes from flash.
- Load desired address into Z
- Prepare rTemp2 register for later
- Reset CRC
- Set Signature Read Bit (etc)
- Load Signature Byte
- Wait for Serial Send buffer to be empty
- Send Byte and feed CRC
- Repeat from (4) until done
- Send CRC value
// From datasheet section 29.7.10 .equ SigRowStart=0x0E .equ SigRowEnd=0x18 // Setup Z ptr signature bytes as per LPM ldi ZL, SigRowStart ldi ZH, 0x00 // Register needed for LPM instruction ldi rTemp2, ((1<<SIGRD) | (1<<SPMEN)) rcall ResetCRC SignatureLPMLoop: // Specify type of LPM: Signature Read sts SPMCSR, rTemp2 // Load next signature byte lpm rTemp0, Z+ rcall WaitSerialSend rcall SendSerialDataCalcCRC cpi ZL, SigRowEnd brne SignatureLPMLoop rcall SendCRC
The obvious first guess as to what may be wrong is rTemp2 getting mangled in one of the `rcall`s. Upon inspection, rTemp2 is not touched in the called functions. I also tried moving the line where I set rTemp2 to immediately before storing that to SPMSCR.
Any suggestions as to what I might doing wrong?