This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

关于MSP430G2755 USCI I2C SLAVE问题

Other Parts Discussed in Thread: BQ40Z50

HI,TI

设计功能是MSP430做主机模拟I2C读取BQ40Z50(已成功),然后用户通过硬件USCI I2C读取数据。 在调USCI I2C 从机时,用EV2300去读程序总是跑飞,死在RX中断。简单的从机程序也不行,请大神看看哪里问题。code如下:

#include "io430.h"

unsigned char *PRxData; // Pointer to RX data
unsigned char RXByteCtr;
volatile unsigned char RxBuffer[128]; // Allocate 128 byte of RAM


#define CPU_F ((double)1000000)//1MHZ
//#define CPU_F ((double)8000000)//8MHZ
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))//x必须是常量或常量表达式
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))//x必须是常量或常量表达式

int main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;

BCSCTL1 = CALBC1_1MHZ; // Set DCO to 1MHz 频率校准
DCOCTL = CALDCO_1MHZ;

BCSCTL1 &=~XTS; //XT1低频模式
BCSCTL1 |= DIVA_0 + XT2OFF; //关闭XT2,XT1不分频
BCSCTL2 |= SELM_0 + DIVM_0 + DIVS_0;//+ SELS //MCLK选择DCO时钟,不分频,SMCLK选择DCO,不分频
BCSCTL3 |= XT2S_2 + LFXT1S_2; //XT2频率范围为3MHz到16MHz,ACLK为VLO=12KHz

P3SEL |= 0x06; // Assign I2C pins to USCI_B0
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 |= UCMODE_3 + UCSYNC; // I2C Slave, synchronous mode
UCB0CTL1 |= UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 10; // Set prescaler 1M/10~100KHZ
UCB0BR1 = 0;
UCB0I2COA = 0x0B; // Own Address 0x16>>1
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
UCB0I2CIE |=UCSTPIE + UCSTTIE; // Enable STT, STP interrupt
IE2 |= UCB0RXIE; // Enable RX TX interrupt
P2DIR|=BIT3;//P2.3设置为输出
P2OUT|=BIT3;
P3DIR|=BIT5;//P3.5设置为输出
P3OUT|=BIT5;
__enable_interrupt(); // Enable GIE bit

while(1)
{
P3OUT^=BIT5;
delay_ms(100);
}

}
#pragma vector = USCIAB0RX_VECTOR
__interrupt void USCIAB0RX_ISR(void)
{
RxBuffer[RXByteCtr]= UCB0RXBUF; // Get RX'd byte into buffer
RXByteCtr++;
}