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.
大家好,近来我在学习使用LaunchPad的硬件I2C,我使用了430WARE里的I2C写PCF8574的程序,但是不知道为什么不能够使用。下面是我使用代码:
#include <msp430g2553.h>
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop Watchdog Timer
P1OUT = 0xff;
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST+UCMODE_3+UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2+UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 11; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = 0x40; // Set slave address
P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0
P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
IFG2 &= ~(UCB0TXIFG);
IE2 |= UCB0TXIE; // Enable RX interrupt
__bis_SR_register(GIE); // interrupts enabled
while (1)
{
UCB0CTL1 |= UCTR;
UCB0CTL1 |= UCTXSTT; // I2C TX, start condition
while (UCB0CTL1 & UCTXSTT); // Loop until I2C STT is sent
UCB0CTL1 |= UCTXSTP; // I2C stop condition after 1st TX
while (UCB0CTL1 & UCTXSTP);
}
}
// USCI_B0 Data ISR
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{
UCB0TXBUF = 0x00;
}
上拉电阻我已经接了,PCF8674也测试过是好用的,LaunchPad 换过两块都不能用硬件I2C,我用万用表测得SCL的电压为1.9V,SDA一直为低。当我按过复位键之后,SDA会变为高电平,但过一段时间又会变低。
我还是一名在校学生,能力实在有限,恳请各位的帮助。
楼主,注意了在msp430g2553的launchpad中,I2C的所用到的P1.6管脚还经过一个跳线帽连接到LED上,在进行I2C通信之前,要将这个跳线帽去掉,再试试。