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.

USART/SPI init

Other Parts Discussed in Thread: MSP430AFE253

U0CTL |= SWRST; 

ME1 |= USPIE0;
U0TCTL = CKPH+SSEL1+SSEL0+STC;
U0CTL = CHAR+SYNC+MM; 
U0BR0 = 0x02;
U0BR1 = 0x0; // 0
U0MCTL = 0x00; // no modulation

U0CTL &= ~SWRST;

I can't transmit data without SPI. May be i doing something wrong...

  • Instead of this...

    Aleksey Cherepanov said:
    U0CTL = CHAR+SYNC+MM; 

    Try this...

    U0CTL = CHAR+SYNC+MM+SWRST;

    Also be sure you have assigned the SIMO, SOMI, SCLK, etc pins to the USCI using the PxSEL register(s).

    To transmit, write to U0TXBUF.

    Jeff

  • The code does not switch the MSP pins to USART function.
    You'll need something like PxSEL |= 0xyy, so the pins go from GPIO mode to USART mode. See description of the digital I/O ports in the users guide and the por tpin schematics in the device datasheet.

    Also, SPI is give-and.take. To receive a byte, you'll have to send a byte. If you're not sending, the USART won't generate a clock signal and you're not receiving.

  • At this point I do not have the device receiving the signal SPI, connected only an oscilloscope.

    This full code:

    #include "msp430.h"

    void main( void )
    {
    WDTCTL = WDTPW + WDTHOLD; 

    while(FLL_CTL0 & 3 ); 

    U0CTL |= SWRST;

    P1SEL |= BIT6 + BIT7;
    P2SEL |= BIT1; 
    // U0CTL &= ~SPB; 

    ME1 |= USPIE0;// USPIE1; 
    U0TCTL = CKPH+SSEL1+SSEL0+STC; 
    U0CTL = CHAR+SYNC+MM+SWRST;
    U0BR0 = 0x02;
    U0BR1 = 0x0;
    U0MCTL = 0x00; 

    U0CTL &= ~SWRST; 

    for (;;) {
    while (!(IFG1 & UTXIFG0));
    U0TXBUF = 0x35;
    }

    }

  • Aleksey Cherepanov said:
    P1SEL |= BIT6 + BIT7;

    Without knowing your MSP model, I cannot tell whether your init is correct. I can only guess from FLL_CTL0 that it is a 4x family device.
    And 'U0CTL' indicates that it is one with the USART module.
    IIRC, on USART; you'll not only have to set the PxSEL bits, but also set the proper port pin direction with PxDIR. But I'm not sure about this. (The USCI module does this automatically)

  • Hello,
    I coded this init_SPI() function for my MSP430AFE253 which has USART module, but I cannot get any signal out of the pin (checking with oscillo).
    I do put a char in U0TXBUF but i never see it going out ...
    Would you have any advice for me ?
    void init_SPI() //Config USART for SPI on MSP430AFE253
    {
    
    
    /* 1. Software Reset Enable */
    U0CTL =  SWRST;
    
    
    /* 2. Initialize USART registers */
    
    
    // 8bit data, SPI mode, USART is Master
    U0CTL |= CHAR + SYNC + MM;
    
    
    // Polarity CPOL=0, Phase CPHA = 1
    // BRCLK source is SMCLK, 4pin mode (STE enabled)
    U0TCTL = CKPH + SSEL1;
    
    
    // USART Baud Rate Control Register
    U0BR0 = 0x02; // Config. Baud Rate as UCLK/2
    U0BR1 = 0;
    U0MCTL = 0;
    
    
    /* 3. Enable USART Module*/
    // USART0 SPI Module Enable
    ME1 |= USPIE0;
    
    
    /* 4. Clear SWRST */
    // Initialize USART state machine, SPI enable
    U0CTL &= ~SWRST;
    
    
    /* 5. Interrupts */
    IE1 |= UTXIE0 + URXIE0;  // TX and RX interrupt enable
    
    
    
    
    /* Pin Function selection */
    
    
    //P1.5 as SPI_MOSI
    //P1.6 as SPI_MISO
    //P1.7 as SPI_CLK
    P1SEL  |= BIT5 + BIT6 + BIT7;
    
    
    //P2.0 as SPI_CS
    P2SEL  |= BIT0;
    
    
    /* Pin Direction */
    P1DIR |= BIT5 + BIT6 + BIT7;
    P2DIR |= BIT0;
    }
  • Pfister Frederic said:
    P1DIR |= BIT5 + BIT6 + BIT7;

    You surely won't MISO being an output :) BIT6 is wrong here. But the USART is overriding it anyway.

    When a FET is attached and is operated in 4-wire JTAG mode (TEST pin high) all three pins are unavailable for USART operation.

    Pfister Frederic said:
    U0TCTL = CKPH + SSEL1;

    Sure about CKPH? Most SPI slaves rerequire inactive-high signal (CKPL) but not CKPH.
    YOu also select ACLK as clock source. Is ACLK clocked at all?

    Then you don't set STC. This means that STE is active. STE is an input to the USART and will shut-up the USART if STE is low. It is no output and not used to 'select' the slave.

    Unless you operate as slave in multi-slave or as master in multi-master configuration, you should use 3-wire mode by setting STC bit. The slave chip select must be done with normal GPIO by software anyway. Sicne there are many slaves possible on one SPI bus, teh USART doesn't know which one you want to access. Controlling the slave chip select is to be done by the application software, depending on the 'high-level protocol' the slave expects.

  • Thanks a lot Jens-Michael Gross, 

    I actually didn't understand that STE was an input to the MSP But now I see, and this explains why I didn't get any signal out of my MCU...

    Yes my SPI Slave requires CKPH, and the Clock is set to SMCLK with SSEL1 (BIT5).

    And I did find a working configuration , I post it for anyone who might need it :

    void halSPISetup(void)
    {
    UCTL0 = CHAR + SYNC + MM + SWRST; // 8-bit SPI Master **SWRST**
    UTCTL0 = CKPH + SSEL1 + SSEL0 + STC; // SMCLK, 3-pin mode
    UBR00 = 0x02; // UCLK/2
    UBR10 = 0x00; // 0
    UMCTL0 = 0x00; // No modulation
    ME1 |= USPIE0; // Enable USART0 SPI mode
    UCTL0 &= ~SWRST; // Initialize USART state machine
    }

    It can be found in the library used in slaa281b, check it out...

    Anyway now I need to get my slave responding back to me .. 

  • Pfister Frederic said:
    Yes my SPI Slave requires CKPH.

    Sure? Note that TI (MSP) polarity is reverse to the Motorola polarity.So when a device requires polarity set, you usually don't have to set CKPL and v.v.

    Pfister Frederic said:
    Yes my SPI Slave requires CKPH, and the Clock is set to SMCLK with SSEL1 (BIT5).

    Ah, sorry, I confused SSEL1 with SSEL_1m, which is mor ecommonly used as it enumerates the different bit combinations instead of combining bits. It also allows using SSEL_0, which won't set a bit at all btui still describe that you intentionally selected this and not just forgot to pick a clock.

    Pfister Frederic said:
    Anyway now I need to get my slave responding back to me .. 

    Be nice to him and he will. My slave always does. Sometimes it needs a slash with a whip, but he always responds to me :)

**Attention** This is a public forum