Infineon / TLV493D-A1B6-3DMagnetic-Sensor

Library for the TLV493D-A1B6 3D magnetic sensor for Arduino.
MIT License
39 stars 27 forks source link

How to init using 400kHz clock rate? #17

Closed gwideman closed 1 year ago

gwideman commented 4 years ago

I see that the library has a setAccessMode that can switch between various modes, including FASTMODE (1MHz with special clock handling). But how do you set plain old 400kHz clock rate, and switch between that and even-plainer 100kHz mode?

As a part of this, I would note that considerable confusion is introduced by this library using the enum label "FASTMODE" to refer to the 1MHz clock-rate mode (and having some additional requirements). The I2C user-guide specifies:

The most egregious problem is that the library FASTMODE doesn't match the I2C standard "Fast-mode".

Beyond that, it's not clear to me how the mode of TLV493D that's invoked by the library "FASTMODE" does or doesn't correspond to I2C "Fast-mode Plus".

9Volts9er commented 3 years ago

You are right, that the naming can be confusing. I had a look into the Datasheet and the User Manual to solve the mystery.

What is configurable in the sensor is actually the sampling rate. The higher the sampling rate, the more current consumption is to expect. Fastmode of the sensor means 3.3 kHz sampling rate, that's as fast as the sensor can get, so that explains the naming.

What you need to know is that the communication speed is totally decoupled from the sensors sampling rate. You can communicate with the sensor in I²C fast mode plus (if you make sure the capacities are low enough) even in it's lowest sampling rate. Or you can read in I²C standard mode (100 kbit/s) while the sensor is in fast mode (3.3 kHz sampling rate). The only problem in the last case - and that's why it's recommended to use the fast mode plus for communication here: the sensor is sampling continuously and will overwrite the data if it's not read in the meantime. So the microcontroller will miss data if the readout takes longer than one sampling cycle.

And now to finally answer your question about how to set the I²C clock rate: Unfortunately as I see it there is no function for that in the TLV493D-A1B6 library. But you can use the standard Arduino Wire library for that. Simply include Wire.h in your Arduino sketch. Then after you've called the begin() of the 3D-Library in the setup, which itself calls the Wire.begin(), you can use the Wire.SetClock() function. That should work...