void USCI_B_I2C_masterSendSingleByte(uint16_t baseAddress,
uint8_t txData)
{
//Store current TXIE status
uint8_t txieStatus = HWREG8(baseAddress + OFS_UCBxIE) & UCTXIE;
//Disable transmit interrupt enable
HWREG8(baseAddress + OFS_UCBxIE) &= ~(UCTXIE);
//Send start condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTR + UCTXSTT;
//Poll for transmit interrupt flag.
while(!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG))
{
;
}
//Send single byte data.
HWREG8(baseAddress + OFS_UCBxTXBUF) = txData;
//Poll for transmit interrupt flag.
while(!(HWREG8(baseAddress + OFS_UCBxIFG) & UCTXIFG))
{
;
}
//Send stop condition.
HWREG8(baseAddress + OFS_UCBxCTL1) |= UCTXSTP;
//Clear transmit interrupt flag before enabling interrupt again
HWREG8(baseAddress + OFS_UCBxIFG) &= ~(UCTXIFG);
//Reinstate transmit interrupt enable
HWREG8(baseAddress + OFS_UCBxIE) |= txieStatus;
}
以上是MSPWare中的IIC例程的其中一个函数,我不理解的地方在于主机发送起始位之前为何要关闭发送中断,中断标志位UCTXIFG是当UCBxTXBUF为空的时候置1,在中断被关闭的条件下,标志位UCTXIFG还会相应的变化吗?查询标志位可以成功判断发送已经完成吗?
我在实际调试过程中发现,如果一直没有开启中断,那中断标志位就不会变化。
灰小子:
这是哪个例程?我也去看看