[问题] 新手发问:MSP430与I2C通讯的一些问题

楼主: whynotjolin (whynotjolin)   2014-04-25 11:07:56
版上各位大大好,小弟是个刚学习单芯片的新手
有一些基本的暂存器运算问题想请问各位
while((UCB0STAT & UCBBUSY) != 0); // Wait for Bus to be Inactive
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX Mode, Start Condition
while((IFG2 & UCB0TXIFG) == 0); // Wait for Transmitter to be Ready
UCB0TXBUF = (Address >> 8) & 0x00FF; // Load MSB Address
while((IFG2 & UCB0TXIFG) == 0); // Wait for Transmitter to be Ready
UCB0TXBUF = Address & 0x00FF; // Load LSB Address
while((IFG2 & UCB0TXIFG) == 0); // Wait for Transmitter to be Ready
UCB0TXBUF = DataByte0; // Load Data Byte0
while((IFG2 & UCB0TXIFG) == 0); // Wait for Transmitter to be Ready
UCB0CTL1 |= UCTXSTP; // Generate I2C Stop Condition
while((UCB0CTL1 & UCTXSTP) != 0); // To Prevent Arbitration Lost
1. 在第一行的while条件中,是要满足((UCB0STAT & UCBBUSY) != 0,但是小弟不明
白的点在于UCBBUSY在datasheet中是说
0 Bus inactive
1 Bus busy
但要满足Bus to be inactive不就是要UCB0STAT跟UCBBUSY都是1吗?
又我们又如何知道UCB0STAT是1 or 0
2. 在第倒数第二行的程式中,|= 的意思是UCB0CTL1 = UCB0CTL1 | UCTXSTP吗?
如果是,那如何确定UCTXSTP一定是1?
0 No STOP generated
1 Generate STOP
以上
恳问版上大大高见

Links booklink

Contact Us: admin [ a t ] ucptt.com