Wierd variable problem

trinity

New Member
Hi, I'm writing code to stash variables in a modified 18x datalogger. The sample prog below counts up b12 and b13 so that they are clearly different, then sticks them into a pair of 512's. The LCD shows the number I expect but when I pull them out again the B12 is the same as B13?? What's going on??

init:
pause 1000
serout 6,N2400,(254,1)
let w2=20 ' change w2 value for number of readings
read 0,b2
read 1,b3
b13=0
b12=0

readD:
'readadc 1,b0
'readtemp 2,b1
pause 300
serout 6,N2400,(254,1,128,"P: ",#b12," ","T: ",#b13,254,192,"Adrs:",#w1,"/",#w2)

write1:
i2cslave %10100000, i2cfast, i2cword
writei2c w1,(b12)
pause 10
i2cslave %10100001, i2cfast, i2cword
writei2c w1,(b13)

inc:
pause 50
let w1=w1+1
write 0,b2
write 1,b3
if w1=w2 then full
b12 = b12+2
b13=b13+b12
goto readD

full:
high 2

datalink:

serout 6,N2400,(254,1,128,"Waiting for G")
serin 6, N4800,("G")
let w1=0
serout 6,N2400,(254,1,"Transfer...")
serout 7,N4800,("Address",44,"Amps",44,"Temp"," ",13,10)

read_data:

i2cslave %10100000, i2cfast, i2cword
readi2c w1,(b12)
pause 10
i2cslave %10100001, i2cfast, i2cword
readi2c w1,(b13)
pause 10

tx_data:
serout 7,N4800,(#w1,44,#b12,44,#b13,13,10)
let w1=w1+1
if w1=w2 then all_done
goto read_data

all_done:
low 2
serout 6,N2400,(254,1,128,"All done!")
serout 7,N4800,(0)
let w1=0
write 0,b2
write 0,b3
wait 5
end
Thanks for any suggestions.....

 

trinity

New Member
It looks like the address lines are all shifted right one place. Using the address 0010 for the second chip seems to work fine.
 

hippy

Technical Support
Staff member
Have a more detailed read of the I2C tutorial ( axe110_i2c.pdf ). The least-significant bit of the I2C Device Address is irrelevant, so ...

- i2cslave %10100000, i2cfast, i2cword
- readi2c w1,(b12)
- i2cslave %10100001, i2cfast, i2cword
- readi2c w1,(b13)

will both read from the same location. The same applies when writing.

Edited by - hippy on 31/05/2006 22:04:43
 

whizzer

Senior Member
Good point Hippy.
And the Manual could have explained this better also. It may have been a case of wanting to keep the explanation simple for beginners, but in the process caused a lack of clarity. On page 3 (of Axe110_i2c.pdf), the manual states that:

<i>&#8220;The slave address is generally 7 bits long, with the 8th bit reserved to indicate whether the master wishes to write (1) or read (0) from the slave.&#8221; </i>

At first glance, this might seem to be suggesting that the eighth bit (actually bit 7 since bits are counted b0 to b7), might be the one that signals whether I2C is doing a read or write operation. But in fact, it&#8217;s the <i>Least Significant Bit </i> (bit 0) that is used for this purpose.

(And of course it&#8217;s the readi2c &amp; writei2c commands themselves which actually control the state of bit 0 ).

Perhaps the manual should have stated something like this:

&#8220;The slave address is generally 7 bits long. The first bit (bit 0) is always reserved to indicate whether the master wishes to write (1) or read (0) from the slave, while the remaining bits form the actual address.&#8221;
 

womai

Senior Member
Yeah, I got bitten by that &quot;simplified&quot; explanation, too, and thought that the read/write bit is the most significant. Of course reading the original I2C interface spec cleared that up, but who reads that monster before trying and failing?

I'd recommend to RevEd to reword it to &quot;the least significant bit&quot;, and even better, give an example, like &quot;if you want to write to slave address 7, i.e. %0000111, then the parameter for i2cslave must be %00001110 - in other words, just add a 0 to the binary slave address&quot;.

Just my 2 cents

Wolfgang

Edited by - womai on 01/06/2006 07:21:24
 

Dippy

Moderator
Yes, it can be confusing. I assume 'a pair of 512s' means a couple of the normal 24LC512s?

I can HUGELY recommend that people read the EEPROM data sheet as well - rather than cut/paste from PICAXE manual.

Then Trinity would see that the format is:
%1010 A2 A1 A0 x . Where the A2,1,0 pins are wired to V+ or Gnd.
Trinity said a pair of i2C but didn't mention how A2 A1 A0 were electrically connected. As your code line works in conjunction with the hard wiring.

P.S. Its a well-written and brief data sheet.

Edited by - Dippy on 01/06/2006 10:00:38
 

hippy

Technical Support
Staff member
Thanks for pointing out the confusion in the manual - I'm so used to ambiguity etc in datasheets that I often read what it is meant to say, not what what it actually does !

I agree, 1st..8th and and similar descriptions are confusing, most significant and left-most are better terms, but simply saying 'Bit N' should be clearer.

Whizzer : Note that bit 0 is the right-most, least-significant bit for the PICAXE and nearly every other use ( but there are a few rare exceptions ).
 

whizzer

Senior Member
Is there some sort of weird planetary alignment that is causing human miscommunication across the planet today?

From Hippy
<i>Whizzer : Note that bit 0 is the right-most, least-significant bit for the PICAXE and nearly every other use&#8230; </i>

Reply to Hippy from Whizzer:
But I thought that that was what I was trying to say!
i.e. right-most is the least significant digit. No difference to decimal there!
Is there really anyone who would think otherwise?

From Dippy:
<i>I can HUGELY recommend that people read the EEPROM data sheet as well - rather than cut/paste from PICAXE manual. </i>

Comment to Dippy:
Re your: <i>&#8220;&#8230;rather than cut/paste from PICAXE manual.&#8221; </i>
WHAT&#8230;?? After all this time admonishing people for not reading the Picaxe manuals, are you now saying they shouldn&#8217;t be trusted?

mmmm Must be the planets! :)
 

hippy

Technical Support
Staff member
You confused me with &quot;Perhaps the manual should have stated something like this: The slave address is generally 7 bits long. The first bit (bit 0) ...&quot; where to me, bit 0 is the last bit when read ( to the right ) and when sent as an address on the I2C bus.
 

Dippy

Moderator
Doh! Me admonish? I was really suggesting that a bit of inward-digestion is a good idea. I wasn't criticizing the Manuals though I reckon a bit of extra explanation in areas might help.
I know I have a data sheet fettish ... I'm trying to get help.
 

whizzer

Senior Member
Hi to Hippy &amp; to Dippy.
phew! Glad that&#8217;s all sorted out then! :)
It&#8217;s amazing how little misunderstandings can creep in when trying to be make postings as brief as possible.

To all: Dippy&#8217;s advice about reading the specific product data sheets (in addition to the Picaxe manuals), can be time very well spent for anyone starting out on a new project. And of all the fetishes known to humankind, a data-sheet fetish is really not a bad one to have!

To Trinity: Dippy&#8217;s further advice about making the two memory chips be able to be seen as two <i>separate </i> addresses on the I2C bus (by wiring the hardware address-pins appropriately) is essential for the two devices to operate correctly side by side. Hope that you remembered to do that.

Regards to all

Edited by - whizzer on 02/06/2006 06:21:58
 
Top