用169做主机发送数据,然后用5529接收数据,现在发现169在发送数据,但是在5529中怎么也进不了接收数据的中断,上拉电阻也加了,大神们给点意见啊,附上代码:169主机的代码:#include <msp430.h>/file:///C:UsersADMINI~1AppDataLocalTemp)QN1UH78VKP2T7)IA]ZM(FW.gifar TXData = 0;
int main (void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL |= 0x0A; // Select I2C pins
P1OUT |= 0x00;
U0CTL |= I2C + SYNC; // Recommended init procedure
U0CTL &= ~I2CEN; // Recommended init procedure
I2CTCTL |= I2CSSEL1; // SMCLK
I2CNDAT = 0x01; // Write one byte
I2CSA = 0x0048; // Slave Address is 048h
I2CIE = TXRDYIE; // Enable RXRDYIFG interrupt
U0CTL |= I2CEN; // Enable I2C
// I2CDCTL |=0x00;
__enable_interrupt(); // Enable interrupts
while (1)
{
U0CTL |= MST; // Master mode
I2CTCTL |= I2CSTT + I2CSTP + I2CTRX; // Initiate transfer
__bis_SR_register(CPUOFF); // Enter LPM0
}
}
// Common ISR for I2C Module
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USART0TX_VECTOR
__interrupt void I2C_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USART0TX_VECTOR))) I2C_ISR (void)
#else
#error Compiler not supported!
#endif
{
I2CDRB = 0x5A; // TX data
while (I2CBUSY & I2CDCTL); // I2C ready?
P1OUT |= 0x01;
P1DIR |= 0x01;
__bic_SR_register_on_exit(CPUOFF); // Clear LPM0
}
5529从机的代码:
#include <msp430.h>
volatile unsigned char RXData;
int main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3SEL |= 0x03; // Assign I2C pins to USCI_B0
P1OUT = 0;
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMODE_3 + UCSYNC; // I2C Slave, synchronous mode
UCB0I2COA = 0x48; // Own Address is 048h
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
UCB0IE |= UCRXIE; // Enable RX interrupt
while (1)
{
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0, enable interrupts(就停在这里了)
__no_operation(); // Set breakpoint >>here<< and read
} // RXData
}
// USCI_B0 Data ISR
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector = USCI_B0_VECTOR
__interrupt void USCI_B0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCI_B0_ISR (void)
#else
#error Compiler not supported!
#endif
{ // Vector 10: RXIFG
RXData = UCB0RXBUF; // Get RX data
P1DIR |= 0X01;
P1OUT =0x01;
__bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
}
此帖出自
小平头技术问答
推荐你看个帖子,很有用的,但是不是中断模式,是轮询模式
MSP430F5438 I2C学习笔记——AT24C02
http://bbs.eeworld.com.cn/forum. ... &fromuid=698700
(出处: 电子工程世界-论坛)
我有硬件I2C轮询成功的代码,你看看你需不需要
一周热门 更多>