STM32 HAL I2C库读指定寄存器的数据
来源:互联网 发布:北京好吃的餐厅知乎 编辑:程序博客网 时间:2024/06/05 08:07
Support for "repeated start" in STM32 HAL I2C library
Q:
I am working with a slave I2C device (Kionix KX022 acccelerometer) which uses a "repeated start" mechanism to send data requested by the master (STM32F405), e.g. to read two bytes of data (from register N and register N+1) the following sequence
Master Slave
--------------------- ------------------------
START
Slave Address + Write
ACK
N (starting register)
ACK
START (repeat)
Slave Address + Read
ACK
Data
ACK
Data
NACK
STOP
It appears the STM32F4xx HAL I2C library does not support this directly, since HAL_I2C_Master_Transmit() sends STOP after the data.
I just want to confirm this before writing some code (i.e. gluing together the HAL_I2C_Master_Transmit() and HAL_I2C_Master_Recieve() functions and removing the intervening STOP).
Thanks in advance,
Mike
Master Slave
--------------------- ------------------------
START
Slave Address + Write
ACK
N (starting register)
ACK
START (repeat)
Slave Address + Read
ACK
Data
ACK
Data
NACK
STOP
It appears the STM32F4xx HAL I2C library does not support this directly, since HAL_I2C_Master_Transmit() sends STOP after the data.
I just want to confirm this before writing some code (i.e. gluing together the HAL_I2C_Master_Transmit() and HAL_I2C_Master_Recieve() functions and removing the intervening STOP).
Thanks in advance,
Mike
A:
Hi Mike,
Regarding your needs, it seems that your I2C slave device have a comportment like a EEPROM memory. For this prefer to use HAL_I2C_Mem_Write or HAL_I2C_Mem_Read interface.
To give you more explanation about functionality of this interface :
1- First step of this interface is to send this sequence => START + Slave addr + R/W bit + ACK + Regvalue to write or read + ACK
2- Second step of this interface is to send this sequence => Repeated Start + Slave addr + R/W bit + ACK + DataValue to write or read on RegValue + ACK ….+ STOP
Hope that help,
Best regards,
Heisenberg.
Regarding your needs, it seems that your I2C slave device have a comportment like a EEPROM memory. For this prefer to use HAL_I2C_Mem_Write or HAL_I2C_Mem_Read interface.
To give you more explanation about functionality of this interface :
1- First step of this interface is to send this sequence => START + Slave addr + R/W bit + ACK + Regvalue to write or read + ACK
2- Second step of this interface is to send this sequence => Repeated Start + Slave addr + R/W bit + ACK + DataValue to write or read on RegValue + ACK ….+ STOP
Hope that help,
Best regards,
Heisenberg.
注:
HAL_I2C_Mem_Read和HAL_I2C_Mem_Write 操作真的很方便。
应用如:
SD3088读数据方法 1 示例(从7H~9H 地址读取数据):
模拟读写I2C,再见。
0 0
- STM32 HAL I2C库读指定寄存器的数据
- 关于STM32的HAL库硬件I2C简单调试
- stm32 hal i2c 库读写sd3088时钟
- STM32-寄存器I2C--2402
- STM32-寄存器I2C--2402
- stm32 i2c通信 [操作寄存器+库函数]
- stm32 i2c通信 [操作寄存器+库函数]
- stm32 i2c通信 [操作寄存器+库函数]
- stm32 i2c通信 [操作寄存器+库函数]
- stm32 i2c通信 [操作寄存器+库函数]
- stm32 i2c通信 [操作寄存器+库函数]
- stm32 i2c通信 [操作寄存器+库函数]
- stm32 i2c通信 [操作寄存器+库函数]
- I2C上拉电阻问题分析(基于stm32 HAL库)
- STM32 HAL库 USB CDC程序只能接收一次数据
- STM32的I2C通信
- STM32的I2C-EEPROM
- STM32的I2C通信
- HDU 5630:Rikka with Chess【规律】
- Hibernate映射集合属性
- 线程的创建和启动
- log4j配置和使用
- Android四大组件之Service
- STM32 HAL I2C库读指定寄存器的数据
- Method Not Allowed和Forbidden错误
- hdoj 2084 数塔(经典dp)
- HUST 1602 Substring
- JAVA-内部类
- UNP daytime例子报文分析
- 初遇
- 第二周求圆周率
- JAVA web调用执行python脚本程序的四种方式,回避java.lang.OutOfMemoryError:PermGen space内存溢出问题