How to read ATMega6450 fuse bits from program

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd like to read the fuse bits (specifically OCDEN) in an ATMega6450 from the program running on it.  Possible?  If so, how?  Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I saw your post in the other forum and don't know how to do it with ICC, using Studio you need to add fuse.h I think, maybe you can try with Studio and then port the code to ICC.

http://www.nongnu.org/avr-libc/u...

Not much more help from here smiley I have only code in assembler for some Xmega chips.

 

edit and I may have it all wrong, it seem that the fuse.h is used to embed the fuse values into the elf file blush

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Sun. Mar 12, 2017 - 07:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes, you can use < avr/boot.h>
I think that all AVRs can read their fuses. Modern ones can read their Signature and Calibration too.
.
David.

Last Edited: Sun. Mar 12, 2017 - 07:18 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, guys. I'll see if IMAGECraft C has AVR/boot.h in the morning (not at my PC right now). Hopefully that'll have what I'm looking for.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And I dug out some ASM code for the Mega chips too, it will give you an idea on how to do it even in ICC.

 

;Fuse value returned in temp
read_low_fuses:
	ldi		zh,0x00					;point z to 0x0000 low fuse byte 
	ldi		zl,0x00
	rjmp	read_fuses_ret
read_high_fuses:
	ldi		zh,0x00					;point z to 0x0003 high fuse byte 
	ldi		zl,0x03
	rjmp	read_fuses_ret
read_ext_fuses:
	ldi		zh,0x00					;point z to 0x0002 ext fuse byte 
	ldi		zl,0x02

read_fuses_ret:
	ldi   temp,(1<<BLBSET | 1<<SPMEN)
	out   SPMCSR,temp
	lpm   temp,z
	ret

 

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Unfortunately, I haven't been able to find avr/boot.h in ICCAVR.  I did track down GCC-AVR's implementation here, but I haven't been able to get the relevant part (#define boot_lock_fuse_bits_get( address)) to work in ICCAVR.  Of course, I'm not very sophisticated when it comes to defines and only use them as simple substitution macros, so that one's incomprehensible to me.  Hopefully someone will chime in from the ICCAVR mailing list where I also posted.  If not, I'll try your asm, John.  Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Easier to post here than the ICC forum to post pictures.

 

So I found and dusted off ICCV8.12 and installed it, tried the example Richard provided and I get errors, this is the code I used.

 

#include <macros.h>

char read_fuse(void) {

//  point z to 0x0003 (high fuse byte )

asm("ldi R31h,0x00\n"

"ldi  R30,0x03\n"

"ldi  R16,(1<<BLBSET | 1<<SPMEN)\n"

"out  SPMCSR,R16\n"

"lpm  R16,z\n"

"ret\n");
}

int main(void)
{

    // Insert code

    do
    {
     read_fuse();
    }while(0);

    return 0;
}

 

 

doesn't like a few things.

 

The Help file didn't work on my install but found the PDF help and even tried a couple of lines copied from there unsuccessfully.

 

Obviously I don't know what I'm doing. crying

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for going to all that effort, John.  I get the same errors as your first three.  I'll post back to the ICCAVR list to see if Richard can straighten things out.