請問若參考範例249a中的msp430x26x_SMB_tmp175
我看不懂它如何傳送與接受資料部份
有人可以大致說明一下嗎?? 謝謝
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{ if (TXByteCtr) // Check TX byte counter { UCB0TXBUF = *PTxData++; // Load TX buffer TXByteCtr--; // Decrement TX byte counter } else { UCB0CTL1 |= UCTXSTP; // I2C stop condition IFG2 &= ~UCB0TXIFG; // Clear USCI_B0 TX int flag __bic_SR_register_on_exit(CPUOFF); // Exit LPM0 }
}
// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{ if (UCB0RXBUF > 0x20) P1OUT |= 0x01; // LED on if >32C else P1OUT &= ~0x01; // LED off UCB0CTL0 |= UCMST; // Master mode while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent UCB0CTL1 |= UCTXSTT; // I2C start condition while (UCB0CTL1 & UCTXSTT); // Start condition sent? UCB0CTL1 |= UCTXSTP; // I2C stop condition
}
#pragma vector=PORT2_VECTOR
__interrupt void p2_isr(void)
{ P2IFG = 0; UCB0I2CSA = 0x19; // SMBus Alert response UCB0CTL0 |= UCMST; // Master mode while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent UCB0CTL1 |= UCTXSTT; // I2C start condition while (UCB0CTL1 & UCTXSTT); // Start condition sent? UCB0CTL1 |= UCTXSTP; // I2C stop condition UCB0I2CSA = 0x48; // Slave Address
}
|