我看官方提供的430操作该器件发送的从机地址是7位(0x20)
/************************** I2C Address ***************************************/ #define TCA6416A_ADDRESS 0x20 // I2C Address 0100 00 + ADDR + R/W // ADDR tied to P2.2 of LaunchPad /************************** I2C Registers *************************************/
然后
// ****************************************************************************
//! @fn void TCA6416AInitI2CReg(TCA6416ARegs* Regs)
//! @brief
//!
//! TODO Implement I2C return (success/failure)
// ****************************************************************************
unsigned char TCA6416AInitI2CReg(TCA6416ARegs* Regs){
unsigned char return_Value = I2C_OPERATION_SUCCESSFUL;
I2C_Write(2, TCA6416A_ADDRESS, TCA6416A_CONFIG_REG0, (unsigned char*)&Regs->Config, 0);
I2C_Write(2, TCA6416A_ADDRESS, TCA6416A_OUTPUT_REG0, (unsigned char*)&Regs->Output, 0);
I2C_Write(2, TCA6416A_ADDRESS, TCA6416A_POLARITY_REG0, (unsigned char*)&Regs->PolarityInversion, 0);
if(NACK)
{
NACK = 0;
return_Value = I2C_OPERATION_FAIL;
}
return return_Value;
}
然后
void I2C_Write (unsigned char byte_Count, unsigned char Slave_Address, unsigned char Register_Address, unsigned char Register_Data[], unsigned char offset)
{
// wait until I2C module has finished all operations.
while (UCB0STAT & UCBUSY);
// Set slave address
UCB0I2CSA = Slave_Address;
I2CBufferArray[byte_Count] = Register_Address;
// If word mode, write 2 bytes
int x = byte_Count-1;
unsigned char y=0;
for (;x>=0;x--)
{
I2CBufferArray[x] = Register_Data[y+offset];
y++;
}
PtrTransmit = byte_Count;
// start condition generation
I2CWriteInit();
// => I2C communication is started
UCB0CTL1 |= UCTXSTT;
UCB0I2CIE |= UCNACKIE;
// Enter LPM0 w/ interrupts
__bis_SR_register(LPM0_bits + GIE);
// I2C stop condition
UCB0CTL1 |= UCTXSTP;
// Ensure stop condition got sent
while(UCB0CTL1 & UCTXSTP);
UCB0I2CIE &= ~UCNACKIE;
}
UCB0I2CSA = Slave_Address;
从上面这句话可以看出访问TCA6416A就是这个,那个R/W#位怎么使用的。
