Addressing MAG3110 on FRDM-KL46Z using I2C

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Addressing MAG3110 on FRDM-KL46Z using I2C

2,127 Views
amanjain
Contributor I

Hi,

I'm trying to use I2C to capture data from MAG3110 to get magnetometer readings.

What should be the ideal baud rate for the device?(As I cannot see where we set the baud rate

in MAG3110).

What is the default bus clock in the microcontroller.

0 Kudos
Reply
7 Replies

1,495 Views
Stano
NXP Employee
NXP Employee

Hi Aman,

I suggest you to remap I2C0 bus pins from pins PTE24/25 to I2C1 bus pins PTC1/2 and write and debug "Reset I2C" routine by scope. When finished remap pins back to I2C0 and use it. The I2C1 pins are available on the board header.

Best Regards,

Stano.

0 Kudos
Reply

1,495 Views
Stano
NXP Employee
NXP Employee

Hi Arman,

When this kind of issue on the I2C bus occurs, the good way to solve it is to generate "I2C bus reset". Then all I2C slaves on bus will receive messages properly. The I2C bus reset must be generated by master by GPIO pins. Just switch I2C pins to GPIO mode and generate START bit (event), then SDA=0 and 9 SCL pulses and the STOP bit (event). After this command switch I2C pins back to I2C mode and use I2C bus standard way.

The reason why the slave not answers properly could be caused by such incorrect state of I2C peripheral after power up. The "I2C Reset" helped me many times to solve this issue with many different I2C slaves.

I think it will help you.

Best Regards,

Stano.

0 Kudos
Reply

1,495 Views
amanjain
Contributor I

Unfortunately, the pins that the SCL and SDA lines of MAG3110 are connected (PTE24 AND PTE25 respectively) are not available to me for connection on the board externally(see PIN map attached). Thus, I'm not able to give the required sequence on the pins or use the logic analyzer. Any workaround to the issue?

FRDMKL46Z-PIN MAP ADDITIONAL.jpgFRDMKL46Z-PIN MAP.png

0 Kudos
Reply

1,495 Views
amanjain
Contributor I

When I send the device address on the I2C bus after a start, I should get an acknowledge signal on the bus, but I do not receive any acknowledge signal. I am using the device address for MAG3110 as 0x0E. Assuming the bus clock as 24MHz, baud is set to 100kHz. The RXAK bit in Status register of I2C0 is always set when I read it(It should be cleared when I2C receives an acknowledge signal).

Attaching my code for I2C setup as well.

Timing diagram for i2c.JPG

0 Kudos
Reply

1,495 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Aman Jain,

      MAG3110 is just the I2C slave device, it just receive the baud, if the I2C baud is under the max baud, the MAG3110 hardware can receive, you don't need to care it, just keep the master I2C baud at the I2C baud range which MAG32110 can receive.

  About the communication is failed,  MAG3110 is NACK, please use the logic analyzer to capture the I2C wave, whether it is correct, whether the Address is sent correct.

  After you capture it , please give me some pictures!


Have a great day,

Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

1,495 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Aman Jain,

      From the MAG3110 datasheet, you will get that the max I2C baud is 400Khz:

31.jpg

32.jpg

400Khz is the max baudrate, you can use the lower baudrate, eg,10Khz, 50khz, 100khz. etc.

About the bus clock in the microcontroller, it is determined by the system clock which you are configure.

If you don't configure it, and just use the internal slow IRC 32.768khz, the bus clock is 20.97152Mhz.

Wish it helps you!

If you still have question, please contact with me!


Have a great day,
Jingjing

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply

1,495 Views
amanjain
Contributor I

I understand that the maximum baudrate is 400kHz and it is set when FR bit is set. But when that is not the case, how does the MAG3110 know the baudrate I am operating on? Or is that something it learns from the SCL line?

0 Kudos
Reply