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.

mSP430F2618 spi OR uart?

Other Parts Discussed in Thread: MSP430F2618

Hi,

In MSP430F2618 mixed signal DS pins:

P3.4/UCA0TXD/ UCA0SIMO

P3.5/UCA0RXD/ UCA0SOMI

have same PxSEL configuration that is P3SEL = 1 for both the pins for both UCA0TXD/ UCA0SIMO where we can configure for UART and SPI.

i have clock and SPI init functions are below setted for 9600 baud rate:

int main(void)
{
volatile unsigned int i;

WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
if (CALBC1_8MHZ ==0xFF || CALBC1_8MHZ == 0xFF)
{
while(1); // If calibration constants erased
// do not load, trap CPU!!
}
BCSCTL1 = CALBC1_8MHZ; // Set DCO to 8MHz
DCOCTL = CALBC1_8MHZ;

P1SEL |= 0x00;
P1DIR |= 0x20;
P3SEL |= 0x31;
P3DIR |= 0x01;
P3DIR |= 0x10;
P3DIR &= ~0x20;
//Slave SEL pin P4.4
//// P4SEL &= ~0x10;


UCA0CTL1 |= UCSWRST; // **Put state machine in reset**
UCA0CTL0 |= (UCMST+UCSYNC+UCMSB); // 3-pin, 8-bit SPI master
// Clock polarity high, MSB
UCA0CTL1 |= UCSSEL_2; // SMCLK
UCA0BR0 = 20; // /2 change to /1
UCA0BR1 = 0; //
UCA0MCTL = 0;
UCA0CTL1 &= ~UCSWRST;
IE2 |= UCA0RXIE + UCA0TXIE;

UCA0TXBUF = 0x21;

_BIS_SR(GIE); // Enter LPM4, enable interrupts
}

// Echo character
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCIA0RX_ISR (void)
{
while (!(IFG2 & UCA0RXIFG)); // USCI_A0 TX buffer ready?
UCA0TXBUF = UCA0RXBUF;
}

but my code is not working... i want to configure for SPI how to do? is the baud rate setting fine?

