Can not LD data with Y-Index

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

Please excuse my question if it can be found elsewhere--I've yet to find a good resource (other than here) on getting started with AVR. I'm coming from an M68HC11 background.

I'm using the Y-Index and pointing it at a table that I've created and I'd like to step through the table, but I am unable to load any data from it. Here is a simplified example of what I'm working on.


.include "m8535def.inc"
.def Temp = R16

.org 0x0000
	ldi YL, low(Table)	
	ldi YH, high(Table)


Loop:
	ld Temp, Y+
	;...
	rjmp Loop

.org 0x0101
Table: .DW 0,9,11,16,48

Thing is, when I get to ld Temp, Y+ my Y will inc but I get nothing in Temp. What gives? The only thing I can think of is maybe I'm mixing Program space and data space? I don't know how to differentiate between the two really, if that's my problem.

Thanks for everyones help! :)
Jason

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

SteveN wrote:
Hi,

Sorry if you read my "ghost" post. I wrote before but then realized I had not properly read your post so then I deleted that post.

Anyway, you can only use the .dw directive with program memory or EEPROM. Use the .byte directive for SRAM and you will need to initialize the SRAM yourself (at least that is what I do, maybe there is another way...in which case I would love to learn that way as well :) ).

Regards,
Steve

Thanks for the tip and quick reply. What do you mean by "Program Memory"? Isn't that where I'm putting it? Sd far as intializing it do I need to use LDI or something? How would I get the info there in the first place?

Thanks,
Jason

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

SteveN wrote:
Hi again,

BTW, this is an excellent reference if you do not already have it:

http://www.atmel.com/dyn/resourc...

Regards,
Steve

Oh! I haven't seen that one before, but there wasn't much that was new to me. I see the .DSEG and .CSEG, but I'm not sure how to use them. I did notice though, on page 13 they have this snippet

.CSEG
varlist:.DW 0,0xffff,0b1001110001010101,-32768,65535

and I think that's precisely what I want to use. I also see them using the .DSEG and reserving memory with .BYTE, but still my question is...how do I get my data there?

Thanks,
Jason

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

Lakee911 wrote:
Please excuse my question if it can be found elsewhere--I've yet to find a good resource (other than here) on getting started with AVR. I'm coming from an M68HC11 background.

I'm using the Y-Index and pointing it at a table that I've created and I'd like to step through the table, but I am unable to load any data from it. Here is a simplified example of what I'm working on.


.include "m8535def.inc"
.def Temp = R16

.org 0x0000
	ldi YL, low(Table)	
	ldi YH, high(Table)


Loop:
	ld Temp, Y+
	;...
	rjmp Loop

.org 0x0101
Table: .DW 0,9,11,16,48

Here is one way to do it that works:

.include "m8535def.inc"
.def Temp = R16

.cseg

.org 0x0000
ldi ZH, high(2*Table)
ldi ZL, low(2*Table)

Loop:
lpm
adiw ZL,1
rjmp Loop

Table: .DB 0,9,11,16,48

Leon

Leon Heller G1HSM

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

I will definately check out this LPM bussiness ;) That may be what I am looking form. I am beginning to wonder: Should I be storing my data in SRAM or EEPROM? Is that better or easier? When should I use it?

Thanks,
Jason

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

SteveN wrote:

Leon's code will work. The value loaded will be in R0. The mega8535 will, however, support the following: (if I am reading the datasheet correctly...which this morning is not a given :roll: )

lpm Rx,Z+

Yes it did! Tha'ts great. Thanks for both of your guys help. I'm just not sure I'm going about this the right way now. I don't know if I'm storing my data in the right place, or even accessing it the best way.

How should I go about this? This the best way? I've only got Z-Index to Load Byte Data, but I think I need two Indexes.... :(

Thanks,
Jason

Last Edited: Mon. Aug 16, 2004 - 01:57 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok. Thanks I will post a new topic with the question.

Jason

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

Lakee911

The AVR is not like a HC11 , in regards of reading values stored in CSEG (FLASH)

The AVR is using Harvard Architecture , and you can not access the CSEG (FLASH Section) from within your program.
Only the CPU (Program counter) can fetch from the instruction/flash bus.
... Well unless you use the new LPM instruction , witch is made for accessing tables etc. in flashmem , or was it made for Selfprogramming , and we just got the other things as a "Side effect". :lol:

I hope i have explained it correctly , im a newbie on AVR's also.

/Bingo

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

You got it almost right, except LPM is not a new instruction, SPM is the new instruction for writng to flash (aka self programming).

LPM has existed since day one as a means of fetching data from the instruction bus (flash). Because of the AVR's harvard architecture the same instructions for fetching and moving data on teh data bus cannot be used for fetching data over the code space/instruction bus (separate address spaces). There are many forms of LPM, you will need to consult the datasheet for your AVR to see which froms are actually supported.

Writing code is like having sex.... make one little mistake, and you're supporting it for life.