[Tinyos-help] [FIXED] Magnetometer gain problem with IRIS and MTS310 - (I2C problem)
raphael.polonowski at free.fr
raphael.polonowski at free.fr
Fri Aug 29 07:23:06 PDT 2008
Hi all,
I asked for help a while ago about the I2C problem for IRIS + MTS310 board when
adjusting the magnetometer gain with the AD5242 component :
http://www.mail-archive.com/tinyos-help@millennium.berkeley.edu/msg22159.html
I fixed it a month ago but didn't find the time since then to post on the
mailing.
So first of all, I found this post which helped me a little :
http://mail.millennium.berkeley.edu/pipermail/tinyos-help/2007-January/021749.html
But instead of changing the code directly in "HplAtm128I2CBusP.nc", I prefer
changing the argument of the init call in "Atm128I2CMasterPacketP.nc" in the
function "AsyncStdControl.start()" :
I changed
>> call I2C.init(FALSE)
to
>> call I2C.init(TRUE)
After this, the I2C bus was truly enabled, so I thought the problem was fixed,
but I was wrong : the gainAdjustX or Y function had no effect at all. So I
decided to build a logic analyzer like this one :
http://www.xs4all.nl/~jwasys/old/diy2.html
It work wonderfully.
I started by sending known characters on the bus, like 0xAA55 :
http://img297.imageshack.us/img297/1624/0xaa55writeenvt2.jpg
I looked at the AD5242 datasheet and I recognized the adress of the compoment in
the first byte, but it was shifted left of 1 bit (the grey rectangles shows
that). So the adress is obviously wrong, and that explains why the component
never acknowledge ("A" bit should be 0 if the component had acknowledge). The
reason : this line in "Atm128I2CMasterPacketP.nc" (again !) :
>> call I2C.write(((packetAddr & 0x7f) << 1) | ATM128_I2C_SLA_WRITE);
I replaced it by
>> call I2C.write( packetAddr | ATM128_I2C_SLA_WRITE );
And I retried with 0x00AA ... and it's working now ! :
http://img398.imageshack.us/img398/4330/0x00aawriteokenqz1.jpg
Every "A" bit was acknowledged... So I tried some gain values with gainAdjustY()
and the magnetometer signal was finally visible. Once again I thought it was OK,
but there was one more problem, I couldn't get the X axis working, with
gainAdjustX().
This last problem was about the subadress of the AD5242, in "MagP.nc", in the
function "Mag.gainAdjustX(uint8_t val)" :
Instead of
>> gainData[0] = 0x01;
you must put
>> gainData[0] = 0x80;
the subadress bit is the MSB, referring to the datasheet...
And then, I had my two-axis magnetometer working perfectly. I developped a
simple dichotomy algorithm to center the signals, and it's working very well,
taking only 5 steps to center them.
Voilà ! I don't know if some TinyOS developpers agrees with what I did, but if
they do, maybe they can change the sources.
Anyway, I hope it will help for other people in the same situation.
Thanks again Miklos for trying to help me with my previous posts.
Raphael Polonowski
PS : sorry for my poor english
More information about the Tinyos-help
mailing list