跳转至内容
  • 版块
  • 最新
  • 标签
  • 热门
折叠
品牌标识

YunTu Forum

YTMicro.com
  1. 主页
  2. Discussion & Question
  3. YT SDK
  4. I2C Slave 中断回调函数 Case 使用说明

I2C Slave 中断回调函数 Case 使用说明

已定时 已固定 已锁定 已移动 YT SDK
1 帖子 1 发布者 24 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • quanfengQ 离线
    quanfengQ 离线
    quanfeng YunTu
    编写于 最后由 编辑
    #1

    1. 问题背景

    1. 软件:MD1 SDK 1_4_0 I2c_Slave_Demo
      I2c_Slave_Demo.zip
    2. 硬件:MD14 EVB or 客户板子
    3. 问题表述:
    • I2C 从机模式时,客户想在回调函数里做处理,但不清楚回调函数里 Case 的使用情况。

    2. Case 说明

    1. I2C0_SlaveRxCpltCallback 函数
    /*
        伪 C 语言代码,直接编译会报错
    */
    void I2C0_SlaveRxCpltCallback(i2c_slave_event_t event, void *userData)
    {
        /* Get the instance number from userData */
        uint32_t instance = 0;
        (void)userData;
        /* Depending on the event received, set the buffers or abort the transfer */
        switch (event)
        {
            case I2C_SLAVE_EVENT_RX_REQ:
                /*
                 * If the bus master requests data, then set the destination RX buffer
                 * and accepted transfer size
                 */
                  I2C_DRV_SlaveSetRxBuffer(instance, slaveRxBuffer, BUFF_SIZE);
                break;
            case I2C_SLAVE_EVENT_TX_REQ:
                /*
                 * If the bus master sends data, then set the source TX buffer
                 * and accepted transfer size
                 */
                  I2C_DRV_SlaveSetTxBuffer(instance, slaveTxBuffer, BUFF_SIZE);
                break;
            case I2C_SLAVE_EVENT_TX_EMPTY:
                /*
                 * If the TX buffer is empty. Because the example does not handle 
                 * this case there is no action taken.
                 */
            case I2C_SLAVE_EVENT_RX_FULL:
                /*
                 * If the RX buffer is full, check the slave receive buffer is correct
                 */
                break;
            case I2C_SLAVE_EVENT_STOP:
                /*
                 * This case is used when a stop condition is on the bus. Because
                 * the example does not handle this case there is no action taken.
                 */
                break;
        }  
    }
    

    0b7d3fa6-05ae-4356-8070-568980a9a476-image.png

    3. 获取接收 Data 的个数

    1. 使用 I2C_DRV_SlaveGetTransferStatus 函数可以获取 Data 接收的个数,I2C_DRV_SlaveSetTxBuffer 函数的第三个参数是当前 rxSize 的剩余长度,接收长度(已知) - bytesRemaining 得到当前接收了多少字节
      9dfa6e82-5e74-4d8f-8b15-13ddddb62ded-image.png
    1 条回复 最后回复
    0

  • 云途开发生态介绍

    快速上手云途开发生态

  • 云途论坛规则/Yuntu Forum Rules

    发帖前请查看

  • YT CONFIG TOOL调查问卷

    帮助改进和优化YT CONFIG TOOL,有机会抽取YTM32B1ME0 EVB哦...

  • can
    23
    demo
    20
    uds
    13
    lin stack
    12
    md14
    6
    fbl
    5
    yt-link
    5
    adc模块
    4
    Online Users
    mcM
    mc
    Tiger987T
    Tiger987
    EkkoE
    Ekko
    zhaodong1Z
    zhaodong1
    xiangyuX
    xiangyu
    D
    Derrick
    彭希哲彭
    彭希哲
    abcbillA
    abcbill
    xianghanX
    xianghan
    YQHY
    YQH
    swordsS
    swords
    • 登录

    • 登录或注册以进行搜索。
    • 第一个帖子
      最后一个帖子
    0
    • 版块
    • 最新
    • 标签
    • 热门