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.

LM4F232和MSP430 之间的I2C通信

Other Parts Discussed in Thread: MSP430G2553

大家好!我想尝试一下LM4F232和MSP430g2553之间的I2C通信。M4不断发送数据给430,以下是我的代码:

(1)M4 做主机(代码是修改ivaWare\examples\peripherals\i2c的)

#define SLAVE_ADDRESS 0x48

int

main(void)

{

SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |

                   SYSCTL_XTAL_16MHZ);

SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);       //I2C0 enablePB[3:2]

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

GPIOPinConfigure(GPIO_PB2_I2C0SCL);

GPIOPinConfigure(GPIO_PB3_I2C0SDA);

GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3);

 HWREG(I2C0_MASTER_BASE + I2C_O_MCR) |= 0x01;

I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false);       // Initialize the I2C0 master module. I2C data transfer rate.

I2CSlaveEnable(I2C0_SLAVE_BASE);     // Set the slave address to SLAVE_ADDRESS.

 I2CSlaveInit(I2C0_SLAVE_BASE, SLAVE_ADDRESS);

 I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, false);

while(1)

    {

        I2CMasterDataPut(I2C0_MASTER_BASE, 0x55);

        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);

        while(!(I2CSlaveStatus(I2C0_SLAVE_BASE) & I2C_SCSR_RREQ))

               {

               }

   }

}

(2)MSP430的代码

#include"msp430g2553.h"

unsignedcharRXData;

voidmain(void)

{

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  P1DIR |= BIT0;                                               // P1.0 output

  P1SEL |= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0

  P1SEL2|= BIT6 + BIT7;                     // Assign I2C pins to USCI_B0

   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

  UCB0I2CIE |= UCSTTIE;                     // Enable STT interrupt

  IE2 |= UCB0TXIE;                          // Enable TX interrupt

//  TXData = 0xff;                            // Used to hold TX data

 while (1)

  {

    __bis_SR_register(CPUOFF + GIE);        // Enter LPM0 w/ interrupts

  }

}

// USCI_B0 State ISR

#pragma vector = USCIAB0TX_VECTOR

__interruptvoidUSCIAB0RX_ISR(void)

{

RXData = UCB0RXBUF;                       // Get RX data

  __bic_SR_register_on_exit(CPUOFF);        // Exit LPM0

}

现在我的情况是SCL和SDA没有波形,全部为低电平(我已将上拉电阻焊上了),我不知道哪里的问题,通信没有成功。请大家帮忙看看!