正在弄msp430f5438硬件i2c,可是为什么初始化以后设置UCB0CTL1 |= UCTXSTT+UCTR 都没有起始信号呢,scl和sda线都没任何反应,看了文档觉得初始化都没问题呀,就是找不到原因,贴上代码,还请大家帮我看看哪里有问题。急死我了!运动会口号
void init_iic(void)
{
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2 + UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 20; // fSCL = SMCLK/20 = 400kHz
UCB0BR1 = 0;
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
}
BOOL iic_tx_byte_rx_ack(uint8_t byte)
{
uint8_t retry = 50;
while (--retry)
{
if (UCB0IFG & UCTXIFG)
{
break;
}
else
{
delay_us(2);
}
}
if (retry == 0)
{
return FALSE;
}
UCB0TXBUF = byte; // Write data to TXBUF
while (!UCTXIFG)//1空闲,0繁忙
{
if(UCNACKIFG == 1)
{
return FALSE;
}
}
return TRUE;
}
static BOOL iicBusy = NO;
BOOL iic_write(uint8_t seven_bit_addr, uint8_t *txdata, uint16_t txlen)
{
uint8_t *temp = txdata;
if (iicBusy == YES)
{
return FALSE;
}
iicBusy = YES;
#if 1
while (UCB0CTL1 & UCTXSTP);
UCB0I2CSA =seven_bit_addr;
UCB0CTL1 |= UCTXSTT+UCTR ;
// while(UCB1CTL1 & UCTXSTT) ; uctxstt·ÅÔÚÕâÀï»áËÀÑ»·¡£
while(! (UCB0IFG & UCTXIFG) ) ;
//UCB0TXBUF = seven_bit_addr;
//while(UCB0CTL1 & UCTXSTT) ; //·ÅÔÚÕâÀï¾Íͨ¹ýÁË
#else
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
//while (UCTXSTP);
// I2C TX, start condition
UCB0CTL1 |= UCTR + UCTXSTT;