期间用了msp430提供的历程 ,下载运行也会停在while (!(UCB0IFG & UCTXIFG)),用超时机制跳过,重新开始 ,抓取到的波形如下:

只要发起开始信号,SCL就自然变为低电平。
附件是源码
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5,GPIO_PIN2 + GPIO_PIN3,GPIO_PRIMARY_MODULE_FUNCTION);/** Disable the GPIO power-on default high-impedance mode to activate* previously configured port settings*/PMM_unlockLPM5();__delay_cycles(1000);UCB0CTLW0 |= UCSWRST;// Software reset enabledUCB0CTLW0 |= UCMODE_3 | UCMST | UCSYNC; // I2C mode, Master mode, syncUCB0CTLW0 |= UCSSEL_2 ;// Use SMCLK, keep SW resetUCB0BRW = 10;// fSCL = SMCLK/10 = ~100kHzUCB0I2CSA = slaveAddress;// Slave Address is 048hUCB0CTL1 &= ~UCSWRST;// Clear SW reset, resume operation
void I2C_write(unsigned char *TX_buffer, int writeLength)
{
int i = 0;
/* Clear USCI_B0 TX interrupt flag */
UCB0IFG &= ~UCTXIFG; //while (UCB0CTL1 & UCTXSTP);// Ensure stop condition got sent
// Set UCB0 as I2C's TX mode, and send a START condition
// This will also send out the slave address
UCB0CTL1 |= UCTR | UCTXSTT;
//Send the number of "writeLength" bytes out
for (i = 0; i < writeLength; i++) {
/* Wait for TX buffer to empty */
while (!(UCB0IFG & UCTXIFG));
/* Send pointer byte */
UCB0TXBUF = *TX_buffer++;
}
while (!(UCB0IFG & UCTXIFG));
/* Generate Stop condition */
UCB0CTL1 |= UCTXSTP;
/* Wait for Stop to finish */
while (UCB0CTL1 & UCTXSTP);
}
’
Loops:
你用的是哪 款芯片? I/O有没有设置上拉?如果用寄存器的例程是否能正常工作?
TI中文支持网



