主题中讨论的其他器件:PCA9536
您好!
我在自己的电路板上使用了 I2C 总线、并通过 F28069驱动 EEPROM 24EE256和 PCA9536。 地址正常:一个为0x50 (EEPROM),另一个为0x41 (用于 PCA)。
使用 EEPROM 时、一切都正常、与代码完美配合、但 IO 扩展器永远不会应答写入或读取请求。
我每20ms 发送一次写入命令。 我没有任何错误。 我加入了示波器打印屏幕和源代码。
我使用 " UINT16 I2C_Write_Data (UINT16 Slave_address、UINT16寄存器、UINT16 Data)" 、例如
I2C_Write_Data (0x41、0x0001、0x0000);//每20ms 执行一次
我请求向寄存器0x1写入0x0到器件地址0x41、但在示波器上、我只能看到地址0x41、没有数据?! 为什么?

如果您有任何想法、请告诉我。 感谢你的帮助
OL
//##################### I2C_Write_Data #################################################################################
// Function Name: void I2C_Write_Data
// Return Type: Uint16
// Arguments: Uint16 Slave_address, Uint16 Register, Uint16 Data
// Description: I2C_Write_Data
//#################################################################################################################
Uint16 I2C_Write_Data(Uint16 Slave_address, Uint16 Register, Uint16 Data)//
{
Uint16 ii = 0;
Uint16 TimeOutI2C = 0;
I2caRegs.I2CMDR.bit.IRS = 1; // reset I2C
__asm(" RPT #10 || NOP");
// Make sure I2C is not busy and has stopped
while (I2caRegs.I2CSTR.bit.BB == 1) //; // busy loop
{
TimeOutI2C++;
if(TimeOutI2C > 20000)
return 0;
}
TimeOutI2C = 0;
// Clear the SCD bit (stop condition bit)
I2caRegs.I2CSTR.bit.SCD = 1; // Clear the SCD bit (stop condition bit)
while(I2caRegs.I2CMDR.bit.STP == 1) //; // stop bit loop
{
TimeOutI2C++;
if(TimeOutI2C > 20000)
return 0;
}
TimeOutI2C = 0;
// code d'origine
//##################################################
I2caRegs.I2CSAR = Slave_address;
//still busy?
while(I2caRegs.I2CMDR.bit.STP != 0){
TimeOutI2C++;
if(TimeOutI2C > 20000)
return 0;
}
TimeOutI2C = 0;
// Start bit, write mode, Higher 16 address bits, Master, Repeat mode.
I2caRegs.I2CMDR.bit.TRX = 1; //TRANSMIT_MESSAGE;
I2caRegs.I2CDXR = Register; // Register
//##################################################//
I2caRegs.I2CMDR.all = 0x26A0; //01 00 11 01 01 00 000
//I2caRegs.I2CMDR.all = 0x27A0; //01 00 11 01 01 00 000
/* I2caRegs.I2CMDR.bit.NACKMOD = 0; // NACK mode bit
I2caRegs.I2CMDR.bit.FREE = 1; // Stop I2C when suspended
I2caRegs.I2CMDR.bit.STT = 0; // START condition bit
I2caRegs.I2CMDR.bit.STP = 0; // STOP condition bit
I2caRegs.I2CMDR.bit.MST = 1; // Master mode
I2caRegs.I2CMDR.bit.TRX = 1; // Transmitter mode
I2caRegs.I2CMDR.bit.XA = 0; // 7-bit addressing mode
I2caRegs.I2CMDR.bit.RM = 1; // Repeat Mode
I2caRegs.I2CMDR.bit.DLB = 0; // Digital loopback mode is disabled
I2caRegs.I2CMDR.bit.IRS = 1; // The I2C module is enabled
I2caRegs.I2CMDR.bit.STB = 0; // The I2C module is not in the START byte mode
I2caRegs.I2CMDR.bit.FDF = 0; // Free data format mode is disabled
I2caRegs.I2CMDR.bit.BC = 000; // 8 bits per data byte
*/
//(Lower 16) address bits
while(I2caRegs.I2CSTR.bit.ARDY != 1){
TimeOutI2C++;
if(TimeOutI2C > 20000)
return 0;
}
TimeOutI2C = 0;
I2caRegs.I2CDXR = Data; //
while (I2caRegs.I2CSTR.bit.NACK == 1) // Clear if NACK received
{
I2caRegs.I2CSTR.bit.NACK = 1;
TimeOutI2C++;
if(TimeOutI2C > 20000)
return 0;
}
TimeOutI2C = 0;
I2caRegs.I2CMDR.all = 0x0EA0;
/* I2caRegs.I2CMDR.bit.NACKMOD = 0; // NACK mode bit
I2caRegs.I2CMDR.bit.FREE = 1; // Stop I2C when suspended
I2caRegs.I2CMDR.bit.STT = 0; // START condition bit
I2caRegs.I2CMDR.bit.STP = 1; // STOP condition bit
I2caRegs.I2CMDR.bit.MST = 1; // Master mode
I2caRegs.I2CMDR.bit.TRX = 0; // Transmitter mode
I2caRegs.I2CMDR.bit.XA = 0; // 7-bit addressing mode
I2caRegs.I2CMDR.bit.RM = 0; // Nonrepeat mode
I2caRegs.I2CMDR.bit.DLB = 0; // Digital loopback mode is disabled
I2caRegs.I2CMDR.bit.IRS = 1; // The I2C module is enabled
I2caRegs.I2CMDR.bit.STB = 0; // The I2C module is not in the START byte mode
I2caRegs.I2CMDR.bit.FDF = 0; // Free data format mode is disabled
I2caRegs.I2CMDR.bit.BC = 000; // 8 bits per data byte
*/
while(I2caRegs.I2CSTR.bit.SCD != 1){
TimeOutI2C++;
if(TimeOutI2C > 20000)
return 0;
}
TimeOutI2C = 0;
I2caRegs.I2CSTR.bit.SCD = 1; // Clear stop condition
return 1;
}


