|
本帖最后由 paulhyde 于 2014-9-15 03:21 编辑
求助
msp430g2553与TCA6416用IIC通讯 但中断只能进一次,这是什么原因
#include "msp430g2553.h"
void gpio_init (void);
void iic_init(void);
unsigned char TXData[4]={0x02,0x00,0xa2,0x03};
int i,j;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; //Close Interal Watchdog Timer
i=0;
P1DIR |= 0x01;
P1OUT&= ~0x01;
_EINT();
gpio_init ();
iic_init();
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
while (1){
}
}
void gpio_init (void)
{
P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0
P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0
}
void iic_init(void)
{
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2 + UCSWRST+ UCTR; // Use SMCLK, keep SW reset
UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = 0x20; // Slave Address is 020h
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
IE2 |= UCB0TXIE; // Enable TX interrupt
}
// USCI_B0 Data ISR
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{
UCB0TXBUF = TXData; // TX data
P1OUT^=0x01;
i=i+1;
if(i==4){
UCB0CTL1 |= UCTXSTP; // I2C TX, start condition
}
}
|
|