1
\$\begingroup\$

Im trying to read Data Output Registers of X,Y,Z

So far I've been able to:

Send a START - flag 0x08 = START condition transmitted.
Send 0x3C - flag 0x18 = SLA+W transmitted, ACK received.
//For configuring HMC5883L Control Register A & B
Send 0x02 data byte - flag 0x28 = Data byte transmitted, ACK received.
Send 0x00 data byte - flag 0x28 = Data byte transmitted, Ack Received.
Send a Repeat Start - flag 0x10 = Repeat Start condition transmitted.
Send 0x3D - flag 0x40 = SLA+R transmitted, ACK received.

Start > SLA+W > Configure Control Register A & B > Repeat Start > SLA+R > ??

I'm stuck on what to do after sending a SLA+R, I've tried sending a 0x03 (MSB register for Output X). I keep getting a repeated fixed value like (0,10,10,18 - repeat).

My main question would be how do I correctly read the memory address of the slave at 0x03 followed by 0x04, 0x05, 0x06, 0x07, 0x08 successfully?

In the data sheet it is mentioned:

When one or more of the output registers are read, new data cannot be placed in any of the output data registers until all six data output registers are read.

To minimize the communication between the master and this device, the address pointer updated automatically without master intervention. The register pointer will be incremented by 1 automatically after the current register has been read successfully.

The address pointer value itself cannot be read via the I2C bus. Any attempt to read an invalid address location returns 0’s, and any write to an invalid address location or an undefined bit within a valid address location is ignored by this device.

To move the address pointer to a random register location, first issue a “write” to that register location with no data byte following the commend. For example, to move the address pointer to register 10, send 0x3C 0x0A.

Any help would be appreciated, thanks in advance!

\$\endgroup\$
0
\$\begingroup\$

To move the address pointer to a random register location, first issue a “write” to that register location with no data byte following the commend. For example, to move the address pointer to register 10, send 0x3C 0x0A

So, to read from register 0x03 on, try:

Start > SLA+W > 0x03 > Repeat Start > SLA+R > read 6x

(Notice the W in the first SLA+W.)

| improve this answer | |
\$\endgroup\$
0
\$\begingroup\$

Ive actually solved the issue, but another weird issue is: when I write to 0x03 (to set the pointer), I'm not exactly sure wheres the pointer, but it reads 0x04 instead. To fix it, I started from 0x02, they it worked perfectly. I verified this by reading ID register A,B,C. Reading the first ID at 0x0A gave me a '4' when I was supposed to get a 'H'. So to rectify this, i actually started reading from 0x09, then it gave me a 'H', '4', '3'.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Note that you must not actually write any data. Just write one byte -the register number- and then switch to reading. \$\endgroup\$ – JimmyB Jul 8 '16 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.