cancel
Showing results for 
Search instead for 
Did you mean: 

HTS221 driver integration for imx6

quentin duhamel
Associate II
Posted on June 21, 2017 at 12:34

Hi,

I'm having trouble with HTS221 device driver integration (for a FreeRTOS app). ST provides a platform independent driver (see

http://www.st.com/en/mems-and-sensors/hts221.html

 ). But those drivers have functions which need to be remapped :

         // the user must redefine the proper HTS221_WriteReg

         #define HTS221_WriteReg(RegAddr, NumByteToWrite, Data)  HAL_WriteReg(HTS221_I2C_ADDRESS, RegAddr,      NumByteToWrite, Data)

I want to use this driver with I2C but I don't find how, since I'm not use to play with drivers.

Did someone already do this ? Or use another similary driver with an imx6 board ?

QD

4 REPLIES 4
Legacy member
Not applicable
Posted on June 21, 2017 at 13:36

Hello,

I haven't used these drivers, but I have written my own and I think I can provide you a brief description, what is this about.

The driver itself (.c file) and its header file (.h file) provide the sensor functionality and necessary function etc. declarations. However, in order to be platform independent, a

https://en.wikipedia.org/wiki/Hardware_abstraction

is used. All the code provided by ST is generally working without using any code accessing a specific hardware. That is the only way it can remain platform independent. Since HTS221 is an I2C / SPI sensor, it assumes the programmer will just write (define) the functions you mentioned above.

So, your job is to write the code for the system specific part (this means suited to your RTOS and HW). You need to find a documentation to your RTOS (and probably also your micro-controller and learn), how the I2C bus (if this is the bus you want to use) is initialized and used. If you are familiar with I2C already, the only thing to implement are methods to start the I2C in master mode, method to write registers (with parametrised count of them) at some device's address and a method to read registers (again, with parametrised count of them) from some device's address.

David

Posted on June 21, 2017 at 15:02

Thanks for answering. I see clearly the stuff I have to do, but I don't find any example helping me to develop the expected function. I've just found the API reference manual for the freertos BSP of i.MX6SoloX :0690X00000607RNQAY.png0690X00000607L7QAI.png

Legacy member
Not applicable
Posted on June 21, 2017 at 16:55

That is a good step!

As I wrote above, I would focus on three things:

1) I2C initialization: that is exactly what you pasted in the reference manual in section 9.2.2

2) Read multiple bytes: that is just about writing a cycle to send more bytes via I2C_ReadByte as stated in section 9.2.3

3) Write multiple bytes: the same as for 2) using I2C_WriteByte

If you struggle with the FreeRTOS, try to ask for help on FreeRTOS forum. If you struggle with the i.MX device, try to ask on

https://community.nxp.com/

. You would have to be quite lucky to find a help here, since your question roots are not in the sensor itself...
Posted on June 21, 2017 at 17:38

Thanks David, I'll focus on the indications you gave me ! Hope it will work !