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.

TMS320f28027 (master) && MSP430G2553 (slave) SPI

Other Parts Discussed in Thread: TMS320F28027, MSP430G2553

 Hi,

I need advice. (I posted this post in C2000 forum, because I think it's the problem of C2000 initialization sequence).
I was trying to do communication between launchpads mentioned above.. And eventually found a solution:

If I run MSP430 launchpad into debug mode and immediately C2000 launchpad also in debug mode. Then start MSP430 and afterwards the C2000. Since C2000 is master, I check proper work of program in comparison of send and receive data arrays of master. Sometimes I disconnect wires to see if connections breaks as it should.

So it seems that I finally managed to make program work properly, but only with microcontroller startup sequence as above. (If, for example, I run MSP430 first (before starting debug of C2000), data shift occurs, and no more valid data is being transferred in between).

Besides I needed 5 wire system, because in other cases bit shift also occurs (SIMO,MOSI,CS, CLK and common GND).

So the question is: How could I avoid this unwanted bit shift, if in case I forget to follow correct startup sequence, since in prototype mode I will  need a lot of start of new debug sessions.

Thanks in advance.

P.S. I add the code in case someone needs it, I actually took a lot of time until I decided to start using CS, which solved everything in moments.

//###########################################################################
//
// Original Source by S.D.
//
// $TI Release: 2802x C/C++ Header Files V1.26 $
// $Release Date: February 2, 2010 $
//###########################################################################


#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

// Prototype statements for functions found within this file.
// interrupt void ISRTimer2(void);
interrupt void spiTxFifoIsr(void);
interrupt void spiRxFifoIsr(void);
void delay_loop(void);
void spi_fifo_init(void);
void error();

unsigned char sdata[2];     // Send data buffer
unsigned char rdata[2];     // Receive data buffer
Uint16 rdata_point;  // Keep track of where we are
                     // in the data stream to check received data

void main(void)
 {
   Uint16 i;

   InitSysCtrl();

   InitSpiaGpio();


   DINT;
   IER = 0x0000;
   IFR = 0x0000;

   InitPieCtrl();

   InitPieVectTable();

   EALLOW;	// This is needed to write to EALLOW protected registers
   PieVectTable.SPIRXINTA = &spiRxFifoIsr;
   EDIS;   // This is needed to disable write to EALLOW protected registers

   spi_fifo_init();	  // Initialize the SPI only

   for(i=0; i<2; i++)
   {
      sdata[i] = i;
   }
   rdata_point = 0;


   PieCtrlRegs.PIECTRL.bit.ENPIE = 1;   // Enable the PIE block
   PieCtrlRegs.PIEIER6.bit.INTx1=1;     // Enable PIE Group 6, INT 1
   IER=0x20;                            // Enable CPU INT6
   EINT;                                // Enable Global Interrupts


	for(;;)
	{
		 SpiaRegs.SPITXBUF=0;//sdata[0]<<8;      // Send data
		 sdata[0]++;
		 delay_loop();
	}

}

// Some Useful local functions
void delay_loop()
{
    long      i;
    for (i = 0; i < 10000; i++) {}
}

void error(void)
{
    asm("     ESTOP0");	 //Test failed!! Stop!
    for (;;);
}

void spi_fifo_init()
{
// Initialize SPI FIFO registers
   SpiaRegs.SPICCR.bit.SPISWRESET=0; // Reset SPI

   SpiaRegs.SPICCR.all=0x0007;       //16-bit character, Loopback mode
   SpiaRegs.SPICTL.all=0x0017;       //Interrupt enabled, Master/Slave XMIT enabled
   SpiaRegs.SPISTS.all=0x0000;
   SpiaRegs.SPIBRR=0x007d;           // Baud rate
 //  SpiaRegs.SPIFFTX.all=0xC022;      // Enable FIFO's, set TX FIFO level to 2
 //  SpiaRegs.SPIFFRX.all=0x0022;      // Set RX FIFO level to 2
   SpiaRegs.SPIFFCT.all=0x00;
   SpiaRegs.SPIPRI.all=0x0010;

   SpiaRegs.SPICCR.bit.SPISWRESET=1;  // Enable SPI

   SpiaRegs.SPIFFTX.bit.TXFIFO=1;
   SpiaRegs.SPIFFRX.bit.RXFIFORESET=1;
}

interrupt void spiRxFifoIsr(void)
{
    Uint16 i;

	rdata[0]=SpiaRegs.SPIRXBUF;		// Read data

	rdata_point++;
	SpiaRegs.SPIFFRX.bit.RXFFOVFCLR=1;  // Clear Overflow flag
	SpiaRegs.SPIFFRX.bit.RXFFINTCLR=1; 	// Clear Interrupt flag
	PieCtrlRegs.PIEACK.all|=0x20;       // Issue PIE ack
}

/* --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.
 */

#include <msp430.h>

unsigned char gauti1=0;
unsigned int i=0;

int main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  while (!(P1IN & BIT4));                   // If clock sig from mstr stays low,
                                            // it is not yet in SPI mode
  P1SEL = BIT1 + BIT2 + BIT4 + BIT5;
  P1SEL2 = BIT1 + BIT2 + BIT4 + BIT5;
  UCA0CTL1 = UCSWRST;                       // **Put state machine in reset**
  UCA0CTL0 |=  UCSYNC+  UCMSB + UCMODE1;
  UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
  IE2 |= UCA0RXIE;                          // Enable USCI0 RX interrupt

  __bis_SR_register(LPM4_bits + GIE);       // Enter LPM4, enable interrupts
}

