[讨论] MSP430G2232 硬件I2C配置问题

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

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

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

  2. {

  3. P1OUT |=BIT6+BIT7;
  4. P1REN |= BIT6+BIT7;
  5. P1DIR |=BIT6+BIT7;

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

  7. //following is setting for I2C

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

  12. USICTL0 &= ~USISWRST;//CLEAR RESET BIT

  13. //START
  14. USISRL =0x00;
  15. USICTL0 |= USIGE+USIOE;
  16. USICTL0 &=~USIGE;

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

  22. USISRL = add;//register Address
  23. USICNT =0x08;//8bit
  24. while(USICTL1&USIIFG==0);
  25. ACK_CHECK();

  26. USISRL = data;//data
  27. USICNT =0x08;//8bit
  28. ACK_CHECK();

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

  37. }

  38. void ACK_CHECK(void)
  39. {
  40. // following is for ACK check
  41. USICTL0 &= ~USIOE;//INPUT
  42. USICNT =0X01;//1bit ack
  43. while(USICTL1&USIIFG==0);//waiting for ACK
  44. if(USISRL&0X01==1)// if NACK stop
  45. {
  46. I2C_ERROR =1;
  47. }
  48. else
  49. {
  50. I2C_ERROR =0;
  51. }

  52. USICTL0 |= USIOE; //enable output
  53. }


回复评论

暂无评论,赶紧抢沙发吧
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复