我用msp430f5529控制ds3231时钟芯片,采用IO口模拟I2C,程序正确,时间可以正常工作,
当我用msp430g2553控制ds3231时,也是用IO口模拟I2C,程序基本一样,与5529的程序的唯一区别是时钟不一样,但是G2553却不行,显示为00;请问是什么原因?
5529的时钟程序如下:- #define CPU_F ((double)4000000)
- #define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
- #define delayus(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
- #define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
- #define DelayMS(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
- void clk_init()
- {
- P5SEL |= BIT2+BIT3; // Port select XT2
- UCSCTL6 &= ~XT2OFF; // Enable XT2
- UCSCTL3 |= SELREF_2; // FLLref = REFO
- // Since LFXT1 is not used,
- // sourcing FLL with LFXT1 can cause
- // XT1OFFG flag to set
- UCSCTL4 |= SELA_2; // ACLK=REFO,SMCLK=DCO,MCLK=DCO
- // Loop until XT1,XT2 & DCO stabilizes - in this case loop until XT2 settles
- do
- {
- UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
- // Clear XT2,XT1,DCO fault flags
- SFRIFG1 &= ~OFIFG; // Clear fault flags
- }while (SFRIFG1&OFIFG); // Test oscillator fault flag
- UCSCTL6 &= ~XT2DRIVE0; // Decrease XT2 Drive according to
- // expected frequency
- UCSCTL4 |= SELS_5 + SELM_5; // SMCLK=MCLK=XT2
- UCSCTL5 |= DIVS_2;
- }
复制代码2553的时钟程序如下:- #define CPU_F ((double)16000000)
- #define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
- #define delayus(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
- #define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
- #define DelayMS(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
复制代码- BCSCTL1 = CALBC1_16MHZ; // Set DCO to 1, 8, 12 or 16MHz
- DCOCTL = CALDCO_16MHZ;
复制代码5529现象如下(工作正常):
2553现象如下(一直显示00,i2c工作不正常):
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
这是IIC的程序,不是串口程序,两者的差别就是时钟频率不一样,其他时序都一样
一周热门 更多>