找回密码
 立即注册

使用微信账号登录

只需一步,快速开始

QCC512x QCC302x 使用I2C驱动外设(Bitserial)

2020-5-14 19:02| 发布者: csdn| 查看: 8005| 评论: 4|来自: CSDN

摘要: QCC512x QCC302x 使用I2C驱动外设(Bitserial) 1、旧接口 I2cTransfer ADK6.x 版本对 i2c的库进行了重写,在 a

QCC512x QCC302x 使用I2C驱动外设(Bitserial)

1、旧接口 I2cTransfer

ADK6.x 版本对 i2c的库进行了重写,在 app 层不能够直接使用 #include 里面的 API了。

uint16 I2cTransfer(uint16 address, const uint8 * tx, uint16 tx_len, uint8 * rx, uint16 rx_len);

开发底层库的话,依然可以调用 I2cTransfer,需要在 subsys7_config3.htf 指定 I2C pios ,第一个是 SCL、第二个是 SDA。类似于用 PSTool 的设置。

I2C Pios

2、新接口 Bitserial

在 app 层调用的话,只能用 Bitserial API,需要包含此头文件 #include
使用 Bitserial 需要将此宏打开 #if TRAPSET_BITSERIAL,在 该头文件内定义(默认打开
Bitserial 同时支持 I2C 与 SPI 两种通信。
Bitserial 提供的功能有以下几个,常用为前三个。

I2C 初始化分为几步2.1、I2C 初始化

  1. 设置 PIO 由硬件控制;
    PioSetMapPins32Bank(bank, mask, 0);
  2. 设置 PIO 功能;
    PioSetFunction(pio,func);
  3. 设置 PIO 方向;
    PioSetDir32Bank(bank, mask, 0);
  4. 设置 PIO 电平;
    PioSet32Bank(bank, mask, mask);
    PioSetStrongBias32Bank(bank, mask, mask);
  5. 设置 Bitserial 模式为 I2C;
    bsconfig.mode = BITSERIAL_MODE_I2C_MASTER;
  6. 设置 Bitserial 速度;
    bsconfig.clock_frequency_khz = prox->config->i2c_clock_khz;
  7. 设置 Bitserial 从地址;
    bsconfig.u.i2c_cfg.i2c_address = I2C_ADDRESS;
  8. 调用 BitserialOpen 并返回句柄。
    handle = BitserialOpen((bitserial_block_index)BITSERIAL_BLOCK_1, &bsconfig);

2.2、I2C 读写函数

可以直接调用 BitserialTransfer 来实现 I2C 的写操作。

static uint8 user_i2c_write_byte(bitserial_handle handle, uint8 reg, uint8 value)
{
    uint8 ret;
    uint8 txbuf[2];
    txbuf[0] = reg;
    txbuf[1] = value;
    ret = BitserialTransfer(handle, 0, txbuf, 2, NULL, 0);
    return ret;
}

同时可以实现连续写入多个寄存器操作。

static uint8 user_i2c_write_buffer(bitserial_handle handle, uint8 buffer[], uint16 buflen)
{
    uint8 ret;
    ret = BitserialTransfer(handle, 0, buffer, buflen, NULL, 0);
    return ret;
}

2.3、I2C 读函数

可以直接调用 BitserialTransfer 来实现 I2C 的读操作。

static uint8 user_i2c_read(bitserial_handle handle, uint8 txdat,uint8 rxbuf[], uint8 rxlen)
{
    uint8 ret;
    uint8 txbuf[1];
    txbuf[0] = txdat;
    memset(rxbuf,0,rxlen);
    ret = BitserialTransfer(handle, 0, txbuf, 1, rxbuf, rxlen);
    return ret;
}

3、总结

对比:

I2C地址相关注意事项:
I2cTransfer:传入设备的地址为8位写地址。
Bitserial :传入设备的地址为7位地址。

来源:https://blog.csdn.net/qq_29225913/article/details/102639717
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
10

路过
1

雷人

握手

鲜花

鸡蛋

刚表态过的朋友 (11 人)

相关阅读

发表评论

最新评论

引用 想~nl 2021-7-27 21:49
这个是什么资料,好好看看
引用 朝朝辞暮 2021-5-11 11:08
I2C
引用 ℡﹏ℳ๓构思 2020-10-21 13:22
学习
引用 yiyuzaishui 2020-6-26 09:36
经典,学习

查看全部评论(4)

小黑屋|手机版|我爱蓝牙网 - 52Bluetooth

GMT+8, 2024-4-27 00:12 , Processed in 0.242060 second(s), 32 queries , Gzip On, MemCached On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

返回顶部