完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
在定制板上使用STM32L4 MCU初始化SPI 3线接口后,无论何时调用获取压力方法,驱动器始终返回零作为压力值。即使温度传感器读数也作为输出返回零。这是初始化错误还是校准错误?
#stm32l4-spi#lps22hb 以上来自于谷歌翻译 以下为原文 After initializing an SPI 3-wire interface with a STM32L4 MCU on a custom board, the driver always returns zero as the pressure value whenever the get pressure method is called. Even the temperature sensor reading is also returning zero as output. Is this an initialization error or calibration error? #stm32l4-spi #lps22hb |
|
相关推荐
4个回答
|
|
你好,
您是否有逻辑分析仪来验证您是否将数据发送到传感器并正确地恢复数据? 您是否已开始在传感器中进行测量? 你能分享你的代码吗? 大卫 以上来自于谷歌翻译 以下为原文 Hello, Do you have a logic analyzer to verify you send the data to the sensor and get the data back correctly? Have you started the measurement in the sensor? Could you share your code? David |
|
|
|
嗨大卫,
我没有逻辑分析仪来验证数据。我从en.x-cube-mems1扩展包中移植了代码。传感器在3线SPI模式下初始化。初始化和传感器测量的伪代码如下 BSP_PRESSURE_Init(PRESSURE_SENSORS_AUTO,& PRESSURE_handle); BSP_PRESSURE_Sensor_Enable(PRESSURE_handle); if(BSP_PRESSURE_IsEnabled(PRESSURE_handle,& status)== COMPONENT_OK&& status == 1) {BSP_PRESSURE_Get_Press(PRESSURE_handle,& PRESSURE_Value); } 以上来自于谷歌翻译 以下为原文 Hi David, I don't have a logic analyzer to verify the data. I ported the code from en.x-cube-mems1 expansion package. The sensor is initialized in the 3-wire SPI mode. The pseudo code for initialization and sensor measurement is below BSP_PRESSURE_Init( PRESSURE_SENSORS_AUTO, &PRESSURE_handle ); BSP_PRESSURE_Sensor_Enable(PRESSURE_handle); if(BSP_PRESSURE_IsEnabled(PRESSURE_handle, &status) == COMPONENT_OK && status == 1) { BSP_PRESSURE_Get_Press(PRESSURE_handle, &PRESSURE_Value); } |
|
|
|
我想问题是你的微控制器的SPI 3线设置不在传感器中,在范围或逻辑分析仪上调试可能很棘手且难以调试。
我建议你仔细检查你的SPI配置,或者更确切地说是在第一次使用I2C。 以上来自于谷歌翻译 以下为原文 I suppose the problem is in the SPI 3-wire settings of you microcontroller not in the sensor, it can be tricky and difficult to debug witnout scope or logic analyzer. I would recomend you to double check your SPI configuration or rather use I2C at firts. |
|
|
|
这是我的SPI配置
SENSORTILE_SENSORS_SPI_CLK_ENABLE(); SENSORTILE_SENSORS_SPI_GPIO_CLK_ENABLE(); GPIO_InitStruct.Pin = SENSORTILE_SENSORS_SPI_MOSI_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; HAL_GPIO_Init(SENSORTILE_SENSORS_SPI_Port,& GPIO_InitStruct); GPIO_InitStruct.Pin = SENSORTILE_SENSORS_SPI_SCK_Pin; GPIO_InitStruct.Pull = GPIO_PULLUP; HAL_GPIO_Init(SENSORTILE_SENSORS_SPI_Port,& GPIO_InitStruct); SPI_Sensor_Handle.Instance = SENSORTILE_SENSORS_SPI; SPI_Sensor_Handle.Init.Mode = SPI_MODE_MASTER; SPI_Sensor_Handle.Init.Direction = SPI_DIRECTION_1LINE; SPI_Sensor_Handle.Init.DataSize = SPI_DATASIZE_8BIT; SPI_Sensor_Handle.Init.CLKPolarity = SPI_POLARITY_HIGH; SPI_Sensor_Handle.Init.CLKPhase = SPI_PHASE_2EDGE; SPI_Sensor_Handle.Init.NSS = SPI_NSS_SOFT; // SPI_Sensor_Handle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; // 5 MHz SPI_Sensor_Handle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; // 2.5MHz SPI_Sensor_Handle.Init.FirstBit = SPI_FIRSTBIT_MSB; SPI_Sensor_Handle.Init.TIMode = SPI_TIMODE_DISABLED; SPI_Sensor_Handle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED; SPI_Sensor_Handle.Init.CRCPolynomial = 7; SPI_Sensor_Handle.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; SPI_Sensor_Handle.Init.NSSPMode = SPI_NSS_PULSE_DISABLED; HAL_SPI_Init(安培; SPI_Sensor_Handle); SPI_1LINE_TX(安培; SPI_Sensor_Handle); __HAL_SPI_ENABLE(& SPI_Sensor_Handle);所有定义都已更改,以反映我的自定义板上的正确引脚。这是否初始化了 MCU的SPI 3线设置是否正确? 以上来自于谷歌翻译 以下为原文 This is my SPI configuration SENSORTILE_SENSORS_SPI_CLK_ENABLE(); SENSORTILE_SENSORS_SPI_GPIO_CLK_ENABLE(); GPIO_InitStruct.Pin = SENSORTILE_SENSORS_SPI_MOSI_Pin; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_HIGH; GPIO_InitStruct.Alternate = GPIO_AF5_SPI2; HAL_GPIO_Init(SENSORTILE_SENSORS_SPI_Port, &GPIO_InitStruct); GPIO_InitStruct.Pin = SENSORTILE_SENSORS_SPI_SCK_Pin; GPIO_InitStruct.Pull = GPIO_PULLUP; HAL_GPIO_Init(SENSORTILE_SENSORS_SPI_Port, &GPIO_InitStruct); SPI_Sensor_Handle.Instance = SENSORTILE_SENSORS_SPI; SPI_Sensor_Handle.Init.Mode = SPI_MODE_MASTER; SPI_Sensor_Handle.Init.Direction = SPI_DIRECTION_1LINE; SPI_Sensor_Handle.Init.DataSize = SPI_DATASIZE_8BIT; SPI_Sensor_Handle.Init.CLKPolarity = SPI_POLARITY_HIGH; SPI_Sensor_Handle.Init.CLKPhase = SPI_PHASE_2EDGE; SPI_Sensor_Handle.Init.NSS = SPI_NSS_SOFT; // SPI_Sensor_Handle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16; // 5 MHz SPI_Sensor_Handle.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; // 2.5MHz SPI_Sensor_Handle.Init.FirstBit = SPI_FIRSTBIT_MSB; SPI_Sensor_Handle.Init.TIMode = SPI_TIMODE_DISABLED; SPI_Sensor_Handle.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED; SPI_Sensor_Handle.Init.CRCPolynomial = 7; SPI_Sensor_Handle.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE; SPI_Sensor_Handle.Init.NSSPMode = SPI_NSS_PULSE_DISABLED; HAL_SPI_Init(&SPI_Sensor_Handle); SPI_1LINE_TX(&SPI_Sensor_Handle); __HAL_SPI_ENABLE(&SPI_Sensor_Handle);all the defines have been changed to reflect the correct pins on my custom board. Does this initialize the SPI 3-wire settings of the MCU correctly ? |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2655 浏览 1 评论
3216 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1790 浏览 1 评论
3619 浏览 6 评论
5997 浏览 21 评论
946浏览 4评论
1319浏览 4评论
在Linux上安装Atollic TRUEStudio的步骤有哪些呢?
591浏览 3评论
使用DMA激活某些外设会以导致外设无法工作的方式生成代码是怎么回事
1309浏览 3评论
1369浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-30 00:13 , Processed in 1.385946 second(s), Total 84, Slave 68 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号