野火电子论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 15533|回复: 0

怎样向从机的寄存器写入数据?

[复制链接]
发表于 2020-7-14 14:17:41 | 显示全部楼层 |阅读模式
stm32l0xx hal Slave Address: 0x7C(Write) Regaddress:0x00,0x01,0x03,data:0x14,0x14,0x03
怎样向从机的寄存器写入数据?


HAL_StatusTypeDef HAL_I2C_Master_Transmit(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
HAL_StatusTypeDef HAL_I2C_Master_Receive(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint8_t *pData, uint16_t Size, uint32_t Timeout);
HAL_StatusTypeDef HAL_I2C_Slave_Transmit(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
HAL_StatusTypeDef HAL_I2C_Slave_Receive(I2C_HandleTypeDef *hi2c, uint8_t *pData, uint16_t Size, uint32_t Timeout);
HAL_StatusTypeDef HAL_I2C_Mem_Write(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout);
HAL_StatusTypeDef HAL_I2C_Mem_Read(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint16_t MemAddress, uint16_t MemAddSize, uint8_t *pData, uint16_t Size, uint32_t Timeout);
HAL_StatusTypeDef HAL_I2C_IsDeviceReady(I2C_HandleTypeDef *hi2c, uint16_t DevAddress, uint32_t Trials, uint32_t Timeout);



如下代码不起作用:
HAL_I2C_Mem_Write(&hi2c1, 0x7C, 0x00, I2C_MEMADD_SIZE_8BIT, (uint8_t *)0x14, 1, 1000);
HAL_I2C_Mem_Write(&hi2c1, 0x7C, 0x01, I2C_MEMADD_SIZE_8BIT, (uint8_t *)0x14, 1, 1000);
HAL_I2C_Mem_Write(&hi2c1, 0x7C, 0x03, I2C_MEMADD_SIZE_8BIT, (uint8_t *)0x03, 1, 1000);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

联系站长|手机版|野火电子官网|野火淘宝店铺|野火电子论坛 ( 粤ICP备14069197号 ) 大学生ARM嵌入式2群

GMT+8, 2024-11-25 14:44 , Processed in 0.025559 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表