// Echo character
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR (void)
{
	i++;

	while (!(IFG2 & UCA0TXIFG));              // USCI_A0 TX buffer ready?

	UCA0TXBUF=0xff;

	switch (i) {
	  case 1:
		  UCA0TXBUF=0xf0;
	 break;
	  case 2:
		  UCA0TXBUF=0xff;

	  break;
	  case 3:
		  UCA0TXBUF=0xab;

      break;
	  case 4:
		  UCA0TXBUF=0xcd;
		  i=0;
	  break;
	  default: i=0; break;
	}
}

  • Hello,

    I am wondering, seems that you are not using SPI FIFO for your code and you use 8-bits characters.

    In this case, did you get the correct value in rdata[0] in spiRxFifoIsr?

    Also, does MSP430 not need Chip Select pin?

    As I know, Master usually will set high and low the CS pin of slave to enable it before transmission.

    I know nothing about MSP430, so please check it.

    Best regards,

    Maria

  • Hello,


    Thank you for concern. I've done a bit different code afterwards, so maybe I'll upload it later. And for your answers- although I was using 1 slave, which should mean that it is not necessary to use CS (STEA) line, but it was crucial to use this line since without it, detection of first bit was often gone wrong so in time (after a few shifts) started to appear different data, than I was sending (fixed data pattern).

    Regards

  • Hello again,

    I want to confirm about your case.

    In your case, the SPI slave (MSP430) runs (sends data) even though there is no SPI Master (C2000)? Is it correct?

    Because normally, SPI Slave gets clock from SPI Master and SPI Master initiates the CS pin to enable the Slave transmission.

    I saw your MSP430 code that you use this line:

    while (!(P1IN & BIT4));

    And the comment said that "If clock sig from mstr stays low, it is not yet in SPI mode"

    Actually, this is a little strange for me.

    However, I think the correct one is you should use while (!(P1IN & BIT5));

    Which P1.5 is USCI_A0 slave transmit enable. This is the Chip Select of MSP430 for SPI (Slave) for USCI_A0.

    This pin should be connected to one of SPI Master pin (C2000 GPIO pin) and in the GPIO initialization of SPI Master, it should be set as HIGH to disable the transmission in the beginning.

    Then before transmission, SPI Master pin that connected to P1.5 of MSP430 will be set as LOW to start the transmission.

    In this case, I think your MSP430 as SPI Slave will not start the transmission before C2000 as SPI Master starts the transmission and you will not miss any bit.

    Hope this helps.

    And if I am wrong, please somebody correct me.

    Best regards,

    Maria