在调I2C,只是在示例上更改了从机地址,使用的是AT24C16,但是程序就是死在一个地方,貌似收不到应答信号,求指导!!
就是死在红线的那一句
#include "msp430g2553.h"
#define CPU_F ((double)1000000)
#define delay_us(x) __delay_cycles((long)(CPU_F*(double)x/1000000.0))
#define delay_ms(x) __delay_cycles((long)(CPU_F*(double)x/1000.0))
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop Watchdog Timer
P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0
P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST+UCMODE_3+UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 = UCSSEL_2+UCSWRST; // Use SMCLK, keep SW reset
UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = 0xA0; // Set slave address
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
IE2 |= UCB0RXIE; // Enable RX interrupt
TACCTL0 = CCIE; // TACCR0 interrupt enabled
TACTL = TASSEL_2 + MC_2; // SMCLK, contmode
while (1)
{
__bis_SR_register(CPUOFF + GIE); // CPU off, interrupts enabled
UCB0CTL1 &= ~UCTR; // I2C RX
UCB0CTL1 |= UCTXSTT; // I2C start condition
while (UCB0CTL1 & UCTXSTT); // Loop until I2C STT is sent
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
__bis_SR_register(CPUOFF + GIE); // CPU off, interrupts enabled
while (UCB0CTL1 & UCTXSTT); // Loop until I2C STT is sent
UCB0CTL1 |= UCTXSTP; // I2C stop condition after 1st TX
}
}
#pragma vector = TIMER0_A0_VECTOR
__interrupt void TA0_ISR(void)
{
__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
}
// USCI_B0 Data ISR
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{
UCB0TXBUF = (UCB0RXBUF << 4) | 0x0f; // Move RX data to TX
__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
}
此帖出自
小平头技术问答
一周热门 更多>