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. The two pictures after come from the imx6 freertos bsp.
Did someone already do this ? Or use another similary driver with an imx6 board ?
QD
Hi Quentin
seems it is necessary to write own HTS221_WriteReg(RegAddr, NumByteToWrite, Data)
function using examples in i.MX FreeRTOS, actually sect.9.2.3 describes necessary steps for it.
For simplicity one can start with NumByteToWrite=1 and use examples in
FreeRTOS/imx6sx_sdb_m4/driver_examples/i2c_imx/i2c_polling_sensor
Best regards
igor
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
I've also tried to start with i2c_polling_sensor example from free rtos. But it seems I can't access to my device; I'm wondering if the error come from freertos, or if I have to change something on the kernel configuration of the board. Indeed, if the i2c driver is for instance taken by the A9 core, the M4 can't have it.
Has no one ever attempted such a thing ? (adding an i2c device to the imx6solox eval board, handled by free rtos on the m4 core).
one can check how i2c module is configured by
Resource Domain Controller (RDC), described in Chapter 52
i.MX6SX Reference Manual.
~igor
Thanks you igorpadykov for answering.
Yes, I understood I had to use the 9.2.3 section. Yet, it seems to me that we need an extra parameter, to specify the i2c bus adress. Hereafter is the function I wrote, wich is not compatible with the HTS221_ReadReg macro used in the ST driver. How can I do to avoid this extra parameter ? Using global variable ?
HTS221_Error_et IMX_HTS221_ReadReg(I2C_Type* base, uint8_t RegAddr, uint16_t NumByteToRead, uint8_t* Data) {
/*
Following instructions of FreeRTOS_BSP_i.MX6SoloX_API_Reference_Manual.pdf
*/
uint8_t writeBytes[2];
HTS221_Error_et status = HTS221_OK;
/* Clear I2C interrupt flag to avoid spurious interrupt */
I2C_ClearStatusFlag(base, i2cStatusInterrupt);
/* setting RX mode */
I2C_SetDirMode(base, i2cDirectionReceive);
// setting master mode to send start signal
I2C_SetWorkMode(base,i2cModeMaster);
/* Change to receive state. */
I2C_SetDirMode(base, i2cDirectionReceive);
*Data = I2C_ReadByte(base);
// Will be modified later :
return(true);
}