Accessing SIGROW in Tiny series

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

I have just started using the new Attiny214 chip and found the great feature - serial number that I need to serialize my product. Now the question.

 

uint8_t id0 = SIGROW_SERNUM0; // works fine

but

memcpy(id_array, *( uint8_t *)SIGROW_SERNUM0, 10); // does not work

and again

memcpy(id_array, *( uint8_t *)0x1103, 10);  // also works

 

I suspect it has something to do with special instructions to access IO space, but what are the rules to write proper code? Sure I can define my own constant, but what is "_SFR_MEM8"?

 

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

These new Tinies have a single address space, therefore you can read these memories like any other memory. You just need to know the address.

 

_SFR_MEM8 is defined in sfr_defs.h as:

 

#define _SFR_MEM8(mem_addr) (mem_addr)

 

So it does nothing, actually. The problem is that you need to pass a pointer to memcpy, but you are dereferencing it. The correct way is:

 

memcpy(id_array, ( void *)SIGROW_SERNUM0, 10);

or

memcpy(id_array, ( void *)&SIGROW.SERNUM0, 10);

 

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

Have another read of sfr_defs I think you'll find it defines _SFR_MEM8() simply for the Doxygen case and in a more complex way for building code.

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

Your right, well, not for Doxygen exactly, but the real definitions are:

 

#define _MMIO_BYTE(mem_addr) (*(volatile uint8_t *)(mem_addr))
...
#define _SFR_MEM8(mem_addr) _MMIO_BYTE(mem_addr)

 

So they are dereferenced pointers and now I'm slightly confused, but I suppose you have to take their address and pass that to memcpy.