Storing a word variable

pwaggie

New Member
OK maths is not my strong point :(

I am trying to store a word variable which indicates the finishing address of my data in eeprom, this is fine up to 255 but after that does not seem to work, here is the relevant code –

SYMBOL Addrs = w6
(lots of code)
hi2cout 0,(Addrs)

Later I wish to recover the address with
hi2cin 0,(Addrs)

But this only saves and returns the LSB, I could of course save b12 & b13 separately, but how do I then combine them into a word variable when I read them back, I’m sure there is a clever routine to do this but it is beyond my feeble capabilities at the moment.
Many thanks for any help
 

jtcurneal

Senior Member
w6 is made up of b13 and b12.
What works for me is.

for saving w6 hi2cout 0,(b12,b13)

for reading back hi2cin 0,(b12,b13)

Joel
 
Last edited:

SAborn

Senior Member
I think you need to use the word "WORD"

hi2cout 0,word (Addrs)

hi2cin 0,word (Addrs)

or as jtcurneal quoted.
 

pwaggie

New Member
Doesn't it make you feel stupid when the simplicity of a solution is pointed out, many many thanks to both SAborn & Joel. Now I can get back to programming :)

Peter
 

jtcurneal

Senior Member
As I understand it, when you are writing to or reading from the on chip EEPROM (the data memory) you can use WORD (address), but not when you are using an I2C EEPROM.

Joel
 

inglewoodpete

Senior Member
As I understand it, when you are writing to or reading from the on chip EEPROM (the data memory) you can use WORD (address), but not when you are using an I2C EEPROM.

Joel
I can confirm that the i2c protocol is for transmitting and receiving bytes. When a slave device has more that 256 locations to address, it will usually use word addressing. But it will still only send and receive bytes as data.

It would help minimise the confusion if people would read the manual first. Guessing a reply doesn't help either.
 

SAborn

Senior Member
Code:
Guessing a reply doesn't help either.
One just have to love excepting a cheap shot when someone comes back 8 hours later and comments on a problem!

It also helps to discourage others from offering advice.

If the reply indicates one is not sure but offers a possible solution, then i see nothing wrong, that requires a more knowledgeable member to comment on an attempt to help someone.
 

westaust55

Moderator
@pwaggie,

as jtcurneal has indicated, you need to break the word up into the constituent byte variables. IWP has also confirmed this.

From the PICAXE manual part 2:

HI2COUT location,(variable,...)
- Location is a variable/constant specifying a byte or word address.
- Variable(s) contains the data byte(s) to be written.
 

hippy

Ex-Staff (retired)
To extend on jtcurneal's solution, one can use SYMBOL commands to good effect to make the code more understandable ...

Symbol addrs = w6
Symbol addrs.lsb = b12
Symbol addrs.msb = b13

addrs = 12345
Hi2cOut 0, ( addrs.msb, addrs.lsb )
Pause 10
HI2cIn 0, ( addrs.msb, addrs.lsb )
SerTxd( #addrs, CR, LF )
 
Top