1. 话不多说 直接实战
首先 我是用 YTM32B1MC0 的 I2C Demo 作为演示 和 讲解
1.1 I2C配置
引脚定义,关注 SCL 和 SDA 即可
外设配置
Slave address,7-bit or 10-bit
:从机地址,80 即 0x50. SDK 中的 send 和 recv 接口 会自己把 这个地址 代入
10-bit slave address
:是否选择 10bit 地址, 我们默认的是 7bit
I2C Operating mode
:操作模式 分为 标准模式 和 快速模式; 这里我们用标准模式即可
Baudrate
:波特率 ,按需设定
Type of LPI2C transfer
:传输方式 有 中断 或者 DMA
1.2 Demo
#include "sdk_project_config.h"
#include <string.h>
#include <stdint.h>
#include <stdbool.h>
#define INST_I2C (1U)
#define Stop true
#define NotStop false