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: No data coming out of UCB0 - SPI mode

Part Number: MSP430G2553

I'm trying to use UCB0 to talk to an ADC, while also using UCA0 to communicate with a PC via UART, however I can't seem to get anything to come out of P1.7 (SPI Out) on my device, and I also can't get the transmit interrupt to fire.

I've stripped the code right back so I'm not even attempting to set up the UART as well, but still no luck. I've got nothing connected and P1.7 (UCB0SIMO from the datasheet) seems to be floating with no data ever coming out? 

//#include <msp430.h>
#include "msp430g2553.h"

void portCfg()
{
    P1SEL |=  BIT7 + BIT6 + BIT5;
    P1SEL2 |= BIT7 + BIT6 + BIT5;
    P1DIR |= BIT4 + BIT0;
    P2DIR |= BIT0;
    P2OUT |= BIT0;
}

void spiInit()
{
    UCB0CTL1 |= UCSWRST;

    UCB0CTL1 |= 0x02;
    UCB0CTL0 |=  UCMSB + UCMST + UCSYNC;

    UCB0BR0 |= 0x02;
    UCB0BR1 = 0;

    UCB0CTL1 &= ~UCSWRST;

    IE2 |= UCB0TXIE;
}

int main(void)
{
    WDTCTL = WDTPW | WDTHOLD;
	
    portCfg();
    spiInit();

    UCB0TXBUF = 'U';

    _BIS_SR(LPM0 + GIE);
}

#pragma vector = USCIAB0TX_VECTOR
__interrupt void TransmitInterrupt(void)
{
    UCB0TXBUF = 'U';
}

-- Whilst I'm here, is there any definitive guide for using the peripherals, as in, which registers to set up, what they do, all the different codes for various functions and modes? Stitching together bits of example code and scratching my head for hours on end seems to be getting me nowhere, and the datasheet for the micro doesn't list all the registers and shorthand macros I need to use.

  • Hi Jon,

    The best way to start learning how to properly use the on-board peripherals is to import the example code for the peripheral you want to use from the TI Resource Explorer.

    You can reference msp430g2xx3_uscia0_spi_09.c, and other SPI examples provided, to learn how to properly configure and use the USCI SPI peripheral.

    You can then do the same thing for finding UART examples.

    Once you have a grasp on how the two peripherals are properly used you can then port the functionality into your own project and expand upon it from there.

    For detailed information on the registers of the peripherals please refer to the device family user's guide for the MSP430G2553 (http://www.ti.com/lit/ug/slau144j/slau144j.pdf)

    Best regards,

    Matt

  • Hi Matt, thanks for your reply.

    The user guide is the document I've been looking for, that's really helpful.

    Unfortunately however, I still haven't been able to resolve my problem. I've used the code from the SPI example you mentioned, modifying it to refer to UCB0 instead of UCA0, and I'm unable to transmit the stream of data that I'm trying to transmit.

    Any idea what might be wrong with my code? It looks like it should be fairly straightforward...

    The only thing is apparently "UCB0MCTL" doesn't exist, so I've had to ignore this line, maybe I can only set this up on A and not B?
  • Jon,

    There is no UCB0MCTL register because the USCI B0 peripheral does not support UART, that is only on the USCI A0 peripheral.

    Could you please insert the modified example code that you implemented so that I can possibly see where the problem is? The example code has been verified to work properly so if the peripheral and port initialization is correctly ported over to the USCI B0 module then the SPI transmission should be seen on the MOSI pin during a transmission.

    Best regards,

    Matt
  • Yup, that finally clicked after a while...

    After a long and painful day of fiddling I've got it all working perfectly now, thanks for the help Matt :)

**Attention** This is a public forum