ST意法半导体
直播中

孙琪

7年用户 167经验值
私信 关注
[问答]

无法使STM32F205的SPI通信正常工作

嗨,我正在使用HTS221湿度和温度传感器以及STM32F205。它们通过SPI总线连接,但我无法使STM32F205的SPI通信正常工作。任何人都可以推荐一些已知可以为这种设备组合工作的示例代码吗?


谢谢,
道格伯瑞尔
#hts221

以上来自于谷歌翻译


以下为原文




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)

李代三

2018-11-14 17:26:52
嗨,
 
遵循STM32L1xx系列的SPI层实现示例。
 
首先,您必须从ST网站下载HTS221驱动程序:
 
 
https://my.st.com/content/my_st_com/en/products/embedded-software/mems-and-sensors-software/drivers-for-mems/stsw-mems035.html#
 
 
1.在HTS221_Driver.h中,您必须重新映射以下用于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)
 
 
有以下几点
#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.用户必须正确地重新定义自己的HAL_ReadReg_SPI和HAL_WriteReg_SPI函数。
 
 
此实现链接到使用的硬件和使用的库。
附加了一个文件.txt,其中包含一个基于STM32L1xx_Spi标准库的SPI函数示例。
您必须获得此示例并将其调整为STM32F205库。
 
 
3.用户必须根据所使用的hw正确初始化GPIO->配置3线SPI串行数据输入/输出(SDI / SDO),CLK和CHIP选择
 
 
4.用户必须根据使用的hw正确初始化SPI接口 - >在.txt文件中,您可以找到一个示例:请参阅HAL_Init_SPI()函数
 
总结步骤如下:
 
 
1.初始化GPIO(基于hw)
2.初始化SPI(基于hw)
3.重新映射HTS221_Driver.h中的函数,包括文件自己的HAL_Implementation.h文件。
4.在OWN HAL_Implementation.c中,用户必须编写HAL_ReadReg_SPI和HAL_WriteReg_SPI的源代码(沿.txt文件中报告的示例行)
 
问候
安东内拉

以上来自于谷歌翻译


以下为原文







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-mems035.html#


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
举报

更多回帖

发帖
×
20
完善资料,
赚取积分