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.
BOOLEAN i2c_led_ReadData(BYTE pSrc, BYTE *pDst, UINT32 size)
{
BYTE p1 = pSrc,
*p2 = pDst;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE );
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
if (size < 1) {return 0;} //start
Start_I2c();
SendByte(p1); //发送地址
if(ack==0)return(0);
SendByte(0x80); //发送命令字节80
if(ack==0)return(0);
Start_I2c();
SendByte(p1|0x01);//发送地址+1
if(ack==0)return(0);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING ;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
while (size)
{
*p2++ = i2c_RecvByte();
if (size == 1) i2c_NoAck();
else i2c_Ack();
size--;
}
Stop_I2c();
return 1;
i2c_led_ReadData(0x44,wdata084,3);
芯片地址为0x44,总TCA6424A中读出三个INPUT的数据存在数组wdata084中。
问题现象:
1、只能读出port0中的数据,命令字节不会自动增加。程序中已将命令为写成80;
2、读出来的p0的数据智能读出1位:
p01 为低电平 读出来 FE 1111 1110
p02 为低电平 读出来 FC 1111 1100
p03 为低电平 读出来 F8 1111 1000
p04 为低电平 读出来 F0 1111 0000
p05为低电平 读出来 FE 1110 0000
p06 为低电平 读出来 FC 1100 0000
p07 为低电平 读出来 F8 1000 0000
p08 为低电平 读出来 F0 0000 0000