A gap in the 08M2 documentation?

cpedw

Senior Member
#1
I was trying to find how many ordinary RAM (peek/poke) locations there are in an 08M2.

Manual 2 under peek & poke gives "The M2 parts have up to 512 bytes of user RAM " but the next sentence "The peek and poke commands are used to read and write to all 256 bytes of the user RAM " seems not totally consistent. That's followed by explicit accounts for 14, 18 and 20M2. (Incidentally, can "location" in peek/poke be a word variable to reach addresses 256-511?)

Manual 1 page 54, "Storage Variables" has a table for everything but not 08M2.

The "PICAXE-M2 summary" and "M2 series product briefing" dated 02/2012 gives 128 variables for 08M2. Is that the right answer?

Derek
 

Aries

New Member
#4
This short bit of code checks whether an address is valid. It uses bptr (which always works) to put values into locations 127, 255 and 511. It then tries to read them back, using peek from the address or via a word variable holding the address (so no truncation to 255).

Code:
symbol TestLoc127 = 127
symbol TestLoc255 = 255
symbol TestLoc511 = 511

bptr = TestLoc127 : @bptr = 012 : sertxd("TestLoc127=",#bptr," value = ",#@bptr,CR,LF)
bptr = TestLoc255 : @bptr = 123 : sertxd("TestLoc255=",#bptr," value = ",#@bptr,CR,LF)
bptr = TestLoc511 : @bptr = 234 : sertxd("TestLoc255=",#bptr," value = ",#@bptr,CR,LF)

peek TestLoc127,b1 : sertxd("TestLoc127=",#b1,CR,LF)
peek TestLoc255,b1 : sertxd("TestLoc255=",#b1,CR,LF)
peek TestLoc511,b1 : sertxd("TestLoc511=",#b1,CR,LF)

w2 = TestLoc127 : peek w2,b2 : sertxd("TestLoc127=",#b2,CR,LF)
w2 = TestLoc255 : peek w2,b2 : sertxd("TestLoc255=",#b2,CR,LF)
w2 = TestLoc511 : peek w2,b2 : sertxd("TestLoc511=",#b2,CR,LF)
Using the simulator on a 20m2, the result is as expected:
Code:
TestLoc127=127 value = 12
TestLoc255=255 value = 123
TestLoc255=511 value = 234
TestLoc127=12
TestLoc255=123
TestLoc511=234
TestLoc127=12
TestLoc255=123
TestLoc511=234
However, on an 08m2, bptr is restricted to 127 (hence 128 bytes only) and the simulator throws an error (invalid RAM address) on the first attempt to access the value via peek.
Code:
TestLoc127=127 value = 12
TestLoc255=127 value = 123
TestLoc255=127 value = 234
TestLoc127=234
 < this is when the invalid address message appears>
 

hippy

Technical Support
Staff member
#5
"The peek and poke commands are used to read and write to all 256 bytes of the user RAM " seems not totally consistent
It is always worth checking the online documentation which is the more authoritative source these days. That has the "256" removed because, as you note, it's not entirely consistent with how many bytes of RAM there actually are.

http://www.picaxe.com/BASIC-Commands/Variables/peek
http://www.picaxe.com/BASIC-Commands/Variables/poke

A quick way to determine how many bytes of RAM there are for M2's and X2's ...
Code:
bPtr = -1
w0   = bPtr + 1
SerTxd( "There are ", #w0, " bytes of RAM (0-", #bPtr, ")", CR, LF )
Also works for size of Scratchpad on the X2's ...
Code:
ptr = -1
w0   = ptr + 1
SerTxd( "There are ", #w0, " bytes of Scratchpad (0-", #ptr, ")", CR, LF )
 
Top