Search code examples
avravr-gccatmegaavr-studio5

how to read atmega 32 signature row?


I tried to read signature row of atmega32 with boot_signature_byte_get(0); but i get this error : 'SIGRD' undeclared (first use in this function) and it seems that it's because of we only can read the signature with the AVRs that have SIGRD bit in SPMCR (i suppose!).
Is this right? and so then how can i read signature row another way?


Solution

  • Back in 2007, there was no function in any header to read the signature byte, then it was introduced in the same year. But as it seems, it still has some problems with that.

    The datasheet says:

    All Atmel microcontrollers have a three-byte signature code which identifies the device.
    This code can be read in both serial and parallel mode, also when the device is locked.
    The three bytes reside in a separate address space.
    

    Meaning that the ATMEGA32 has read-access to this byte. Also in the datasheet, it specifies how to read this byte. And in most of their MCUs, it's read in the same way, but for some reason, the SIGRD definition number is missing in some header files, including the ATMEGA32 one.

    But, as a workaround, we can define SIGRD manually. We just have to known its value. When I do some findstr (or grep) in the header files searching this definition, unanimously, its value is 5.

    So, the workaround would be:

    #define SIGRD 5
    #include <avr/boot.h>
    

    I compiled this successfully, but I've just tried to test the program on a simulation software, as I don't have the ATMEGA32 with me right now. It returns a byte, so now it's up to you to known if this is the correct byte...

    Regarding the SPMCR thing you said, it seems that the signature row is in another address space (by my understanding, I don't know if this is right I can't confirm), and the way to get it, is using some instructions, similarly when we upload some program to the MCU.