[solved]ATtiny45 Access Memory Directly

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

I am trying to read/write the contents of a specific memory location on the ATtiny45. Here is the code.

uchar val;
uchar *addr = (uchar *)(0x06);   // 0x06 = ADCSRA
val = *addr;

I have also tried

uchar val;
memcpy(val, (uchar *)(0x06), 1);

val however is always zero even when I know the value is not.
I have tried different addresses but the result is always the same.

Could someone please tell me where I am going wrong.

Last Edited: Sun. Aug 9, 2009 - 07:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

// 0x06 = ADCSRA

Check your memory map again. 0x06 is R6 on real AVRs (Xmega are another matter).

See "6.2 SRAM Data Memory".

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

I have checked the datasheet and 0x06 is definitely ADCSRA on the ATtiny45. Thing is, it doesn't seem to matter what address I give it the resulting value is always zero.

Thanks for your quick reply though.

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

volatile

Stealing Proteus doesn't make you an engineer.

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

Here's what ImageCraft says it is:

#define ADCSRA	(*(volatile unsigned char *)0x26)

Chuck Baird

"I wish I were dumber so I could be more certain about my opinions. It looks fun." -- Scott Adams

http://www.cbaird.org

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

Chuck is right. It is address 6 in i/o space (after the 32 registers (hence the 0x20 + 6 = 0x26) in SRAM

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

maximax wrote:
I have checked the datasheet and 0x06 is definitely ADCSRA on the ATtiny45.
The data sheet lists in its register summary only the I/O-addresses. But you are accessing a memory-address, so you need to add 0x20 to the address.

Stefan Ernst

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

Well, what can I say? The following does indeed return the correct value for ADCSRA

volatile uchar *addr = (uchar *)(0x26);

Not sure if volatile was needed but it can't do any harm I guess.

Thank you to all who replied.

Question remains however why the Atmel datasheet tells me the address of ADCSRA is 0x06 and that 0x26 should be CLKPR ???

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

BTW, the SRAM Data Memory section ,which shows a figure describing this offset seems to be in section 5.2 of the data sheet rather than 6.2 as mentioned earlier.

--- bill

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

Quote:
The data sheet lists in its register summary only the I/O-addresses. But you are accessing a memory-address, so you need to add 0x20 to the address.

oops, I guess that answers my last question then. Thanks again!