使用6726做主设备给从设备发送数据,从设备是ADS1113,代码如下:
#include <msp430.h>
unsigned char TXData;
unsigned char TXByteCtr;
int main(void)
{
WDTCTL = WDTPW | WDTHOLD; // Stop WDT
// Setup P2.0 UCB0SCL, P2.1 UCB0SDA
P2SEL |= BIT0 | BIT1; // Set P2.0,P2.1 to UCB0SCL, UCB0SDA
// Setup eUSCI_B0
UCB0CTLW0 |= UCSWRST; // Enable SW reset
UCB0CTLW0 |= UCMST | UCMODE_3 | UCSSEL_2; // I2C Master, use SMCLK
UCB0BRW_L = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BRW_H = 0;
UCB0I2CSA = 0x48; // Slave Address is 048h
UCB0CTLW0 &= ~UCSWRST; // Clear SW reset, resume operation
UCB0IE |= UCTXIE0; // Enable TX interrupt
TXData = 0x01; // Holds TX data
while (1)
{
TXByteCtr = 1; // Load TX byte counter
while (UCB0CTLW0 & UCTXSTP) ; // Ensure stop condition got sent
UCB0CTLW0 |= UCTR|UCTXSTT; // I2C TX, start condition
// UCB0CTLW0 |=UCTXSTT;
__bis_SR_register(LPM0_bits | GIE); // Enter LPM0 w/ interrupts
__no_operation(); // Remain in LPM0 until all data
// __delay_cycles(10000); // is TX'd
TXData++; // Increment data byte
}
}
//------------------------------------------------------------------------------
// The USCIAB0_ISR is structured such that it can be used to transmit any
// number of bytes by pre-loading TXByteCtr with the byte count.
//------------------------------------------------------------------------------
// USCI_B0 interrupt service routine
#pragma vector = USCI_B0_VECTOR
__interrupt void USCI_B0_ISR(void)
{
switch (__even_in_range(UCB0IV, 30))
{
case USCI_NONE: break; // No interrupts
case USCI_I2C_UCALIFG: break; // ALIFG
case USCI_I2C_UCNACKIFG: break; // NACKIFG
case USCI_I2C_UCSTTIFG: break; // STTIFG
case USCI_I2C_UCSTPIFG: break; // STPIFG
case USCI_I2C_UCRXIFG3: break; // RXIFG3
case USCI_I2C_UCTXIFG3: break; // TXIFG3
case USCI_I2C_UCRXIFG2: break; // RXIFG2
case USCI_I2C_UCTXIFG2: break; // TXIFG2
case USCI_I2C_UCRXIFG1: break; // RXIFG1
case USCI_I2C_UCTXIFG1: break; // TXIFG1
case USCI_I2C_UCRXIFG0: break; // RXIFG0
case USCI_I2C_UCTXIFG0: // TXIFG0
// if (TXByteCtr) // Check TX byte counter
// {
UCB0TXBUF = TXData; // Load TX buffer
TXByteCtr--; // Decrement TX byte counter
// }
// else
// {
UCB0IFG &= ~UCTXIFG; // Clear USCI_B0 TX int flag
UCB0CTL1 |= UCTXSTP; // I2C stop condition
__bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
// }
break;
case USCI_I2C_UCBCNTIFG: break; // CNTIFG
case USCI_I2C_UCCLTOIFG: break; // LTOIFG
case USCI_I2C_UCBIT9IFG: break; // BIT9IFG
default: break;
}
}
问题来了,程序在 ONLINE DEBUG的时候可以从监视窗口看到数据已发送到UCB0TXBUF ,但是从波形上看只能看到发送从设备地址,没有数据,求教啊! |