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.

MSP430G2553: SPI (polling) Question

Part Number: MSP430G2553

I recently ran into a problem in using a G2553 in spi mode (polling)
and connected to a 74HC595 shift register. The problem was I was not
getting the bit QA on the 595 to load. I was able to fix the problem
by changing: while((IFG2 & UCA0TXIFG) == 0); to: while(IFG2 & UCA0TXIFG == 0);
Can someone please explain the difference between the two?
Also, I have noticed that: while((IFG2 & UCA0TXIFG) == 0); seems to work in IIC mode
but not in SPI.

Thanks.

  • The command while((IFG2 & UCA0TXIFG) == 0); evaluates if the IFG2 bit of UCA0TXIFG is equal to zero whereas while(IFG2 & UCA0TXIFG == 0); evaluates if UCA0TXIFG is equal to zero and operational ANDs that value with IFG2 to see if the result is true or false. The former is the correct method to evaluate whether UCA0TXIFG is empty and ready to be populated with another character but is more commonly written as while (!(IFG2 & UCA0TXIFG)); for efficiency. UCA0 does not have an I2C mode. Does the solution work if using interrupts instead?

    Regards,
    Ryan
  • Actually I am using a timer interrupt (along with a port interrupt) to track the position of
    a quadrature encoder (every 5ms) and send the positon data to a 74hc595 using the spi. The UCA0TXBUF is contained within
    this interrupt. What I initially discovered on the spi using an oscilloscope was the data and clock were working
    correctly but the negative latch pulse (software generated) was shifted one clock pulse over (7th position).
    This would explain why I was missing the data on bit0 of the 595. Changing the polling method to
    while(IFG2 & UCA0TXIFG == 0); shifted the latch pulse to the 8th clock pulse and the program now does work.
    I did try using: while (!(IFG2 & UCA0TXIFG));, sorry to say that did not work either.
    I have been using the TI launchpad for only several months and am still learning how to use it after being
    a Freescale/Nxp user.

    You are correct about UCA0 and I2C. I meant to say UCB0 instead, and while((IFG2 & UCB0TXIFG) == 0);
    does work in my I2C applications.

    Thanks for your explanation.
    John
  • With the latch pulse shift behavior it may be the case that the SPI clock phase and polarity settings are inverted from what they should be on the MSP430 USCI CTL0 register.

    Regards,
    Ryan
  • I was able to get my program working using: while (!(IFG2 & UCA0TXIFG));
    I changed the way that I was generating (in software) the 74HC595 negative latch pulse.
    Doing it the correct way also allows the sending of multiple bytes.
    I verified that the pulse position was correct with an oscilloscope.
    Maybe my solution can help someone else.
    Thanks again.
    John

    //check encoder value and update spi value every 5 ms
    #pragma vector = TIMER1_A0_VECTOR
    interrupt void timer1_A0_irq (void)

    {
    encoder_2 = (P2IN & 0x06);
    //pull 595 output latch low
    P1OUT &= ~BIT5;
    //send data to shift register
    UCA0TXBUF = spi_data[encoder_value];
    //set 595 output latch high
    P1OUT |= BIT5;
    //flag set when data buffer empty
    while(!(IFG2 & UCA0TXIFG));
    }

**Attention** This is a public forum