• Resolved

Problem with I2C communication between MSP430F5529 and AD5933

Part Number: MSP430F5529

#define SLAVE_ADDRESS 0x0D /**< Address to AD5933. */
#define BAUD_RATE 12 /**< Baud Rate value. */
#define SDA_PIN 0x00                                    // msp430F5529 UCB0SDA pin
#define SCL_PIN 0x01                                    // msp430F5529 UCB0SCL pin

P1DIR |= BIT1;
P1OUT |= BIT1;
P1OUT ^= (BIT1);   //turn on LED (is turned off when all data for initialization was send)

P3REN |= SDA_PIN + SCL_PIN;
P3OUT |= SDA_PIN + SCL_PIN;
P3SEL |= SDA_PIN + SCL_PIN;                 // 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 = BAUD_RATE;                        // set prescaler
UCB0BR1 = 0;
UCB0I2CSA = SLAVE_ADDRESS;                  // Set slave address
UCB0CTL1 &= ~UCSWRST;                       // Clear SW reset, resume operation
//UCB0IE = UCNACKIE;	//tried with and without this line, there isn't a difference
UCB0IE |= UCTXIE;                           // Enable TX ready interrupt

P1OUT ^= (BIT1);   //turn off LED

while (UCB0STAT & UCBBUSY)
    ;

That is my code. I know that my board works because the LED blinks fine, but I always get stuck in that last while loop.

This code is adapted from MSP430G2553 communication with AD5933 as well, where it worked fine. I did all the necessary ports and pins changes according to the datasheet.

One other difference between this and the other system is that now I am using a MSP-FET Flash Emulation Tool plus a micro UBS to power,  instead of the mini USB port. But I don't know how this may or may not affect my code.

It seems that the STAT of the MSP never changes and the communication isn't established. Can someone help me with it? I don't know what is wrong with my initialization. Maybe the problem is with the interrupts? What should I do?

Thank you all in advance for trying to help me.

  • Hello Gabriela,

    Please see the following application note for debugging I2C issues. Solutions to Common eUSCI and USCI Serial Communication Issues on MSP430 MCUs

    I would also suggest starting from one of our I2C code examples. From your code above a few things are amiss. First, you enable the TX interrupt, but do not have an ISR. This means you will jump to a trap ISR and do nothing. It also means you are not filling the TXBUFF so nothing is sent on the I2C lines. In addition, If you ever do break out of your while statement, your program will end and do nothing else. This means you would send one byte and then do nothing. You need an application loop [while(1)] to ensure the device keeps performing.

    For other I2C debug efforts, please see the application report linked to above.

    Regards,

    JH

                              _____________________________________________________________________


    Search E2E! Your questions may already be answered!

    TI Cloud Tools             MSP Product Page

  • In reply to Jace H:

    Thank you a lot! I checked that AP and I already have tried these solutions they didn't work. The code jumped into a trap ISR sometimes, but just if I delete that while and continue running my code. I don't understand why didn't it happen in MSP430G2553? I wasn't aware of ISR, although I couldn't correct that despite all my efforts.

    I found the I2C code examples but I can't run them either, it gets stuck in:

    __bis_SR_register(LPM0_bits + GIE);     // Enter LPM0, enable interrupts

    I tried to adapt those examples to my code, but I didn't succeed so I try to run the examples for itself they didn't work.

    http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP-EXP430F5529LP/latest/index_FDS.html

    I pick the examples from here, the windows version and the I2C, then I selected the ones that said "This is the MASTER CODE.", for read or write one or multiple bytes.


    My code actually continues, I send the start bit and read data, etc. I just past the code before the loop where it stops. If I solve it there the rest of it should work fine since it worked in MSP43G2553 system.

    I hope you can help me with it, this is my master's project and I am behind the deadline with all those stepbacks.

    Thank you so much for your time!

    Kind regards,

    Gabriela

  • Hello! Could someone help me with this?

  • In reply to Gabriela Costa:

    You are not initializing the ports correctly. The built-in pull-up resistors are too weak for 100 kHz, and the SDA_PIN/SCL_PIN values are wrong (they must use BITx).
  • In reply to Clemens Ladisch:

    Why aren't the ports correct?  What is missing or wrong? Can you please be more specific?
    About the SDA_PIN/SCL_PIN, they are carrect for P3.0 and 3.1 (BIT0/BIT1 = 0x00 / 0x01).

  • In reply to Gabriela Costa:

    msp430‍f5529.h uses alternative facts:

    #define BIT0                   (0x0001)
    #define BIT1                   (0x0002)
    #define BIT2                   (0x0004)
    ...
  • In reply to Clemens Ladisch:

    Also, how do you know that pull-up resistors are too weak for kHz?
    My pull-up resistors are 4.7kOhm each.
    Maybe I have the baud rate wrong, can you tell me how it should be calculated?
  • In reply to Gabriela Costa:

    The internal pull-up resistors are much larger than 4.7 kΩ. If you have external ones, you do not need to enable the internal ones in PxREN.

    The I²C clock frequency is calculated by dividing the clock source's frequency by the divisor value.
  • In reply to Clemens Ladisch:

    Oh right! Thank you :) I changed it, but it didn't solve my problem.
    I am going directly to an ISR trap or the (UCB0STAT & UCBBUSY) is always 0.
  • In reply to Gabriela Costa:

    As Jace already told you, you get an interrupt because you enabled the interrupt.

    Start with a super-simple program that does nothing but doing a one-byte I²C transaction.