cancel
Showing results for 
Search instead for 
Did you mean: 

hts221 SPI driver

doug2399
Associate
Posted on June 05, 2016 at 03:20

hi, I'm using the HTS221 humidity and temperature sensor along with the STM32F205. They are connected over the SPI bus but I am unable to get the STM32F205's SPI communications working correctly. Can anyone recommend some known to work sample code for this combination of devices?

Thanks,

Doug Burrell

#hts221
1 REPLY 1
licciardello.anto
Associate II
Posted on June 15, 2016 at 10:35

Hi,

follows an SPI layer implementation example for STM32L1xx family.

First of all you have to download the HTS221 drivers from ST website:

https://my.st.com/content/my_st_com/en/products/embedded-software/mems-and-sensors-software/drivers-for-mems/stsw-memshtml#

1. In HTS221_Driver.h you have to remap the following functions used for I2C

#define HTS221_ReadReg(RegAddr, NumByteToRead, Data) HAL_ReadReg(HTS221_I2C_ADDRESS, RegAddr, NumByteToRead, Data)

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

With the following

#define HTS221_ReadReg(RegAddr, NumByteToRead, Data) HAL_ReadReg_SPI (RegAddr, NumByteToRead, Data)

#define HTS221_WriteReg(RegAddr, NumByteToWrite, Data) HAL_WriteReg_SPI( RegAddr, NumByteToWrite, Data)

2. The user must properly redefine the own HAL_ReadReg_SPI and HAL_WriteReg_SPI functions .

This implementation is linked to the hardware used and to the library used.

Attached a file .txt including an example for SPI functions based on STM32L1xx_Spi standard library.

You have to get this example and adapt it for STM32F205 library.

3. The user must properly initialize GPIO according the hw used-> configure 3-wire SPI serial data input /output (SDI/SDO),CLK and CHIP Select

4. The user must properly initialize the SPI interface according the hw used -> In .txt file you can find an example: see HAL_Init_SPI() function

Summarizing the steps are listed below:

1. Initialize GPIO (hw based)

2. Initialize SPI (hw based)

3. Remap functions in HTS221_Driver.h , including file own HAL_Implementation.h file.

4. In OWN HAL_Implementation.c ,the user must write the source code for HAL_ReadReg_SPI and HAL_WriteReg_SPI (Along the lines of the example reported in .txt file)

Regards

Antonella

________________

Attachments :

Example_SPI_STM32L1xx.txt : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzKW&d=%2Fa%2F0X0000000bJv%2Fa_x0iJBry6FEt0zbYZPmLwJlXsAF5P.rfT.5e5at_ac&asPdf=false