I2C Slave 中断回调函数 Case 使用说明
-
1. 问题背景
- 软件:MD1 SDK 1_4_0 I2c_Slave_Demo
I2c_Slave_Demo.zip - 硬件:MD14 EVB or 客户板子
- 问题表述:
- I2C 从机模式时,客户想在回调函数里做处理,但不清楚回调函数里 Case 的使用情况。
2. Case 说明
- 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; } }
3. 获取接收 Data 的个数
- 使用 I2C_DRV_SlaveGetTransferStatus 函数可以获取 Data 接收的个数,I2C_DRV_SlaveSetTxBuffer 函数的第三个参数是当前 rxSize 的剩余长度,接收长度(已知) - bytesRemaining 得到当前接收了多少字节

- 软件:MD1 SDK 1_4_0 I2c_Slave_Demo
快速上手云途开发生态
发帖前请查看
帮助改进和优化YT CONFIG TOOL,有机会抽取YTM32B1ME0 EVB哦...