CH455G 硬件HAL库 I2C驱动

概要

CH455G 硬件HAL库 I2C驱动 能正确采集到案件数值

参考 https://blog.youkuaiyun.com/jzffzj/article/details/107379205
参考 https://github.com/Cathgao/peripherals-libraries-for-STM32/blob/2315f1227b910560f88f98570bea895129216879/CH455/CH455.c

技术细节


/**
 * @breif: 读取CH455键盘数据
 * @param: 无
 * @return: 读取到的数据
 */
uint8_t CH455_ReadKey(void)
{
    uint8_t key_value;
    while (HAL_I2C_Master_Receive(&hi2c1, 0x4F, &key_value, 1, 0xff) != HAL_OK)
    {
        if ((HAL_I2C_GetError(&hi2c1) != HAL_OK))
        {
            HAL_I2C_Init(&hi2c1);
            printf("CH455 read key ERROR! 0x%x \n", HAL_I2C_GetError(&hi2c1));
            return 0;
        }
    }
    printf("CH455 read key 0x%x \n", key_value);
    return key_value;
}

/**
 * @breif: 驱动CH455数码管显示
 * @param: cmd: 要写入的数据
 * @return: 无
 */
void CH455_Write(uint16_t cmd)
{
    uint8_t data1 = 0;
    uint8_t data2 = 0;
    data1 = ((uint8_t)(cmd >> 7) & CH455_I2C_MASK) | CH455_I2C_ADDR;
    data2 = (uint8_t)(cmd & 0x00ff);
    HAL_I2C_Master_Transmit(&hi2c1, data1, &data2, 1, 1000);
}

void CH455_Init(void)
{
    CH455_Write(CH455_8SEG_ON); // 开启显示和键盘,8段显示方式
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值