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 Loopback Example for F28377S Launchpad

Other Parts Discussed in Thread: CONTROLSUITE

Dear TI Team,

I am using the F28377S-LaunchPad XL with a simple SPI device.  I need to send 16 bits at a time to set a value in a potentiometer.  I started working with the example spi_loopack_cpu1 in ControlSuite to keep everything simple.

I checked the SCK output (GPIO 18 pin 76) with an oscilloscope and had 16 distinct peaks at ~3.2-3.3V.  I tried a few examples with sdata = 1, then = 3, then = 8 and everything looked fine.  But when I used a value of 43690 (binary: 1010101010101010),  the SPISIMOA (GPIO16 pin 36) had the following output:

As a result, I start losing values.  It seems to be able to handle 3 or 4 cycles up/down but any more and it drops to 1.8V.

Can you please advise what steps I can do to correct this?

Many thanks...

Source code that was used (no changes to library files) below:

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

// Prototype statements for functions found within this file.

// __interrupt void ISRTimer2(void);

void spi_xmit(Uint16 a);

void spi_fifo_init(void);

void spi_init(void);

int CSPin = 14;  // needed for external device

void main(void)

{

GPIO_SetupPinMux(CSPin, GPIO_MUX_CPU1, 0);

GPIO_SetupPinOptions(CSPin, GPIO_OUTPUT, GPIO_PUSHPULL);

GPIO_WritePin(CSPin, 1); // note circuit diagram 0V = light on; 3.3V light off

Uint16 sdata; // send data

Uint32 counter;

// Step 1. Initialize System Control:

// PLL, WatchDog, enable Peripheral Clocks

// This example function is found in the F2837xS_SysCtrl.c file.

InitSysCtrl();

// Step 2. Initialize GPIO:

// This example function is found in the F2837xS_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 F2837xS_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 F2837xS_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 F2837xS_DefaultIsr.c.

// This function is found in F2837xS_PieVect.c.

InitPieVectTable();

// Step 4. Initialize the Device Peripherals:

spi_fifo_init(); // Initialize the Spi FIFO

spi_init(); // init SPI

// Step 5. User specific code:

// Interrupts are not used in this example.

sdata = 0;

counter = 0;

for(;;)

{

counter++;

if (counter > 500000)

{counter = 0;}

if (counter == 10000)

{GPIO_WritePin(CSPin, 1);} // CS line high - get ready to TX / load data register

if (counter == 400000)

{GPIO_WritePin(CSPin, 0);} // CS line low - get ready to receive data

// Transmit data

if (counter == 500000)  // simple delay

{

spi_xmit(sdata);  // stop in debug mode and change sdata to 43690

}

}  // for loop

} // main

// Step 7. Insert all local Interrupt Service Routines (ISRs) and functions here:

 

 

void spi_init()

