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.

SPI interfacing for two F28069 Control sticks

Other Parts Discussed in Thread: CONTROLSUITE

HI

I am trying to communicate between two F28069 control sticks using SPI. I have gone through the spi_loopback examples in control suite and considering it as base,i changed the SPICCR.4 = 0 to disable it and  SPICTL.2=1/0 for master/slave mode.

The connections between two control sticks is as:

Pin24 i.e. Gpio16(master) to pin 24 i.e Gpio 16(slave)  ..... SPISIMOA

Pin20 i.e. Gpio17(master) to pin 20 i.e Gpio 17(slave)  ..... SPISOMIA

Pin29 i.e. Gpio18(master) to pin 29 i.e Gpio 18(slave)  ..... SPICLKA

Pin25 i.e. Gpio19(master) to pin 25 i.e Gpio 19(slave)  ..... SPISISTEA

Please help ,as i m stuck with this for last two days....

thanks

  • Hello,

    I don't have F28069 control sticks.

    But I used C2000 Launchpad (F28027) before to communicate 2 Launchpads via SPI.

    I don't remember the simple codes (Master-slave) that I made so I tried to generate them again for you, however I could not test the code because currently I only have access to one launchpad.

    And the registers setting is using APIs, not directly calling the registers name. But you can always compare the meaning on spi.c that available here C:\TI\controlSUITE\device_support\f2802x\v220\f2802x_common\source and spi.h (C:\TI\controlSUITE\device_support\f2802x\v220\f2802x_common\include)

    I can say to you that the register settings for SPI are the same between F28027 and F28069.

    //#############################################################################
    //
    //  File:   f2802x_examples_ccsv4/spi_loopback_interrupts/Example_F2802xSpi_FFDLB_int.c
    //
    //  Title:  F2802x Device Spi Digital Loop Back with Interrupts Example.
    //
    //  Group:          C2000
    //  Target Device:  TMS320F2802x
    //
    //! \addtogroup example_list
    //!  <h1>SPI Digital Loop Back with Interrupts</h1>
    //!
    //!   This program is a SPI-A example that uses the internal loopback of
    //!   the peripheral.  Both interrupts and the SPI FIFOs are used.
    //!
    //!   A stream of data is sent and then compared to the received stream.
    //!
    //!   The sent data looks like this:
    //!   0000 0001 \n
    //!   0001 0002 \n
    //!   0002 0003 \n
    //!   ....      \n
    //!   FFFE FFFF \n
    //!   FFFF 0000 \n
    //!    etc..
    //!
    //!   This pattern is repeated forever.
    //!
    //!
    //!   Watch Variables:
    //!   - sdata[2] - Data to send
    //!   - rdata[2] - Received data
    //!   - rdata_point - Used to keep track of the last position in
    //!                   the receive stream for error checking.
    //
    //  (C) Copyright 2012, Texas Instruments, Inc.
    //#############################################################################
    // $TI Release: f2802x Support Library v210 $
    // $Release Date: Mon Sep 17 09:13:31 CDT 2012 $
    //#############################################################################
    
    #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
    
    #include "f2802x_common/include/adc.h"
    #include "f2802x_common/include/clk.h"
    #include "f2802x_common/include/flash.h"
    #include "f2802x_common/include/gpio.h"
    #include "f2802x_common/include/pie.h"
    #include "f2802x_common/include/pll.h"
    #include "f2802x_common/include/spi.h"
    #include "f2802x_common/include/wdog.h"
    
    // Prototype statements for functions found within this file.
    // interrupt void ISRTimer2(void);
    //interrupt void spiTxFifoIsr(void);
    //interrupt void spiRxFifoIsr(void);
    interrupt void spiTxIsr(void);
    interrupt void spiRxIsr(void);
    void delay_loop(void);
    void spi_init(void);
    void spi_fifo_init(void);
    void error();
    
    uint16_t sdata;      // Send data buffer
    uint16_t rdata;      // Receive data buffer
    uint16_t rdata_point;   // Keep track of where we are
                            // in the data stream to check received data
    
    #define SLAVE_ACK 111
                         
    ADC_Handle myAdc;
    CLK_Handle myClk;
    FLASH_Handle myFlash;
    GPIO_Handle myGpio;
    PIE_Handle myPie;
    SPI_Handle mySpi;
    
    void main(void)
    {
      //  uint16_t i;
        
        CPU_Handle myCpu;
        PLL_Handle myPll;
        WDOG_Handle myWDog;
        
        // Initialize all the handles needed for this application    
        myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj));
        myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj));
        myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj));
        myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj));
        myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj));
        myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj));
        myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj));
        mySpi = SPI_init((void *)SPIA_BASE_ADDR, sizeof(SPI_Obj));
        myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));
        
        // Perform basic system initialization    
        WDOG_disable(myWDog);
        CLK_enableAdcClock(myClk);
        (*Device_cal)();
        
        //Enable SPI-A Clock
        CLK_enableSpiaClock(myClk);
    
        //Select the internal oscillator 1 as the clock source
        CLK_setOscSrc(myClk, CLK_OscSrc_Internal);
        
        // Setup the PLL for x12 /2 which will yield 60Mhz = 10Mhz * 12 / 2
        PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2);
        
        // Disable the PIE and all interrupts
        PIE_disable(myPie);
        PIE_disableAllInts(myPie);
        CPU_disableGlobalInts(myCpu);
        CPU_clearIntFlags(myCpu);
        
        // If running from flash copy RAM only functions to RAM   
    #ifdef _FLASH
        memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
    #endif   
    
        // Initalize GPIO
        GPIO_setPullUp(myGpio, GPIO_Number_16, GPIO_PullUp_Enable);
        GPIO_setPullUp(myGpio, GPIO_Number_17, GPIO_PullUp_Enable);
        GPIO_setPullUp(myGpio, GPIO_Number_18, GPIO_PullUp_Enable);
        GPIO_setPullUp(myGpio, GPIO_Number_19, GPIO_PullUp_Enable);
        GPIO_setQualification(myGpio, GPIO_Number_16, GPIO_Qual_ASync);
        GPIO_setQualification(myGpio, GPIO_Number_17, GPIO_Qual_ASync);
        GPIO_setQualification(myGpio, GPIO_Number_18, GPIO_Qual_ASync);
        GPIO_setQualification(myGpio, GPIO_Number_19, GPIO_Qual_ASync);
        GPIO_setMode(myGpio, GPIO_Number_16, GPIO_16_Mode_SPISIMOA);
        GPIO_setMode(myGpio, GPIO_Number_17, GPIO_17_Mode_SPISOMIA);
        GPIO_setMode(myGpio, GPIO_Number_18, GPIO_18_Mode_SPICLKA);
        GPIO_setMode(myGpio, GPIO_Number_19, GPIO_19_Mode_SPISTEA_NOT);
    
        // Another Chip Select (CS)
        GPIO_setPullUp(myGpio, GPIO_Number_12, GPIO_PullUp_Enable);
        GPIO_setMode(myGpio, GPIO_Number_12, GPIO_12_Mode_GeneralPurpose);
        GPIO_setDirection(myGpio, GPIO_Number_12, GPIO_Direction_Output );
    
        GPIO_setPullUp(myGpio, GPIO_Number_34, GPIO_PullUp_Enable);
        GPIO_setMode(myGpio, GPIO_Number_34, GPIO_34_Mode_GeneralPurpose);
        GPIO_setDirection(myGpio, GPIO_Number_34, GPIO_Direction_Output );
    
        // Setup a debug vector table and enable the PIE
        PIE_setDebugIntVectorTable(myPie);
        PIE_enable(myPie);
    
        // Register interrupt handlers in the PIE vector table
        //PIE_registerPieIntHandler(myPie, PIE_GroupNumber_6, PIE_SubGroupNumber_1, (intVec_t)&spiRxFifoIsr);
        //PIE_registerPieIntHandler(myPie, PIE_GroupNumber_6, PIE_SubGroupNumber_2, (intVec_t)&spiTxFifoIsr);
        PIE_registerPieIntHandler(myPie, PIE_GroupNumber_6, PIE_SubGroupNumber_1, (intVec_t)&spiRxIsr);
       // PIE_registerPieIntHandler(myPie, PIE_GroupNumber_6, PIE_SubGroupNumber_2, (intVec_t)&spiTxIsr);
    
        // Initialize the SPI only
        spi_init();
    
    
        // Initalize the send data buffer
        //for(i=0; i<2; i++)
        //{
        //  sdata[i] = i;
        //}
        rdata = 0;
        sdata = 222;   // Master
        rdata_point = 0;
    
        // Enable interrupts required for this example
        PIE_enableInt(myPie, PIE_GroupNumber_6, PIE_InterruptSource_SPIARX);
       // PIE_enableInt(myPie, PIE_GroupNumber_6, PIE_InterruptSource_SPIATX);
        CPU_enableInt(myCpu, CPU_IntNumber_6);
        CPU_enableGlobalInts(myCpu);
    
        for(;;) {
    
        	GPIO_setLow(myGpio, GPIO_Number_19); // low SPISTE // Master
        	//GPIO_setLow(myGpio, GPIO_Number_34);
    
        	SPI_write(mySpi, sdata);
    
        	GPIO_setHigh(myGpio, GPIO_Number_19);
        	//GPIO_setHigh(myGpio, GPIO_Number_34);
        	asm(" NOP");
    
        	// Check whether the master receive ACK
        	if(rdata == SLAVE_ACK)
        	{
        		sdata++;					// Master
        		asm(" NOP");
        		asm(" NOP");
        		rdata = 0;
        	}
    
            asm(" NOP");
        }
    
    }
    
    // Some Useful local functions
    void delay_loop()
    {
        long      i;
        
        for (i = 0; i < 1000000; i++) {
        }
        
        return;
    }
    
    void error(void)
    {
        asm("     ESTOP0");     //Test failed!! Stop!
        for (;;){
            asm(" NOP");
        }
    }
    
    
    void spi_init()
    {
    
        SPI_reset(mySpi);
        SPI_enable(mySpi);
    
        // Reset on, rising edge, 16-bit char bits
        SPI_setCharLength(mySpi, SPI_CharLength_16_Bits);
        //SPI_setCharLength(mySpi, SPI_CharLength_8_Bits); // 8 bits
        //SPI_enableLoopBack(mySpi);
        SPI_disableLoopBack(mySpi); // no loopback
    
        // Enable master mode, normal phase,
        // enable talk, and SPI int disabled.
        SPI_setMode(mySpi, SPI_Mode_Master); // MASTER mode
        SPI_enableTx(mySpi);
        SPI_enableOverRunInt(mySpi);
        SPI_enableInt(mySpi);
    
        SPI_setBaudRate(mySpi, (SPI_BaudRate_e)0x63); // 150K baud rate
    
    
    //    // Initialize SPI FIFO registers
        SPI_disableTxFifoEnh(mySpi);
        //SPI_enableFifoEnh(mySpi);
        //SPI_enableChannels(mySpi);
        //SPI_resetTxFifo(mySpi);
        //SPI_clearTxFifoInt(mySpi);
        //SPI_setTxFifoIntLevel(mySpi, SPI_FifoLevel_2_Words);
        //SPI_enableTxFifoInt(mySpi);
    
        //SPI_resetRxFifo(mySpi);
        //SPI_setRxFifoIntLevel(mySpi, SPI_FifoLevel_2_Words);
        //SPI_enableRxFifoInt(mySpi);
        //SPI_clearRxFifoInt(mySpi);
    
        //SPI_setTxDelay(mySpi, 0);
    
        // Set so breakpoints don't disturb xmission
        SPI_setPriority(mySpi, SPI_Priority_FreeRun);
    
        SPI_enable(mySpi);
    
        //SPI_enableTxFifo(mySpi);
        //SPI_enableRxFifo(mySpi);
    
    }
    /*
    interrupt void spiTxIsr(void)
    {
         uint16_t i;
    
            // Send data
            //SPI_write(mySpi, sdata[0]);
    
            // Increment data for next cycle
            sdata[0]++;
    
        // Clear Interrupt flag
        //SPI_clearTxFifoInt(mySpi);
    
    
        // Issue PIE ACK
        PIE_clearInt(myPie, PIE_GroupNumber_6);
    
        return;
    }
    */
    interrupt void spiRxIsr(void)
    {
    
            // Read data
            rdata = SPI_read(mySpi);
    
    
        rdata_point++;
    
        // Clear Overflow flag
        //SPI_clearRxFifoOvf(mySpi);
    
        // Clear Interrupt flag
        //SPI_clearRxFifoInt(mySpi);
    
        // Issue PIE ack
        PIE_clearInt(myPie, PIE_GroupNumber_6);
    
        return;
    }
    
    //===========================================================================
    // No more.
    //===========================================================================
    
    

    //#############################################################################
    //
    //  File:   f2802x_examples_ccsv4/spi_loopback_interrupts/Example_F2802xSpi_FFDLB_int.c
    //
    //  Title:  F2802x Device Spi Digital Loop Back with Interrupts Example.
    //
    //  Group:          C2000
    //  Target Device:  TMS320F2802x
    //
    //! \addtogroup example_list
    //!  <h1>SPI Digital Loop Back with Interrupts</h1>
    //!
    //!   This program is a SPI-A example that uses the internal loopback of
    //!   the peripheral.  Both interrupts and the SPI FIFOs are used.
    //!
    //!   A stream of data is sent and then compared to the received stream.
    //!
    //!   The sent data looks like this:
    //!   0000 0001 \n
    //!   0001 0002 \n
    //!   0002 0003 \n
    //!   ....      \n
    //!   FFFE FFFF \n
    //!   FFFF 0000 \n
    //!    etc..
    //!
    //!   This pattern is repeated forever.
    //!
    //!
    //!   Watch Variables:
    //!   - sdata[2] - Data to send
    //!   - rdata[2] - Received data
    //!   - rdata_point - Used to keep track of the last position in
    //!                   the receive stream for error checking.
    //
    //  (C) Copyright 2012, Texas Instruments, Inc.
    //#############################################################################
    // $TI Release: f2802x Support Library v210 $
    // $Release Date: Mon Sep 17 09:13:31 CDT 2012 $
    //#############################################################################
    
    #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
    
    #include "f2802x_common/include/adc.h"
    #include "f2802x_common/include/clk.h"
    #include "f2802x_common/include/flash.h"
    #include "f2802x_common/include/gpio.h"
    #include "f2802x_common/include/pie.h"
    #include "f2802x_common/include/pll.h"
    #include "f2802x_common/include/spi.h"
    #include "f2802x_common/include/wdog.h"
    
    // Prototype statements for functions found within this file.
    // interrupt void ISRTimer2(void);
    //interrupt void spiTxFifoIsr(void);
    //interrupt void spiRxFifoIsr(void);
    interrupt void spiTxIsr(void);
    interrupt void spiRxIsr(void);
    void delay_loop(void);
    void spi_init(void);
    void spi_fifo_init(void);
    void error();
    
    uint16_t sdata;      // Send data buffer
    uint16_t rdata;      // Receive data buffer
    uint16_t rdata_point;   // Keep track of where we are
                            // in the data stream to check received data
    #define SLAVE_ACK 111;
    
    ADC_Handle myAdc;
    CLK_Handle myClk;
    FLASH_Handle myFlash;
    GPIO_Handle myGpio;
    PIE_Handle myPie;
    SPI_Handle mySpi;
    
    unsigned char rdata_counter = 0;
    
    
    unsigned int dataToMasterSpi1 = 0;
    unsigned int dataToMasterSpi2 = 0;
    
    
    
    
    void main(void)
    {
      //  uint16_t i;
        
        CPU_Handle myCpu;
        PLL_Handle myPll;
        WDOG_Handle myWDog;
        
        // Initialize all the handles needed for this application    
        myAdc = ADC_init((void *)ADC_BASE_ADDR, sizeof(ADC_Obj));
        myClk = CLK_init((void *)CLK_BASE_ADDR, sizeof(CLK_Obj));
        myCpu = CPU_init((void *)NULL, sizeof(CPU_Obj));
        myFlash = FLASH_init((void *)FLASH_BASE_ADDR, sizeof(FLASH_Obj));
        myGpio = GPIO_init((void *)GPIO_BASE_ADDR, sizeof(GPIO_Obj));
        myPie = PIE_init((void *)PIE_BASE_ADDR, sizeof(PIE_Obj));
        myPll = PLL_init((void *)PLL_BASE_ADDR, sizeof(PLL_Obj));
        mySpi = SPI_init((void *)SPIA_BASE_ADDR, sizeof(SPI_Obj));
        myWDog = WDOG_init((void *)WDOG_BASE_ADDR, sizeof(WDOG_Obj));
        
        // Perform basic system initialization    
        WDOG_disable(myWDog);
        CLK_enableAdcClock(myClk);
        (*Device_cal)();
        
        //Enable SPI-A Clock
        CLK_enableSpiaClock(myClk);
    
        //Select the internal oscillator 1 as the clock source
        CLK_setOscSrc(myClk, CLK_OscSrc_Internal);
        
        // Setup the PLL for x12 /2 which will yield 60Mhz = 10Mhz * 12 / 2
        PLL_setup(myPll, PLL_Multiplier_12, PLL_DivideSelect_ClkIn_by_2);
        
        // Disable the PIE and all interrupts
        PIE_disable(myPie);
        PIE_disableAllInts(myPie);
        CPU_disableGlobalInts(myCpu);
        CPU_clearIntFlags(myCpu);
        
        // If running from flash copy RAM only functions to RAM   
    #ifdef _FLASH
        memcpy(&RamfuncsRunStart, &RamfuncsLoadStart, (size_t)&RamfuncsLoadSize);
    #endif   
    
        // Initalize GPIO
        GPIO_setPullUp(myGpio, GPIO_Number_16, GPIO_PullUp_Enable);
        GPIO_setPullUp(myGpio, GPIO_Number_17, GPIO_PullUp_Enable);
        GPIO_setPullUp(myGpio, GPIO_Number_18, GPIO_PullUp_Enable);
        GPIO_setPullUp(myGpio, GPIO_Number_19, GPIO_PullUp_Enable);
    	GPIO_setQualification(myGpio, GPIO_Number_16, GPIO_Qual_ASync);
        GPIO_setQualification(myGpio, GPIO_Number_17, GPIO_Qual_ASync);
        GPIO_setQualification(myGpio, GPIO_Number_18, GPIO_Qual_ASync);
        GPIO_setQualification(myGpio, GPIO_Number_19, GPIO_Qual_ASync);
        GPIO_setMode(myGpio, GPIO_Number_16, GPIO_16_Mode_SPISIMOA);
        GPIO_setMode(myGpio, GPIO_Number_17, GPIO_17_Mode_SPISOMIA);
        GPIO_setMode(myGpio, GPIO_Number_18, GPIO_18_Mode_SPICLKA);
        GPIO_setMode(myGpio, GPIO_Number_19, GPIO_19_Mode_SPISTEA_NOT);
    
        // Another Chip Select (CS)
        GPIO_setPullUp(myGpio, GPIO_Number_12, GPIO_PullUp_Enable);
        GPIO_setMode(myGpio, GPIO_Number_12, GPIO_12_Mode_GeneralPurpose);
        GPIO_setDirection(myGpio, GPIO_Number_12, GPIO_Direction_Output );
    
        // Setup a debug vector table and enable the PIE
        PIE_setDebugIntVectorTable(myPie);
        PIE_enable(myPie);
    
        // Register interrupt handlers in the PIE vector table
        //PIE_registerPieIntHandler(myPie, PIE_GroupNumber_6, PIE_SubGroupNumber_1, (intVec_t)&spiRxFifoIsr);
        //PIE_registerPieIntHandler(myPie, PIE_GroupNumber_6, PIE_SubGroupNumber_2, (intVec_t)&spiTxFifoIsr);
        PIE_registerPieIntHandler(myPie, PIE_GroupNumber_6, PIE_SubGroupNumber_1, (intVec_t)&spiRxIsr);
       // PIE_registerPieIntHandler(myPie, PIE_GroupNumber_6, PIE_SubGroupNumber_2, (intVec_t)&spiTxIsr);
    
        // Initialize the SPI only
        spi_init();
    
    
        // Initalize the send data buffer
        //for(i=0; i<2; i++)
        //{
        //  sdata[i] = i;
        //}
        sdata = 0; // Slave
        //sdata = 222;   // Master
        rdata_point = 100;
    
        // Enable interrupts required for this example
        PIE_enableInt(myPie, PIE_GroupNumber_6, PIE_InterruptSource_SPIARX);
       // PIE_enableInt(myPie, PIE_GroupNumber_6, PIE_InterruptSource_SPIATX);
        CPU_enableInt(myCpu, CPU_IntNumber_6);
        CPU_enableGlobalInts(myCpu);
    
    
        for(;;) {
    
        	//GPIO_setLow(myGpio, GPIO_Number_19); // low SPISTE // Master
        	//GPIO_setLow(myGpio, GPIO_Number_34);
    
    			// 8-bits data
    			dataToMasterSpi1 = 111;
    			//SPI_write8(mySpi, dataToMasterSpi1);
    			SPI_write(mySpi, dataToMasterSpi1); //16 bits data
    
    
    			delay_loop();
    
     //   	SPI_write(mySpi, sdata);
        	//sdata++;				// Master
            asm(" NOP");
            asm(" NOP");
            //sdata = 0;
    
            //GPIO_setHigh(myGpio, GPIO_Number_19); // high SPISTE // Master
            //GPIO_setHigh(myGpio, GPIO_Number_34);
            //asm(" NOP");
    
        }
    }
    
    // Some Useful local functions
    void delay_loop()
    {
        long      i;
        
        for (i = 0; i < 1000000; i++) {
        }
        
        return;
    }
    
    void error(void)
    {
        asm("     ESTOP0");     //Test failed!! Stop!
        for (;;){
            asm(" NOP");
        }
    }
    
    
    void spi_init()
    {
    
        SPI_reset(mySpi);
        SPI_enable(mySpi);
    
        // Reset on, rising edge, 16-bit char bits
        SPI_setCharLength(mySpi, SPI_CharLength_16_Bits);
        //SPI_setCharLength(mySpi, SPI_CharLength_8_Bits); // 8 bits
        //SPI_enableLoopBack(mySpi);
        SPI_disableLoopBack(mySpi); // no loopback
    
        // Enable master mode, normal phase,
        // enable talk, and SPI int disabled.
        //SPI_setMode(mySpi, SPI_Mode_Master); // MASTER mode
        SPI_setMode(mySpi, SPI_Mode_Slave); // SLAVE mode
        SPI_enableTx(mySpi);
        SPI_enableOverRunInt(mySpi);
        SPI_enableInt(mySpi);
    
        //SPI_setBaudRate(mySpi, (SPI_BaudRate_e)0x63); // 150K baud rate
        //SPI_setBaudRate(mySpi, SPI_BaudRate_150_KBaud_60M ); // 150K baud rate
        //SPI_setBaudRate(mySpi, SPI_BaudRate_1_MBaud_60M ); // 1M baud rate
        //SPI_setBaudRate(mySpi, SPI_BaudRate_500_KBaud_60M ); // 500K baud rate
        //SPI_setBaudRate(mySpi, SPI_BaudRate_75_KBaud_60M ); // 75K baud rate
    
    //    // Initialize SPI FIFO registers
        SPI_disableTxFifoEnh(mySpi);
        //SPI_enableFifoEnh(mySpi);
        //SPI_enableChannels(mySpi);
        //SPI_resetTxFifo(mySpi);
        //SPI_clearTxFifoInt(mySpi);
        //SPI_setTxFifoIntLevel(mySpi, SPI_FifoLevel_2_Words);
        //SPI_enableTxFifoInt(mySpi);
    
        //SPI_resetRxFifo(mySpi);
        //SPI_setRxFifoIntLevel(mySpi, SPI_FifoLevel_2_Words);
        //SPI_enableRxFifoInt(mySpi);
        //SPI_clearRxFifoInt(mySpi);
        //SPI_setTxDelay(mySpi, 0);
    
        // Set so breakpoints don't disturb xmission
        SPI_setPriority(mySpi, SPI_Priority_FreeRun);
    
        SPI_enable(mySpi);
    
        //SPI_enableTxFifo(mySpi);
        //SPI_enableRxFifo(mySpi);
    
    }
    /*
    interrupt void spiTxIsr(void)
    {
         uint16_t i;
    
            // Send data
            //SPI_write(mySpi, sdata[0]);
    
            // Increment data for next cycle
            sdata[0]++;
    
        // Clear Interrupt flag
        //SPI_clearTxFifoInt(mySpi);
    
    
        // Issue PIE ACK
        PIE_clearInt(myPie, PIE_GroupNumber_6);
    
        return;
    }
    */
    interrupt void spiRxIsr(void)
    {
    	//  uint16_t i;
    	// Read data 8 bits (1 byte)
    	rdata = SPI_read(mySpi);// & 0xFF;
    
    	rdata_point++;
    
    
        // Clear Overflow flag
        //SPI_clearRxFifoOvf(mySpi);
    
        // Clear Interrupt flag
        //SPI_clearRxFifoInt(mySpi);
    
    
        // Issue PIE ack
        PIE_clearInt(myPie, PIE_GroupNumber_6);
    
        return;
    }
    /*
    interrupt void spiTxFifoIsr(void)
    {
         uint16_t i;
        for(i=0;i<2;i++) {
            // Send data
            SPI_write(mySpi, sdata[i]);
        }
    
        for(i=0;i<2;i++) {
            // Increment data for next cycle
            sdata[i]++;
        }
    
        // Clear Interrupt flag
        SPI_clearTxFifoInt(mySpi); 
        
        // Issue PIE ACK
        PIE_clearInt(myPie, PIE_GroupNumber_6);
        
        return;
    }
    
    interrupt void spiRxFifoIsr(void)
    {
        uint16_t i;
        
        for(i=0;i<2;i++) {
            // Read data
            rdata[i] = SPI_read(mySpi);
        }
        for(i=0;i<2;i++) {
            // Check received data
            if(rdata[i] != rdata_point+i) {
                error();
            }
        }
        
        rdata_point++;
        
        // Clear Overflow flag
        SPI_clearRxFifoOvf(mySpi);
        
        // Clear Interrupt flag
        SPI_clearRxFifoInt(mySpi);
        
        // Issue PIE ack
        PIE_clearInt(myPie, PIE_GroupNumber_6);
        
        return;
    }
    */
    
    //===========================================================================
    // No more.
    //===========================================================================
    
    

    Good luck!

    Best regards,

    Maria

  • Hi Maria

    Thanks for your time and suggestion.I compared the codes given by you to the one I have used.The settings for registers are same as required. I tried to introduce changes at one or two points,but now it shows very random behavior.

    sdata = 0 always for slave n master

    rdata changes for both but only once and then its fixed,but its is never same.

    shouldn't rdata and sdata be same for slave and master always...

    please find attached the screenshots  for the same before and after the program is run.http://e2e.ti.com/cfs-file.ashx/__key/communityserver-discussions-components-</p> <p>1. code for slave</p> <p>files/171/7343.Example_5F00_2806xSpi_5F00_FFDLB.c 

    2. code for master

    files/171/8875.Example_5F00_2806xSpi_5F00_FFDLB.c]

    3. slave_intially

    4. master intially

    5. slave after

    6. master after

    Please do reply..

    Gautam

    Kindly have a look into the code and help me sort out the problem. Waiting for the reply

    thank you

  • Hi maria/Gautam

    find the codes here...i guess not attached before

    1. Slave

    // TI File $Revision: /main/2 $ 
    // Checkin $Date: January 4, 2011   10:03:27 $ 
    //###########################################################################
    //
    // FILE:   Example_2806xSpi_FFDLB.c
    //
    // TITLE:  F2806x Device Spi Digital Loop Back program. 
    //
    // ASSUMPTIONS:
    //
    //    This program requires the F2806x header files. 
    // 
    //    This program uses the internal loop back test mode of the peripheral. 
    //    Other then boot mode pin configuration, no other hardware configuration
    //    is required. 
    //
    //    As supplied, this project is configured for "boot to SARAM" 
    //    operation.  The F2806x Boot Mode table is shown below.  
    //    $Boot_Table:
    //
    //    While an emulator is connected to your device, the TRSTn pin = 1,
    //    which sets the device into EMU_BOOT boot mode. In this mode, the
    //    peripheral boot modes are as follows:
    //
    //      Boot Mode:       EMU_KEY        EMU_BMODE
    //                       (0xD00)	     (0xD01)
    //      ---------------------------------------
    //      Wait             !=0x55AA        X
    //      I/O              0x55AA	         0x0000
    //      SCI              0x55AA	         0x0001
    //      Wait             0x55AA	         0x0002
    //      Get_Mode         0x55AA	         0x0003
    //      SPI              0x55AA	         0x0004
    //      I2C              0x55AA	         0x0005
    //      OTP              0x55AA	         0x0006
    //      ECANA            0x55AA	         0x0007 
    //      SARAM            0x55AA	         0x000A	  <-- "Boot to SARAM"
    //      Flash            0x55AA	         0x000B
    //      Wait             0x55AA          Other
    //
    //   Write EMU_KEY to 0xD00 and EMU_BMODE to 0xD01 via the debugger
    //   according to the Boot Mode Table above. Build/Load project,
    //   Reset the device, and Run example
    //
    //   $End_Boot_Table
    //
    //
    // Description:
    //
    //    This program is a SPI example that uses the internal loopback of
    //    the peripheral.  Interrupts are not used.
    //
    //    A stream of data is sent and then compared to the recieved stream.
    //  
    //    The sent data looks like this:
    //    0000 0001 0002 0003 0004 0005 0006 0007 .... FFFE FFFF
    //
    //    This pattern is repeated forever.  
    //
    //          Watch Variables:         
    //                sdata - sent data
    //                rdata - received data
    //		
    ////###########################################################################		
    // $TI Release: 2806x C/C++ Header Files and Peripheral Examples V1.00 $ 
    // $Release Date: January 11, 2011 $ 
    //###########################################################################
    
    #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
    
    // Prototype statements for functions found within this file.
    // interrupt void ISRTimer2(void);
    void delay_loop(void);
    void spi_xmit(Uint16 a);
    void spi_fifo_init(void);
    void spi_init(void);
    void error(void);
    
    void main(void)
    {
     Uint16 sdata;  // send data
       Uint16 rdata;  // received data
       
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the F2806x_SysCtrl.c file.
       InitSysCtrl();
    
    // Step 2. Initalize GPIO: 
    // This example function is found in the F2806x_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    // InitGpio();  // Skipped for this example  
    // Setup only the GP I/O only for SPI-A functionality
    // This function is found in F2806x_Spi.c
       InitSpiaGpio();
    
    // Step 3. Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts 
       DINT;
    
    // Initialize PIE control registers to their default state.
    // The default state is all PIE interrupts disabled and flags
    // are cleared.  
    // This function is found in the F2806x_PieCtrl.c file.
       InitPieCtrl();
    
    // Disable CPU interrupts and clear all CPU interrupt flags:
       IER = 0x0000;
       IFR = 0x0000;
       
    // Initialize the PIE vector table with pointers to the shell Interrupt 
    // Service Routines (ISR).  
    // This will populate the entire table, even if the interrupt
    // is not used in this example.  This is useful for debug purposes.
    // The shell ISR routines are found in F2806x_DefaultIsr.c.
    // This function is found in F2806x_PieVect.c.
       InitPieVectTable();
    	
    // Step 4. Initialize all the Device Peripherals:
    // This function is found in F2806x_InitPeripherals.c
    // InitPeripherals(); // Not required for this example
       spi_fifo_init();	  // Initialize the Spi FIFO
       spi_init();		  // init SPI
    
    // Step 5. User specific code:
    // Interrupts are not used in this example. 
     	sdata =0x0000;						
       for(;;)
       {    
         // Transmit data
     //    spi_xmit(sdata);
         // Wait until data is received
        SpiaRegs.SPICTL.bit.TALK=0;
      SpiaRegs.SPITXBUF = rdata;
         while(SpiaRegs.SPISTS.bit.INT_FLAG !=1) { } 
         while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { } 			
         // Check against sent data
         rdata = SpiaRegs.SPIRXBUF;				
      if(rdata != sdata) error();
      sdata++;
       }
    } 	
    
    // Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:	
    
    void delay_loop()
    {
        long      i;
        for (i = 0; i < 1000000; i++) {}
    }
    
    void error(void)
    {
        asm("     ESTOP0");						// Test failed!! Stop!
        for (;;);
    }
    
    void spi_init()
    {    
    	SpiaRegs.SPICCR.all =0x000F;	             // Reset on, rising edge, 16-bit char bits  
    	SpiaRegs.SPICTL.all =0x0002;    		     // Enable slave mode, normal phase,
                                                     // enable talk, and SPI int disabled.
    	//SpiaRegs.SPIBRR =0x007F;									
        SpiaRegs.SPICCR.all =0x008F;		         // Relinquish SPI from Reset   
        SpiaRegs.SPIPRI.bit.FREE = 1;  
                      // Set so breakpoints don't disturb xmission
              SpiaRegs.SPIPRI.bit.TRIWIRE = 1;
    }
    void spi_xmit(Uint16 a)
    {
    	
        
     SpiaRegs.SPITXBUF=a;
    }    
    
    void spi_fifo_init()										
    {
    // Initialize SPI FIFO registers
       SpiaRegs.SPIFFTX.all=0xE040;
        SpiaRegs.SPIFFRX.all=0x209F;
        SpiaRegs.SPIFFCT.all=0x0;
    }  
    
    //===========================================================================
    // No more.
    //===========================================================================
    
    

    2. master

    // TI File $Revision: /main/2 $ 
    // Checkin $Date: January 4, 2011   10:03:27 $ 
    //###########################################################################
    //
    // FILE:   Example_2806xSpi_FFDLB.c
    //
    // TITLE:  F2806x Device Spi Digital Loop Back program. 
    //
    // ASSUMPTIONS:
    //
    //    This program requires the F2806x header files. 
    // 
    //    This program uses the internal loop back test mode of the peripheral. 
    //    Other then boot mode pin configuration, no other hardware configuration
    //    is required. 
    //
    //    As supplied, this project is configured for "boot to SARAM" 
    //    operation.  The F2806x Boot Mode table is shown below.  
    //    $Boot_Table:
    //
    //    While an emulator is connected to your device, the TRSTn pin = 1,
    //    which sets the device into EMU_BOOT boot mode. In this mode, the
    //    peripheral boot modes are as follows:
    //
    //      Boot Mode:       EMU_KEY        EMU_BMODE
    //                       (0xD00)	     (0xD01)
    //      ---------------------------------------
    //      Wait             !=0x55AA        X
    //      I/O              0x55AA	         0x0000
    //      SCI              0x55AA	         0x0001
    //      Wait             0x55AA	         0x0002
    //      Get_Mode         0x55AA	         0x0003
    //      SPI              0x55AA	         0x0004
    //      I2C              0x55AA	         0x0005
    //      OTP              0x55AA	         0x0006
    //      ECANA            0x55AA	         0x0007 
    //      SARAM            0x55AA	         0x000A	  <-- "Boot to SARAM"
    //      Flash            0x55AA	         0x000B
    //      Wait             0x55AA          Other
    //
    //   Write EMU_KEY to 0xD00 and EMU_BMODE to 0xD01 via the debugger
    //   according to the Boot Mode Table above. Build/Load project,
    //   Reset the device, and Run example
    //
    //   $End_Boot_Table
    //
    //
    // Description:
    //
    //    This program is a SPI example that uses the internal loopback of
    //    the peripheral.  Interrupts are not used.
    //
    //    A stream of data is sent and then compared to the recieved stream.
    //  
    //    The sent data looks like this:
    //    0000 0001 0002 0003 0004 0005 0006 0007 .... FFFE FFFF
    //
    //    This pattern is repeated forever.  
    //
    //          Watch Variables:         
    //                sdata - sent data
    //                rdata - received data
    //		
    ////###########################################################################		
    // $TI Release: 2806x C/C++ Header Files and Peripheral Examples V1.00 $ 
    // $Release Date: January 11, 2011 $ 
    //###########################################################################
    
    #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
    
    // Prototype statements for functions found within this file.
    // interrupt void ISRTimer2(void);
    void delay_loop(void);
    void spi_xmit(Uint16 a);
    void spi_fifo_init(void);
    void spi_init(void);
    void error(void);
    
    void main(void)
    {
       Uint16 sdata;  // send data
       Uint16 rdata;  // received data
       
       
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the F2806x_SysCtrl.c file.
       InitSysCtrl();
    
    // Step 2. Initalize GPIO: 
    // This example function is found in the F2806x_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    // InitGpio();  // Skipped for this example  
    // Setup only the GP I/O only for SPI-A functionality
    // This function is found in F2806x_Spi.c
       InitSpiaGpio();
    
    // Step 3. Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts 
       DINT;
    
    // Initialize PIE control registers to their default state.
    // The default state is all PIE interrupts disabled and flags
    // are cleared.  
    // This function is found in the F2806x_PieCtrl.c file.
       InitPieCtrl();
    
    // Disable CPU interrupts and clear all CPU interrupt flags:
       IER = 0x0000;
       IFR = 0x0000;
       
    // Initialize the PIE vector table with pointers to the shell Interrupt 
    // Service Routines (ISR).  
    // This will populate the entire table, even if the interrupt
    // is not used in this example.  This is useful for debug purposes.
    // The shell ISR routines are found in F2806x_DefaultIsr.c.
    // This function is found in F2806x_PieVect.c.
       InitPieVectTable();
    	
    // Step 4. Initialize all the Device Peripherals:
    // This function is found in F2806x_InitPeripherals.c
    // InitPeripherals(); // Not required for this example
       spi_fifo_init();	  // Initialize the Spi FIFO
       spi_init();		  // init SPI
    
    // Step 5. User specific code:
    // Interrupts are not used in this example. 
     	sdata =0x0000;					
       for(;;)
       {    
         // Transmit data
         spi_xmit(sdata);
       SpiaRegs.SPICTL.bit.TALK=1;
         SpiaRegs.SPITXBUF = sdata;
         // Wait until data is received
         while(SpiaRegs.SPISTS.bit.INT_FLAG !=1) { } 	
         while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { } 		
         // Check against sent data
         rdata = SpiaRegs.SPIRXBUF;				
        if(rdata != sdata) error();
        sdata++;
       }
      
    } 	
    
    // Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:	
    
    void delay_loop()
    {
        long      i;
        for (i = 0; i < 1000000; i++) {}
    }
    
    void error(void)
    {
        asm("     ESTOP0");						// Test failed!! Stop!
        for (;;);
    }
    
    void spi_init()
    {    
    	SpiaRegs.SPICCR.all =0x000F;	             // Reset on, rising edge, 16-bit char bits,loopback disabled  
    	SpiaRegs.SPICTL.all =0x0006;    		     // Enable master mode, normal phase,
                                                  // enable talk, and SPI int disabled.
    	SpiaRegs.SPIBRR =0x007F;									
        SpiaRegs.SPICCR.all =0x008F;		         // Relinquish SPI from Reset   
        SpiaRegs.SPIPRI.bit.FREE = 1;  
                      // Set so breakpoints don't disturb xmission
       
    }
    
    void spi_xmit(Uint16 a)
    {
           SpiaRegs.SPITXBUF=a;
    }    
    
    void spi_fifo_init()										
    {
    // Initialize SPI FIFO registers
        SpiaRegs.SPIFFTX.all=0xE040;
       SpiaRegs.SPIFFRX.all=0x2044;
        SpiaRegs.SPIFFCT.all=0x0;
        
    }  
    
    //===========================================================================
    // No more.
    //===========================================================================
    
    

  • Hello Sneha,

    Can you modify SPIFFRX initialization for both Master and Slave to be:

    SpiaRegs.SPIFFRX.all=0x2041;

    Best regards,

    Maria

  • Hi Maria

    I modified SPIFFRX initialization for both master and slave.But it lead to nowhere.

    1. Still sdata=0 for both master and slave..

    2. rdata is different. shouldnt sdata of master = rdata of slave.

    3. individually running the programs on two control sticks gives the same value for rdata but sdata=0. So is there a problem with the transmission?

    4. Am I really going wright with the connections?I am doing like this..

    - connecting stick 1 to PC1 

    - connecting header pin 24 of master to pin 24 of slave ....SIMO

    header pin 20 of master to pin 20 of slave ....SOMI

    header pin 25 of master to pin 25 of slave ....SPISTEA

    header pin 29 of master to pin 29of slave ....SCLK

    -connecting stick 2 to PC2

    -running code for master on istick 1 attached to PC1 and running code for slave on stick 2 attached to PC2.

    -observing watch variables for them on the two PC's.

    kindly spare your time to have a look into it.

    Gautam can you help out

    thanks

  • Hi Sneha,

    Have you connected a ground between the two boards? Ensuring that the two boards have the same ground reference is necessary for proper SPI operation.

    Regards,

    Sam

  • Hi Sam

    No I haven't.Do you mean I need to connect ground pins of both the control sticks together.

    thanks

  • HI sam

    I did that but in vain... :(

    Please help me with this...Its been two weeks for this simple code..How will I proceed ahead then..

    Gautam/Maria/Frank

    Please have a look at the problem.

    Thanks

  • Hi

    after testing it again and again with so many possibilities,i strongly feels there is a probem with the transmission.I get the same result for the watch variable rdata both for slave/master..whether they are connected together or the program is run individually on them..

    kindly suggest something...

    Thanks

  • Hello,

    Did you solve your problem?

    Btw, how about you set low the SPISTE pin before transmit (in master)

    GPIO_setLow(myGpio, GPIO_Number_19); // low SPISTE // Master


    Maybe this will help.

    Best regards,

    Maria

  • Hi Maria

    It's not solved yet. I will try out the above changes.

    thanks

  • Hi

    Can anyone send me the application note for communication interface for piccolo series,having an explanation for SPI n SCI..

    SPI is synchronous and SCI asynchrous,so is it that SCI would be used between two processors for communication and SPI for on board communication? 

  • Hi Sneha,

    Sneha Thakur said:
    Can anyone send me the application note for communication interface for piccolo series,having an explanation for SPI n SCI..

    As far as my knowledge, I've not heard of any app note for the above peripherals. All you've is example codes and peripheral datasheets and example description documentation.

    Sneha Thakur said:
    SPI is synchronous and SCI asynchrous,so is it that SCI would be used between two processors for communication and SPI for on board communication? 

    You can use both the comunication peripherals for the above purposes. I've tried SPI & SCI communication between F28335 and F28027/F28069 and they work very well. I don't have those codes with me right now as they were my early experiments. I've also used SCI for communication between C2000 and Microchip 16F/18F/24F& Atmel Tiny/Atmega series. I'm very satisfied with their performance.

    Regards,

    Gautam