我在用G2553定时读取进行温度时,为什么进入不了IIC接收中断,我是按照官方的TMP100通信来写的,跑不通,后来也把官方的程序跑了一下(改了地址),也是这样,设置断点,当程序执行到UCB0CTL1 |= UCTXSTT;后全速执行,用示波器采用沿触发观察时钟SCL和数据SDA的输出,观察到所发出的地址(和读写位)和时钟,但是在第9个时,无响应,直接就是SDA高电平,TMP112不会响应地址信号,也就是根本不能与TMP112建立通信,我也不知道为什么,板子用的是launchpad,P1.6LED的接头也拔掉了,我接了个示波器的图如下:
下面是程序:
#include <msp430g2553.h>
unsigned int i=0;
unsigned int RxWord,RXByteCtr;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P1DIR |= BIT0; // P1.0 output
//设置IIC
P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0
P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = 0x48; // Set slave address
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
IE2 |= UCB0RXIE; // Enable RX interrupt
//设置定时器TimerA
CCR0 = 4096-1; // 计数周期为10s
TACTL = TASSEL_1 + MC_2+ID_3; // ACLK, upmode,8分频
CCTL0 = CCIE; // CCR0 interrupt enabled
__bis_SR_register(GIE);
while(1)
{
RXByteCtr=2;
__bis_SR_register(LPM0_bits);
UCB0CTL1 |= UCTXSTT+UCTR; // I2C start condition
__bis_SR_register(LPM0_bits);
}
}
//定时器中断,进入后启动温度传输,因为温度为2位,传输两次
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A0 (void)
{
CCR0 += 10000;
P1OUT ^= BIT0; // Toggle P1.0
__bic_SR_register_on_exit(LPM0_bits);
}
//这里仿照G2553例程,主器件接收任意字节数据(2字节) ********不知为什么,程序总是进入不了中断 ?????
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{
RXByteCtr–; // Decrement RX byte counter
if (RXByteCtr)
{
RxWord = UCB0RXBUF; // Move RX data to address PRxData
RxWord =RxWord<<8;
if (RXByteCtr == 1) // Only one byte left?
UCB0CTL1 |= UCTXSTP; // Generate I2C stop condition
}
else
{
RxWord|= UCB0RXBUF; // Move final RX data to PRxData
__bic_SR_register_on_exit(LPM0_bits);
}
}
Jarvan Song:
lz你好
首先你的msp430g2553是作为主机读取,TMP112寄存器里面的数据,所以说msp430g2553他是读模式,所以应设置msp430为主机,receive模式,而不是transmit。
while(1){RXByteCtr=2;__bis_SR_register(LPM0_bits);UCB0CTL1 |= UCTXSTT+UCTR; // I2C start condition__bis_SR_register(LPM0_bits);}