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.

MSP430G2232 硬件I2C配置问题

Other Parts Discussed in Thread: MSP430G2232

MSP430G2232的实际寄存器和《MSP430x2xx Family User's Guide》( slau144j.pdf)这个系列用户手册中的描述完全不一样无法参考,导致在使用I2C通讯的时候不知道如何配置相关寄存器。

请问是否有MSP430G2232  硬件IIC的配置说明?

下面是我按照例官网程写的通过IIC向slave地址为0xAE的设备的Register写入值的函数,请帮忙确认一下下面配置是否有问题。

void I2C_WRITE(int add,int data)

{

P1OUT |=BIT6+BIT7;
P1REN |= BIT6+BIT7;
P1DIR |=BIT6+BIT7;

//SDA和SCL有电阻上拉到VCC,是否还需要上面的设置?

//following is setting for I2C

USICTL0 |= USISWRST;//RESET
USICTL0 |= USIPE6+USIPE7+USIMST ;//P1.6&P1.7 For IIC+MASTER MODE
USICTL1 |= USII2C;//I2C MODE
USICKCTL =USIDIV_3+USISSEL_2+USICKPL;

USICTL0 &= ~USISWRST;//CLEAR RESET BIT

//START
USISRL =0x00;
USICTL0 |= USIGE+USIOE;
USICTL0 &=~USIGE;

//following is for slave address and write/read select
USISRL =0xAE;//slave Address 0XAE,write bit 0
USICNT =0x08;//8bit
while(USICTL1&USIIFG==0);//waiting for all 8 bits shift out
ACK_CHECK();

USISRL = add;//register Address
USICNT =0x08;//8bit
while(USICTL1&USIIFG==0);
ACK_CHECK();

USISRL = data;//data
USICNT =0x08;//8bit
ACK_CHECK();

//STOP
USICTL0|=USIOE;//SDA=OUTPUT
USISRL = 0X00;//MSB=0;
USICNT |=0x01;//USICNT =1 BIT
while (USICTL1&USIIFG==0);//WAITING FOR TRANS COMPLETE
USISRL &= 0xff;//USISRL =1 to drive SDA high
USICTL0 |=USIGE;//TRANSPARENT LATCH EN
USICTL0 &=~(USIGE+USIOE);//LATCH/SDA output disable

}

void ACK_CHECK(void)
{
// following is for ACK check
USICTL0 &= ~USIOE;//INPUT
USICNT =0X01;//1bit ack
while(USICTL1&USIIFG==0);//waiting for ACK
if(USISRL&0X01==1)// if NACK stop
{
I2C_ERROR =1;
}
else
{
I2C_ERROR =0;
}

USICTL0 |= USIOE; //enable output 
}

  • 楼主你好,我也在用MSP430G2232。看到你的帖子,吓我一跳,我详细对比了你附的图和MSP430x2xx Family User's Guide,没发现有什么不同。

    我个人觉得最好的配置说明就是datasheet和MSP430x2xx Family User's Guide,虽然是英文的,不太方便阅读,但是内容是最详细的,也最值得信赖。比很多断章取义的中文资料好多了。