TWI/I2C Protocol with HMC5883L Magnetometer with ATMEGA256RFR2 XPLAINED PRO (megaavr)

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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: The datasheet of ATMEGA256RFR2 can be found here.

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!