Regards.

  • uma pv said:
    _BIS_SR(GIE); // Enter LPM4, enable interrupts
    }

    in this moment your microcontroler finish executing code  :)

    set   while(1);

    or   some LPM mode for example lpm0 

    ( not lpm3 and lmp4 because you use SMCLK)

  • you have many errors in your code,

    look on example from TI site

    (in this example 32768Hz crystal is used, but you can change clock setting )\

    spi slave

    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2012, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *******************************************************************************
     * 
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    //******************************************************************************
    //   msp430x26x Demo - USCI_A0, SPI 3-Wire Slave Data Echo
    //
    //   Description: SPI slave talks to SPI master using 3-wire mode. Data received
    //   from master is echoed back.  USCI RX ISR is used to handle communication,
    //   CPU normally in LPM4.  Prior to initial data exchange, master pulses
    //   slaves RST for complete reset.
    //   ACLK = 32.768kHz, MCLK = SMCLK = DCO ~ 1048kHz
    //
    //   Use with SPI Master Incremented Data code example.  If the slave is in
    //   debug mode, the reset signal from the master will conflict with slave's
    //   JTAG; to work around, use IAR's "Release JTAG on Go" on slave device.  If
    //   breakpoints are set in slave RX ISR, master must stopped also to avoid
    //   overrunning slave RXBUF.
    //
    //             MSP430F261x/241x
    //             -----------------
    //         /|\|              XIN|-
    //          | |                 |   32kHz xtal
    //          | |             XOUT|-
    // Master---+-|RST              |
    //            |             P3.4|<- Data In (UCA0SIMO)
    //            |                 |
    //            |             P3.5|-> Data Out (UCA0SOMI)
    //            |                 |
    //            |             P3.0|<- Serial Clock In (UCA0CLK)
    //
    //
    //   B. Nisarga
    //   Texas Instruments Inc.
    //   September 2007
    //   Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.42A
    //******************************************************************************
    #include <msp430.h>
    
    
    int main(void)
    {
      volatile unsigned int i;
    
      WDTCTL = WDTPW+WDTHOLD;                   // Stop watchdog timer
      if (CALBC1_1MHZ==0xFF)					// If calibration constant erased
      {											
        while(1);                               // do not load, trap CPU!!	
      }
      DCOCTL = 0;                               // Select lowest DCOx and MODx settings
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
      DCOCTL = CALDCO_1MHZ;
    
      while(!(P3IN&0x01));                      // If clock sig from mstr stays low,
                                                // it is not yet in SPI mode
      P3SEL |= 0x31;                            // P3.5,4,0 option select
      UCA0CTL1 = UCSWRST;                       // **Put state machine in reset**
      UCA0CTL0 |= UCSYNC+UCCKPL+UCMSB;          //3-pin, 8-bit SPI master
      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
      IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt
    
      _BIS_SR(LPM3_bits + GIE);                 // Enter LPM4, enable interrupts
    }
    
    // Echo character
    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCIA0RX_ISR (void)
    {
      while (!(IFG2 & UCA0TXIFG));              // USCI_A0 TX buffer ready?
      UCA0TXBUF = UCA0RXBUF;
    }

    spi master

    /* --COPYRIGHT--,BSD_EX
     * Copyright (c) 2012, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     *
     *******************************************************************************
     * 
     *                       MSP430 CODE EXAMPLE DISCLAIMER
     *
     * MSP430 code examples are self-contained low-level programs that typically
     * demonstrate a single peripheral function or device feature in a highly
     * concise manner. For this the code may rely on the device's power-on default
     * register values and settings such as the clock configuration and care must
     * be taken when combining code from several examples to avoid potential side
     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
     * for an API functional library-approach to peripheral configuration.
     *
     * --/COPYRIGHT--*/
    //******************************************************************************
    //   msp430x26x Demo - USCI_A0, SPI 3-Wire Master Incremented Data
    //
    //   Description: SPI master talks to SPI slave using 3-wire mode. Incrementing
    //   data is sent by the master starting at 0x01. Received data is expected to
    //   be same as the previous transmission.  USCI RX ISR is used to handle
    //   communication with the CPU, normally in LPM0. If high, P1.0 indicates
    //   valid data reception.  Because all execution after LPM0 is in ISRs,
    //   initialization waits for DCO to stabilize against ACLK.
    //   ACLK = 32.768kHz, MCLK = SMCLK = DCO ~ 1048kHz.  BRCLK = SMCLK/2
    //
    //   Use with SPI Slave Data Echo code example.  If slave is in debug mode, P1.1
    //   slave reset signal conflicts with slave's JTAG; to work around, use IAR's
    //   "Release JTAG on Go" on slave device.  If breakpoints are set in
    //   slave RX ISR, master must stopped also to avoid overrunning slave
    //   RXBUF.
    //
    //                    MSP430F261x/241x
    //                 -----------------
    //             /|\|              XIN|-
    //              | |                 |  32kHz xtal
    //              --|RST          XOUT|-
    //                |                 |
    //                |             P3.4|-> Data Out (UCA0SIMO)
    //                |                 |
    //          LED <-|P1.0         P3.5|<- Data In (UCA0SOMI)
    //                |                 |
    //  Slave reset <-|P1.1         P3.0|-> Serial Clock Out (UCA0CLK)
    //
    //
    //   B. Nisarga
    //   Texas Instruments Inc.
    //   September 2007
    //   Built with CCE Version: 3.2.0 and IAR Embedded Workbench Version: 3.42A
    //******************************************************************************
    #include <msp430.h>
    
    unsigned char MST_Data,SLV_Data;
    
    int main(void)
    {
      volatile unsigned int i;
    
      WDTCTL = WDTPW+WDTHOLD;                   // Stop watchdog timer
      if (CALBC1_1MHZ==0xFF)					// If calibration constant erased
      {											
        while(1);                               // do not load, trap CPU!!	
      }
      BCSCTL3 |= XCAP_3;                        // Configure load caps
      DCOCTL = 0;                               // Select lowest DCOx and MODx settings
      BCSCTL1 = CALBC1_1MHZ;                    // Set DCO
      DCOCTL = CALDCO_1MHZ;
    
      // Wait for xtal to stabilize
      do
      {
      IFG1 &= ~OFIFG;                           // Clear OSCFault flag
      for (i = 0x47FF; i > 0; i--);             // Time for flag to set
      }
      while ((IFG1 & OFIFG));                   // OSCFault flag still set?
    
      for(i=2100;i>0;i--);                      // Now with stable ACLK, wait for
                                                // DCO to stabilize.
      P1OUT |= 0x02;                             // P1 setup for LED and slave reset
      P1DIR |= 0x03;                            //
      P3SEL |= 0x31;                            // P3.5,4,0 option select
      UCA0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB;    //3-pin, 8-bit SPI master
      UCA0CTL1 |= UCSSEL_2;                     // SMCLK
      UCA0BR0 = 0x02;                           // /2
      UCA0BR1 = 0;                              //
      UCA0MCTL = 0;                             // No modulation
      UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
      IE2 |= UCA0RXIE;                          // Enable USCI_A0 RX interrupt
    
      P1OUT &= ~0x02;                           // Now with SPI signals initialized,
      P1OUT |= 0x02;                            // reset slave
    
      for(i=50;i>0;i--);                        // Wait for slave to initialize
    
      MST_Data = 0x001;                         // Initialize data values
      SLV_Data = 0x000;                         //
    
      UCA0TXBUF = MST_Data;                     // Transmit first character
    
      _BIS_SR(LPM0_bits + GIE);                 // CPU off, enable interrupts
    }
    
    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCIA0RX_ISR (void)
    {
      volatile unsigned int i;
    
      while (!(IFG2 & UCA0TXIFG));              // USART1 TX buffer ready?
      if (UCA0RXBUF==SLV_Data)                  // Test for correct character RX'd
        P1OUT |= 0x01;                          // If correct, light LED
      else
        P1OUT &= ~0x01;                         // If incorrect, clear LED
    
      MST_Data++;                               // Increment data
      SLV_Data++;
      UCA0TXBUF = MST_Data;                     // Send next value
    
      for(i=30;i>0;i--);                        // Add time between transmissions to
    }                                           // make sure slave can keep up

  • Hi Lukasz,,

    My side i have modified code and i am not able to receive data from UCA0RXBUF = 0x21:

    #include <msp430f2618.h>

    unsigned char MST_Data,data;

    int main(void)
    {
    volatile unsigned int i;

    WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
    if (CALBC1_1MHZ==0xFF) // If calibration constant erased
    {
    while(1); // do not load, trap CPU!!
    }
    // BCSCTL3 |= XCAP_3; // Configure load caps
    DCOCTL = 0; // Select lowest DCOx and MODx settings
    BCSCTL1 = CALBC1_1MHZ; // Set DCO
    DCOCTL = CALDCO_1MHZ;

    // Wait for xtal to stabilize
    do
    {
    IFG1 &= ~OFIFG; // Clear OSCFault flag
    for (i = 0x47FF; i > 0; i--); // Time for flag to set
    }
    while ((IFG1 & OFIFG)); // OSCFault flag still set?

    for(i=2100;i>0;i--); // Now with stable ACLK, wait for
    // DCO to stabilize.
    P1OUT |= 0x02; // P1 setup for LED and slave reset
    P1DIR |= 0x03; //
    P3SEL |= 0x31; // P3.5,4,0 option select
    UCA0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB; //3-pin, 8-bit SPI master
    UCA0CTL1 |= UCSSEL_2; // SMCLK
    UCA0BR0 = 0x02; // /2
    UCA0BR1 = 0; //
    UCA0MCTL = 0; // No modulation
    UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
    IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt

    P1OUT &= ~0x02; // Now with SPI signals initialized,
    P1OUT |= 0x02; // reset slave

    for(i=50;i>0;i--); // Wait for slave to initialize

    MST_Data = 0x21; // Initialize data values
    //SLV_Data = 0x000; //

    UCA0TXBUF = MST_Data; // Transmit first character

    _BIS_SR(LPM0_bits + GIE); // CPU off, enable interrupts
    }

    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCIA0RX_ISR (void)
    {
    volatile unsigned int i;

    while (!(IFG2 & UCA0TXIFG)); // USART1 TX buffer ready?
    data = UCA0RXBUF;
    for(i=30;i>0;i--); // Add time between transmissions to
    }

    no results..please suggest some thing.

  • additionally you should commet this code:

    // Wait for xtal to stabilize
    do
    {
    IFG1 &= ~OFIFG; // Clear OSCFault flag
    for (i = 0x47FF; i > 0; i--); // Time for flag to set
    }
    while ((IFG1 & OFIFG)); // OSCFault flag still set?

    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

    you msp430 workink like a master,

    but your slave is connected correctly ?

  • hi Lukasz ,

    i have connected P4.4 as CS.

    and modified like this:

    unsigned char MST_Data,data;

    int main(void)
    {
    volatile unsigned int i;

    WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
    if (CALBC1_1MHZ==0xFF) // If calibration constant erased
    {
    while(1); // do not load, trap CPU!!
    }
    // BCSCTL3 |= XCAP_3; // Configure load caps
    DCOCTL = 0; // Select lowest DCOx and MODx settings
    BCSCTL1 = CALBC1_1MHZ; // Set DCO
    DCOCTL = CALDCO_1MHZ;

    // Wait for xtal to stabilize
    /* do
    {
    IFG1 &= ~OFIFG; // Clear OSCFault flag
    for (i = 0x47FF; i > 0; i--); // Time for flag to set
    }
    while ((IFG1 & OFIFG)); // OSCFault flag still set?
    */
    for(i=2100;i>0;i--); // Now with stable ACLK, wait for
    // DCO to stabilize.
    // P4OUT |= 0x10; // P1 setup for LED and slave reset

    P4DIR |= 0x10; //
    P3SEL |= 0x31; // P3.5,4,0 option select
    UCA0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB; //3-pin, 8-bit SPI master
    UCA0CTL1 |= UCSSEL_2; // SMCLK
    UCA0BR0 = 0x02; // /2
    UCA0BR1 = 0; //
    UCA0MCTL = 0; // No modulation
    UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
    IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt

    P4OUT &= ~0x10; // Now with SPI signals initialized,
    // reset slave

    for(i=50;i>0;i--); // Wait for slave to initialize

    MST_Data = 0x21; // Initialize data values
    //SLV_Data = 0x000; //

    UCA0TXBUF = MST_Data; // Transmit first character

    _BIS_SR(LPM0_bits + GIE); // CPU off, enable interrupts
    }

    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCIA0RX_ISR (void)
    {
    volatile unsigned int i;

    while (!(IFG2 & UCA0TXIFG)); // USART1 TX buffer ready?
    data = UCA0RXBUF;
    for(i=30;i>0;i--); // Add time between transmissions to
    }

    but still not working

     

  • connection should be like on picture below:

    (check your connection MSP430 - slave chip )

    example for 1 master 3 slaves

  • Hi Lukasz,

    It is same way connected

     

  • check this code:

    (cyclic transmision)

    unsigned char MST_Data,data;
    
    int main(void)
    {
    volatile unsigned int i;
    
    WDTCTL = WDTPW+WDTHOLD; // Stop watchdog timer
    
    if (CALBC1_1MHZ==0xFF) // If calibration constant erased
    {
    while(1); // do not load, trap CPU!!
    }
    
    
    BCSCTL1 = CALBC1_1MHZ; // Set DCO
    DCOCTL  = CALDCO_1MHZ;
    
    
    
    P4OUT |= 0x10; // slave reset
    P4DIR |= 0x10; //
    
    P3SEL |= 0x31; // P3.5,4,0 option select
    UCA0CTL0 |= UCMST+UCSYNC+UCCKPL+UCMSB; //3-pin, 8-bit SPI master
    UCA0CTL1 |= UCSSEL_2; // SMCLK
    UCA0BR0 = 0x02; // /2
    UCA0BR1 = 0; //
    UCA0MCTL = 0; // No modulation
    UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
    IE2 |= UCA0RXIE; // Enable USCI_A0 RX interrupt
    
    P4OUT &=~ 0x10; // Now with SPI signals initialized,
    for(i=50;i>0;i--); // Wait for slave to initialize
    
    MST_Data = 0x21; // Initialize data values
    
      while(1)
      {
         UCA0TXBUF = MST_Data; // Transmit first character
        _BIS_SR(LPM0_bits + GIE); // CPU off, enable interrupts
      }
    }
    
    #pragma vector=USCIAB0RX_VECTOR
    __interrupt void USCIA0RX_ISR (void)
    {
      volatile unsigned int i;
    
      while (!(IFG2 & UCA0TXIFG)); // USART1 TX buffer ready?
      data = UCA0RXBUF;
      for(i=30;i>0;i--); // Add time between transmissions to
    
    __bic_SR_register_on_exit(LPM0_bits);
    
    }

    tell me what kind of type slave device do you use ?

  • Hi Lukasz,

    I have checked  your on my side and the rceive buffer is not updating with transmitter data. 

    I am interfacing flash memory M25P80 to msp430f2618 using USCIA0 in SPI mode where, P4.4 is GPIO acting as CS pin.

     

  • look on memory M25P80 datasheet

    http://pdf.datasheetcatalog.com/datasheet/stmicroelectronics/8495.pdf

    you should work with all memory signals (hold write, protect, cs, spi signals)

    and use correct instructions,

    here I found example how to use M25P80,

    http://senstools.gforge.inria.fr/doxygen/m25p80_8c_source.html

    look on:   init, get signature, etc.

     

     

     

  • Hi Lukasz.

    Thank you so much for your help.

    I ll check out in detail and will be back once i have done every thing.

    Regards.

**Attention** This is a public forum