使用C8051通过I2C总线连接PCA9546A芯片,通过查看芯片手册设置的寄存器地址,但是现在无论如何都不能通过i2c总线连接到PCA9546A芯片上,比如说写入读取数据,开启通道1的I2C总线,都不能完成
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
使用C8051通过I2C总线连接PCA9546A芯片,通过查看芯片手册设置的寄存器地址,但是现在无论如何都不能通过i2c总线连接到PCA9546A芯片上,比如说写入读取数据,开启通道1的I2C总线,都不能完成
你好,你说的这个从机地址是7bit的,比如说我A0-1 A1-0 A2-0,此时如果是写信号的话从机地址是 0xE2 如果是读信号的话PCA9546的从机地址是0XE3是吗?

你好,我A0-1 A1-0 A2-0 同时我参考的是
个文档中的I2C数据总线的通信,所以比如说我现在如果想给芯片的地址写数据的话 代码如下,我这么设置可以吗?
//A0--1 A1--0 A2--0
#define PAC9546_W_ADDRES 0XE2
#define PCA_REG0_EN 0xE1//这是参考的芯片手册上说的如果需要通道1使能的话这么设置
/*******************************************************************
字节数据读取函数
函数原型: void Pcf_RecByte();
功能: 从寄存器中读取数据
此状态位进行操作.(不应答或非应答都使ack=0)
发送数据正常,ack=1; ack=0表示被控器无应答或损坏。
********************************************************************/
unsigned char Pcf_RecByte(void)
{
uchar i;
uchar dat = 0;
I2C_SDA = 1; //使能内部上拉,准备读取数据,
for (i=0; i<8; i++) //8位计数器
{
dat <<= 1;
I2C_SCL = 1; //拉高时钟线
ic_delay(20); //延时
dat |= I2C_SDA; //读数据
I2C_SCL = 0; //拉低时钟线
ic_delay(20); //延时
}
return dat;
}
/*******************************************************************
向有子地址器件发送多字节数据函数
函数原型: int pca9546_w_register(unsigned char pca_w_address,unsigned char channel_mode,unsigned char w_data)
功能: 通过I2C向PCA9546A芯片中指定的地址位写入数据
参数: pca_w_address:从机地址
channel_mode:从机寄存器地址 通过B0 B1 B2 B3设置决定
w_data:目标数据
如果返回1表示操作成功,否则操作有误。
注意: 使用前必须已结束总线。
********************************************************************/
void pca9546_w_register(unsigned char pca_address,unsigned char REG_ADDRESS,unsigned char w_data)
{
Pca_Start_I2c(); //启动总线
Pcf_SendByte(pca_address); //发送器件地址
Pcf_SendByte(REG_ADDRESS); //发送器件子地址
Pcf_SendByte(w_data); //数据高字节s
ic_delay(20);
Pca_Stop_I2c(); //结束总线
// return(1);
}
/*******************************************************************
向有子地址器件发送多字节数据函数
函数原型: int pca9546_r_register(unsigned char pca_r_address,unsigned char channel_mode,unsigned char r_data)
功能: 通过I2C向PCA9546A芯片中指定的地址位写入数据
参数: pca_r_address:从机地址
channel_mode:从机寄存器地址 通过B0 B1 B2 B3设置决定
r_data:读取到的目标数据存放地址
如果返回1表示操作成功,否则操作有误。
注意: 使用前必须已结束总线。
********************************************************************/
uchar pca9546_r_register(unsigned char pca_address,unsigned char REG_Address)
{
uchar REG_data;
uchar i;
uchar dat = 0;
Start_I2c(); //启动总线
Pcf_SendByte(pca_address);
Pcf_SendByte(REG_Address);
Pca_Start_I2c(); //启动总线
Pcf_SendByte(pca_address+1);
REG_data=Pcf_RecByte();
ic_delay(100);
Pca_Stop_I2c(); //结束总线
return REG_data;
}
您好,是的,A0-1 A1-0 A2-0的话,写地址为0XE2,读地址为0XE3.