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.

MSP430F248 IIC模块通讯失败怎么回事?

看了官方示例代码,修改了一下,与EEPROM通讯,总是不成功,下面是我改过的代码,请指点下我这代码问题出在那?

#include "io430.h"
#include "in430.h"

unsigned char TxStr[10],RxStr[10];
unsigned char *PTx,*PRx;
unsigned char TxCnt,RxCnt;

void TX_UCB0_STR(void);                      //字符串发送子程序
void RX_UCB0_STR(void);                     //接收字符串字程序   
void INIT_UCB0(void);                             //初始化IIC子程序

void main(void)
{
WDTCTL=WDTPW+WDTHOLD; //STOP WDT

P1DIR=0xff;
P2DIR=0xff;
P3DIR=0xff;
P4DIR=0xff;
P5DIR=0xff;
P6DIR=0xff;

TxStr[0]=0; //初始化数组前两个字节为EEPROM内存地址
TxStr[1]=0;
TxStr[2]=2;
TxStr[3]=3;
TxStr[4]=4;
TxStr[5]=5;
TxStr[6]=6;
TxStr[7]=7;
TxStr[8]=8;
TxStr[9]=9;
INIT_UCB0();                          //初始化IIC
TX_UCB0_STR();                 //发送字符串
P2OUT=0xff;

}

void INIT_UCB0(void)
{


UCB0CTL1|=UCSWRST;                                                             //软复位置1,开始初始化IIC
P3SEL|=BIT1+BIT2;                                                                      //设定IIC通讯脚
UCB0CTL0|=UCMST+UCMODE_3+UCSYNC;                             //IIC主模式,同步通讯
UCB0CTL1 = UCSSEL_1+UCSWRST;                                   //选用ACLK时钟,保持软复位置1 
UCB0BR0 = 1;                                                                            // fSCL = ACLK/1 = ~32kHz
UCB0BR1 = 0;
UCB0I2CSA |=BIT4+BIT6 ;                                                      // 设置七位地址1010000
UCB0CTL1 &= ~UCSWRST;                                                 // Clear SW reset, 初始化完成,释放IIC模块

}
void TX_UCB0_STR()
{


PTx = TxStr; // 字符串首地址
TxCnt = sizeof TxStr; // 字符串计数
UCB0CTL1 |= UCTR + UCTXSTT;                                           //发送起始信号  +地址+写
while(TxCnt)                                                                          //循环发送
{
while(!(IFG2&UCB0TXIFG));
UCB0TXBUF=*PTx++;
TxCnt--;
}

}