一直停在这while((IFG2 & UCB0TXIFG)==0); // UCB0TXIFG is set when UCB0TXBUF is empty
这是神魔情况,网上很多人提过,但是没有看到解决方法,硬件i2c的问题
void I2C_WriteData(uint8 data)
{
I2C_Init(Master,SMCLK);
i2c_delay_ms(1);
while((UCB0CTL1 & UCTXSTP)); // 确保总线空闲
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
while((IFG2 & UCB0TXIFG)==0); // UCB0TXIFG is set when UCB0TXBUF is empty.
UCB0TXBUF = SlaveAddress; // Load TX buffer
while((IFG2 & UCB0TXIFG)==0); // UCB0TXIFG is set when UCB0TXBUF is empty.
UCB0TXBUF = data;
while((IFG2 & UCB0TXIFG)==0); // UCB0TXIFG is set when UCB0TXBUF is empty.
UCB0CTL1 |= UCTXSTP; // I2C stop condition
i2c_delay_ms(1);
} |