本章节只对如何使用进行讲解,基础原理自行查看数据手册。此外,该章节可能存在操作不明现象,可以观看前面几个章节,方便理解
图中为ccs中syscfg页面,IIC主要配置的参数有默认工作模式、数据中每个字节有多少位,设备地址大小(分为7位和11位,具体参数设定根据目标设备确定,例如at24c02为7)等,其他参数配置如图所示,复用引脚选择根据自己pcb确定。
变量声明
#define TARGET_ADDRESS 0x50
#define EEPROM_HIGH_ADDR 0x00
#define EEPROM_LOW_ADDR 0x30
#define NUM_BYTES 8
#define MAX_BUFFER_SIZE 14 // Max is currently 14 because of
// 2 address bytes and the 16-byte
// FIFO
//
// I2C message states for I2CMsg struct
//
#define MSG_STATUS_INACTIVE 0x0000 // Message not in use, do not send
#define MSG_STATUS_SEND_WITHSTOP 0x0010 // Send message with stop bit
#define MSG_STATUS_WRITE_BUSY 0x0011 // Message sent, wait for stop
#define MSG_STATUS_SEND_NOSTOP 0x0020 // Send message without stop bit
#define MSG_STATUS_SEND_NOSTOP_BUSY 0x0021 // Message sent, wait for ARDY
#define MSG_STATUS_RESTART 0x0022 // Ready to become controller-receiver
#define MSG_STATUS_READ_BUSY 0x0023 // Wait for stop before reading data
//
// Error messages for read and write functions
//
#define ERROR_BUS_BUSY 0x1000
#define ERROR_STOP_NOT_