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
- }