{

SpiaRegs.SPICCR.all =0x000F; // Reset on, rising edge, 16-bit char bits

SpiaRegs.SPICTL.all =0x0006; // Enable master mode, normal phase,

// enable talk, and SPI int disabled.

SpiaRegs.SPIBRR.all =0x0063;

SpiaRegs.SPICCR.all =0x009F; // 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.

//===========================================================================


  • Hi Brakel,

    Form above piece of code, spi configuration is fine. Probably, SPI speed is not syncing due to that the above behavior of GPIO16 PIN.

    Could you please check with differnet speed (i mean different values of SPIBRR) ?

    Regards
    Aditya
  • Hi Barkel,

    Is this issue seen with only this specific value of sdata (43690 ). ? With all other value of sdata, does it works fine? Can you capture the clock waveform also along with the data in this case.

    Regards,

    Vivek Singh
  • Hi Vivek,

    The module can do certain values, such as [1010 1000 0000 0000] or [1000 1000 1111 0000] where the signal is held high. But once there are more than 3 up/down cycles it drops to 1.6V. So [1111 1111 1111 0000] would be fine, but not [1101 0000 1100 1100].

    I tried running the code at speed 7F and had similar results.

    My second probe is broken so unfortunately I can't overlay the clock and the data signals at the same time. But from inspection, the clock signals look ok, up to 3.3V no issue.

    Any other suggestions?

    Many thanks,

    TB
  • Thanks. Do you have another Launchpad to try the same example and see if same issue exist there as well?

    Regards,
    Vivek Singh
  • Hi Vivek,

    Unfortunately, I only have the one unit, but feel free to send me another one. If we can get to the bottom of this, we will likely purchase more of them. However, SPI communication is definitely a prerequisite.

    Do you think it would be worthwhile to try to the high-speed pins (GPIO 58,59,60,61), but not in high-speed mode?

    If so, is there anything else that I would need to change other than F2837xS_Spi.c? Can you please confirm the changes below?

    Many thanks,

    TB

    void InitSpiaGpio()
    {

    EALLOW;

    /* Enable internal pull-up for the selected pins */
    // Pull-ups can be enabled or disabled by the user.
    // This will enable the pullups for the specified pins.
    // Comment out other unwanted lines.

    GpioCtrlRegs.GPBPUD.bit.GPIO58 = 0; // Enable pull-up on GPIO16 (SPISIMOA)
    GpioCtrlRegs.GPBPUD.bit.GPIO59 = 0; // Enable pull-up on GPIO17 (SPISOMIA)
    GpioCtrlRegs.GPBPUD.bit.GPIO60 = 0; // Enable pull-up on GPIO18 (SPICLKA)
    GpioCtrlRegs.GPBPUD.bit.GPIO61 = 0; // Enable pull-up on GPIO19 (SPISTEA)

    /* Set qualification for selected pins to asynch only */
    // This will select asynch (no qualification) for the selected pins.
    // Comment out other unwanted lines.

    GpioCtrlRegs.GPBQSEL2.bit.GPIO58 = 3; // Asynch input GPIO16 (SPISIMOA)
    GpioCtrlRegs.GPBQSEL2.bit.GPIO59 = 3; // Asynch input GPIO17 (SPISOMIA)
    GpioCtrlRegs.GPBQSEL2.bit.GPIO60 = 3; // Asynch input GPIO18 (SPICLKA)
    GpioCtrlRegs.GPBQSEL2.bit.GPIO61 = 3; // Asynch input GPIO19 (SPISTEA)

    /* Configure SPI-A pins using GPIO regs*/
    // This specifies which of the possible GPIO pins will be SPI functional pins.
    // Comment out other unwanted lines.

    GpioCtrlRegs.GPBMUX2.bit.GPIO58 = 1; // Configure GPIO16 as SPISIMOA
    GpioCtrlRegs.GPBMUX2.bit.GPIO59 = 1; // Configure GPIO17 as SPISOMIA
    GpioCtrlRegs.GPBMUX2.bit.GPIO60 = 1; // Configure GPIO18 as SPICLKA
    GpioCtrlRegs.GPBMUX2.bit.GPIO61 = 1; // Configure GPIO19 as SPISTEA

    EDIS;
    }
  • Hi Thomas,

    Do you think it would be worthwhile to try to the high-speed pins (GPIO 58,59,60,61), but not in high-speed mode? 

    Yes, that's a good option to try.

    If so, is there anything else that I would need to change other than F2837xS_Spi.c? Can you please confirm the changes below?

    SPI pin you are choosing need mux option 15. Hence you need to set the appropriate fields in GPBGMUX2/GPBMUX2 to value 0x3.

    Following is code for mux setting -

    GpioCtrlRegs.GPBGMUX2.bit.GPIO58 = 3; // Configure GPIO58 as SPISIMOA
    GpioCtrlRegs.GPBGMUX2.bit.GPIO59 = 3; // Configure GPIO59 as SPISOMIA
    GpioCtrlRegs.GPBGMUX2.bit.GPIO60 = 3; // Configure GPIO60 as SPICLKA
    GpioCtrlRegs.GPBGMUX2.bit.GPIO61 = 3; // Configure GPIO61 as SPISTEA

    GpioCtrlRegs.GPBMUX2.bit.GPIO58 = 3; // Configure GPIO58 as SPISIMOA
    GpioCtrlRegs.GPBMUX2.bit.GPIO59 = 3; // Configure GPIO59 as SPISOMIA
    GpioCtrlRegs.GPBMUX2.bit.GPIO60 = 3; // Configure GPIO60 as SPICLKA
    GpioCtrlRegs.GPBMUX2.bit.GPIO61 = 3; // Configure GPIO61 as SPISTEA

    Regards,

    Vivek Singh

  • Hi Vivek / TI Community,

    Unfortunately, this was an error on my part.  The SPI A configuration works fine for all values.

    For anyone using MCP41XXX SPI digital potentiometer, you need to add the following line to the spi_init function:

    SpiaRegs.SPICTL.bit.CLK_PHASE = 1;

    to properly align the clock and data signals.

    Apologies for the confusion and thank you once again for your support.

    TB

  • Hi Thomas,

    Good to know you were able to resolve the issue.

    Regards,
    Vivek Singh