Getting Word data with hi2cout

Bayside888

Active member
First of all, thanks to Flenser and bpowell for their comments to help get this project started. It reads a pressure and a temp sensor and stores the data in regular intervals, then downloads to a terminal for storage when a button is pressed.

It works just right when storing to the internal PicAxe data locations, but that limits the amount of storage space. The read/write commands are shown below, commented out. So, now I amusing a 24LC128 EEprom with the hi2cout and hi2Cin commands. The circuitry works, because I get good data out when the variables are just byte-sized. However, I get large (65,000+/-) values when the data stored are larger than 255. This may be a very simple problem solved many times, but I can’t find the answer after diligently searching the forums. I believe I need to somehow combine the byte values to make a word, but? The problem is likely in the last couple of lines, but I have included the preceding code. Regards:
[CODE]
#PicAxe 28X2
hi2Csetup i2cmaster, %10100000, i2cfast, i2cword 'for 24LC128 EEprom.

Symbol holdvalue1 = W3
Symbol Temp_value = W5
Symbol sensorvalue = W7
Symbol counter = W8
Symbol dataAddr = W13 'holder to keep track of storage location


; ..
; .. get pressure value from sensor = sensorvalue then store in 24LC128

holdvalue1=dataAddr 'next data set number
; write dataAddr, word sensorvalue 'for saving to internal PicAxe eeprom
hi2cout dataAddr,(sensorvalue) 'save to external EEprom
dataAddr = DataAddr+2 'plus "2" for word variables
pause 5 'pause for serial EEprom, next steps take another 5 ms

; .. get temperature value from sensor = Temp_value then store in 24LC128

; write dataAddr, word holdvalue 'write word value of temperature toPicAxe
hi2cout dataAddr,(Temp_value) 'save to external EEprom
dataAddr = DataAddr+2 'plus "2" for word variables

; routine continues logging until user stops prgm

;------------------------------------------dump data to serial line-------------------------
; this portion downloads all data in EEprom to terminal when a button is pressed

Data_dump: 'Hi2cin is always a byte
sertxd("Button pressed",#dataADDr,cr,lf) 'shows location of last data

; 'dataAddr saved from above to find last data
dataAddr = dataAddr/4 'word variables use 2 locations
dataAddr = dataAddr-4 'adjust to read back correctly
holdvalue1=0 'start at first location

for counter = 0 to dataAddr 'count data sets (not locations)
; read holdvalue1, word sensorvalue
hi2cin holdvalue1, (b14,b15)
holdvalue2=holdvalue1+2
; read holdvalue1, word holdvalue1 ;for use with PicAxe internal EEprom
hi2cin holdvalue1, (b10,b11)
sertxd(#counter," Press=",#sensorvalue," Temp=",#Temp_value,cr,lf) 'send data
holdvalue1=holdvalue1+2

[SIZE=5] next[/SIZE]
 
Hi,

PICaxe Basic stores Word variables in a corresponding pair of Bytes, for example W3 is stored in B6 (Low byte) and B7 (High byte). For the READ and WRITE instructions (and also PEEK / POKE) the "WORD" qualifier instructs the complier to automatically replace (for example) W3 with B6 , B7 . However, for the HI2C... instructions the WORD qualifier is not supported, so the Program-Writer must make the substitution themselves. You appear to have done this correctly for the HI2CIN command (i.e. hi2cin holdvalue1, (b10,b11) so I think you just need to do the same for the HI2COUT command, i.e. hi2cout dataAddr,(Temp_value) should be replaced by HI2COUT dataAddr , ( B10 , B11 ) . Note that the dataAddr is treated as a Word value because of the i2cword parameter in the hi2Csetup ... instruction at the start of the program.

When using SYMBOLS, one convention is to define the separate bytes, for example, Symbol Temp_value.L = B10 and Symbol Temp_value.H = B11 , but sadly the compiler doesn't do this automatically and HI2COUT dataAddr , ( Temp_value.L , Temp_value.H ) is quite clumsy anyway. :(

EDIT: (Subsequent to post #3) : Yes indeed, thanks Pete. My only defence is that it was 2.54 AM here in UK. Now corrected in this post.

Cheers, Alan.
 
Last edited:
.... should be replaced by HI2COUT dataAddr , ( W10 , W11 ) . Note that the dataAddr is treated as a Word value because of the i2cword parameter in the hi2Csetup ... instruction at the start of the program.

Cheers, Alan.
Oo-er HI2COUT dataAddr , ( W10 , W11 ) A senior moment Alan? Surely you meant HI2COUT dataAddr , ( B10 , B11 )
 
I tend to ignore other people's senior moments much of the time. Perhaps because those seem more common in my writing since I passed 80? ;-)

I'm currently doing a read-it-as-a-first-timer read of all my published books and making pen & ink notes as I go through. That project is about a million words long so I have several months invested in it. I expect the actual correction sessions to go quickly because the process will be "find 'whatever', change to correction in notebook" and that's quick in Word when you have unique phrases to search for.

I suspect Alan would have picked it up the next time he read through this thread...
 
Hi,

PICaxe Basic stores Word variables in a corresponding pair of Bytes, for example W3 is stored in B6 (Low byte) and B7 (High byte). For the READ and WRITE instructions (and also PEEK / POKE) the "WORD" qualifier instructs the complier to automatically replace (for example) W3 with B6 , B7 . However, for the HI2C... instructions the WORD qualifier is not supported, so the Program-Writer must make the substitution themselves. You appear to have done this correctly for the HI2CIN command (i.e. hi2cin holdvalue1, (b10,b11) so I think you just need to do the same for the HI2COUT command, i.e. hi2cout dataAddr,(Temp_value) should be replaced by HI2COUT dataAddr , ( B10 , B11 ) . Note that the dataAddr is treated as a Word value because of the i2cword parameter in the hi2Csetup ... instruction at the start of the program.

When using SYMBOLS, one convention is to define the separate bytes, for example, Symbol Temp_value.L = B10 and Symbol Temp_value.H = B11 , but sadly the compiler doesn't do this automatically and HI2COUT dataAddr , ( Temp_value.L , Temp_value.H ) is quite clumsy anyway. :(

EDIT: (Subsequent to post #3) : Yes indeed, thanks Pete. My only defence is that it was 2.54 AM here in UK. Now corrected in this post.

Cheers, Alan.
Alan: works very well. Thanks for the late night help!
 
Let’s not talk about senior moments.
My memory is nowadays more volatile than dynamic RAM. A simple glitch and my brain data gets corrupted.
For instance, leaving the car keys inside the fridge.
 
"For instance, leaving the car keys inside the fridge." So far, I haven't done that but my better half locked her keys in the car once, last year. She's now much more careful to ensure those keys are in her pocket or purse BEFORE she exits the vehicle.

Being a senior citizen does have some benefits: most of us no longer deal with a zit on our nose the day of class pictures at school ;-)
 
Back
Top