Problem With 'Read' Function

CDRIVE

Senior Member
For some odd reason the Read function doesn't pass any data. I've copied and pasted sample code from the Picaxe manual but Nada?

Code:
[B][FONT=Courier][SIZE=1][COLOR=#004f8a][FONT=Courier][SIZE=1][COLOR=#004f8a][FONT=Courier][SIZE=1][COLOR=#004f8a][LEFT]Main:For B0 = 0 to 63 
  Read B0,B1      ' read b0 into b1  Note, does notwork!    
  SerOut B.7,N2400,(B1) 
Next B0 [/LEFT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B]
 
Last edited:

nick12ab

Senior Member
Is this in the simulation or in real life?

Have you written data to the EEPROM beforehand? This can be done using the read or write commands at runtime and the eeprom command when downloading a program. Failure to include a #no_table or #no_data directive at the beginning of your program will result in the EEPROM being cleared upon download.

Are you aware that you need to convert numbers to ASCII to see them?
 

eclectic

Moderator
For some odd reason the Read function doesn't pass any data. I've copied and pasted sample code from the Picaxe manual but Nada?

Code:
[B][FONT=Courier][SIZE=1][COLOR=#004f8a][FONT=Courier][SIZE=1][COLOR=#004f8a][FONT=Courier][SIZE=1][COLOR=#004f8a][LEFT]Main:For B0 = 0 to 63 
  Read B0,B1      ' read b0 into b1  Note, does notwork!    
  SerOut B.7,N2400,(B1) 
Next B0 [/LEFT]
[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/B]
See Manual 2, p. 261.
Write some data first, then read it.

e
 

CDRIVE

Senior Member
Is this in the simulation or in real life?

Have you written data to the EEPROM beforehand? This can be done using the read or write commands at runtime and the eeprom command when downloading a program. Failure to include a #no_table or #no_data directive at the beginning of your program will result in the EEPROM being cleared upon download.

Are you aware that you need to convert numbers to ASCII to see them?
Nick, thanks for the reply. Yes, this is a simulation and I guess the simulator doesn't provide a faux EEPROM.
:D And yes, I know I have to precede the byte variable with # to output ASCII. I wasn't working up code for serial output though. I was just reading through the M2 parts manuals and came across the Read function.

This does beg the question as to why the manual used the 'Read' function in that sample code. It seems rather inapplicable. First, because It's a loop, where b0 changes constantly. What's the point of storing b0 into none volatile memory? It'll only hold the last value before exiting the loop. Secondly because the example didn't use the 'Write' function to begin with. Even it they did, it escapes me how it would be useful in this sample code.




Thanks again.
 

oracacle

Senior Member
I thought read was suposed to be done from the data memory where b0 would be the address the information is stored and to be read into b1. so in other word you need to write data in address 0-63, page 261 manual 2. you may well be getting nothing as you havent stored anything there yet

try something like:
Code:
main:
	for b0 = 0 to 63	;increment address from 0 to 63
	let b1 = b1 + 2	'write data in increment of 2
	write b0,b1
	next b0

	pause 5000
	let b0 = 0

	for b0 = 0 to 63	;increments address from 0 to 63
	read b0, b1		;write data drom address to variable
	sertxd (#b1,13,10)	;serial out via download circuit
	next b0
	pause 5000
end
this will write data to the memort first before reading it back to you
 

westaust55

Moderator
@CDDrive,
Does the following code snippet halp you understand the use of EEPROM and the READ command

Code:
;Preload EEPROM memory with some data - this occurs only at time of program download to the PICAXE
EEPROM 0, (0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,32,34,36,38,40,42,44,46,48,50)


Main:For B0 = 0 to 24 
  Read B0,B1      ' read data from EEPROM location b0 into bye variable b1   
  SerOut B.7,N2400,(#B1,cr,lf) 
Next B0
 

CDRIVE

Senior Member
so in other word you need to write data in address 0-63, page 261 manual 2. you may well be getting nothing as you havent stored anything there yet

try something like:

this will write data to the memort first before reading it back to you
@CDDrive,
Does the following code snippet halp you understand the use of EEPROM and the READ command
Yes gentlemen, both of your examples and explanations were very helpful. Far better than the Picaxe examples. I don't think the manual should have given an example like that without including the EEPROM or Write commands in their code.


Thank you very much.
 

Goeytex

Senior Member
I don't think the manual should have given an example like that without including the EEPROM or Write commands in their code.
Agreed. The manual has quite a few examples like that where the example depends upon other commands that are not included. Maybe some day Rev_Ed will take the time to review the examples and fix the ones that need fixing.
 

hippy

Technical Support
Staff member
Maybe some day Rev_Ed will take the time to review the examples and fix the ones that need fixing.
The examples have primarily been to simply demonstrate how a command can be used within a program, rather than to provide exhaustive examples of command use or be a tutorial for the commands. There's therefore some debate on what scope, context or complexity any examples should have but we do take into account users' comments.

We also have the online command references which can more easily have examples added where adding to the PDF manuals may cause an increase in their size and may even detract from their overall usefulness -

http://www.picaxe.com/BASIC-Commands

Everyone is welcome to submit examples there that would prove useful or clarify the use of any commands.
 
Top