Other Parts Discussed in Thread: C2000WARE
Hello,
I'm trying to configure the example provide in C2000Ware SPI Loopback to use SPI-B instead of SPI-A. I need to use both SPI-A and SPI-B in my final design, so I'm trying to make sure I understand how to configure them correctly. I'm using the F28379D Experimenter Kit. I've confirmed that if I use the code as provided with SPI-A everything is working fine. I'm measuring pin 71 with an oscilloscope (GPIO 18) and I can see the clock. I then tried to configure for SPI-B and I can't see anything on pin 79 (GPIO 79) SPIB-clk. I've changed Example_2837xDSpi_FFDLB.c and F2837xD_Spi.c, see below. Is there anything else I need to change to use SPI-B? Any help is appreciated.
//###########################################################################
//
// FILE: Example_2837xDSpi_FFDLB.c
//
// TITLE: SPI Digital Loop Back program.
//
//! \addtogroup cpu01_example_list
//! <h1>SPI Digital Loop Back (spi_loopback)</h1>
//!
//! This program uses the internal loop back test mode of the peripheral.
//! Other then boot mode pin configuration, no other hardware configuration
//! is required. Interrupts are not used.
//!
//! A stream of data is sent and then compared to the received stream.
//! The sent data looks like this: \n
//! 0000 0001 0002 0003 0004 0005 0006 0007 .... FFFE FFFF \n
//! This pattern is repeated forever.
//!
//! \b Watch \b Variables \n
//! - \b sdata - sent data
//! - \b rdata - received data
//!
//
//###########################################################################
// $TI Release: F2837xD Support Library v210 $
// $Release Date: Tue Nov 1 14:46:15 CDT 2016 $
// $Copyright: Copyright (C) 2013-2016 Texas Instruments Incorporated -
// http://www.ti.com/ ALL RIGHTS RESERVED $
//###########################################################################
//
// Included Files
//
#include "F28x_Project.h"
//
// Function Prototypes
//
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 F2837xD_SysCtrl.c file.
//
InitSysCtrl();
//
// Step 2. Initialize GPIO:
// This example function is found in the F2837xD_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// Setup only the GP I/O only for SPI-A functionality
// This function is found in F2837xD_Spi.c
//
InitSpiaGpio();
//
// Step 3. Clear all 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 F2837xD_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 F2837xD_DefaultIsr.c.
// This function is found in F2837xD_PieVect.c.
//
InitPieVectTable();
//
// Step 4. Initialize the Device Peripherals:
//
spi_fifo_init(); // Initialize the SPI FIFO
//
// Step 5. User specific code:
//
sdata = 0x0000;
for(;;)
{
//
// Transmit data
//
spi_xmit(sdata);
//
// Wait until data is received
//
while(SpibRegs.SPIFFRX.bit.RXFFST !=1) { }
//
// Check against sent data
//
rdata = SpibRegs.SPIRXBUF;
if(rdata != sdata)
{
error();
}
sdata++;
}
}
//
// delay_loop - Loop for a brief delay
//
void delay_loop()
{
long i;
for (i = 0; i < 1000000; i++) {}
}
//
// error - Error function that halts the debugger
//
void error(void)
{
asm(" ESTOP0"); // Test failed!! Stop!
for (;;);
}
//
// spi_xmit - Transmit value via SPI
//
void spi_xmit(Uint16 a)
{
SpibRegs.SPITXBUF = a;
}
//
// spi_fifo_init - Initialize SPIA FIFO
//
void spi_fifo_init()
{
//
// Initialize SPI FIFO registers
//
SpibRegs.SPIFFTX.all = 0xE040;
SpibRegs.SPIFFRX.all = 0x2044;
SpibRegs.SPIFFCT.all = 0x0;
//
// Initialize core SPI registers
//
InitSpi();
}
//###########################################################################
//
// FILE: F2837xD_Spi.c
//
// TITLE: F2837xD SPI Initialization & Support Functions.
//
//###########################################################################
// $TI Release: F2837xD Support Library v210 $
// $Release Date: Tue Nov 1 14:46:15 CDT 2016 $
// $Copyright: Copyright (C) 2013-2016 Texas Instruments Incorporated -
// http://www.ti.com/ ALL RIGHTS RESERVED $
//###########################################################################
//
// Included Files
//
#include "F2837xD_device.h"
#include "F2837xD_Examples.h"
//
// Calculate BRR: 7-bit baud rate register value
// SPI CLK freq = 500 kHz
// LSPCLK freq = CPU freq / 4 (by default)
// BRR = (LSPCLK freq / SPI CLK freq) - 1
//
#if CPU_FRQ_200MHZ
#define SPI_BRR ((200E6 / 4) / 500E3) - 1
#endif
#if CPU_FRQ_150MHZ
#define SPI_BRR ((150E6 / 4) / 500E3) - 1
#endif
#if CPU_FRQ_120MHZ
#define SPI_BRR ((120E6 / 4) / 500E3) - 1
#endif
//
// InitSPI - This function initializes the SPI to a known state
//
void InitSpi(void)
{
// Initialize SPI-A
// Set reset low before configuration changes
// Clock polarity (0 == rising, 1 == falling)
// 16-bit character
// Enable loop-back
SpibRegs.SPICCR.bit.SPISWRESET = 0;
SpibRegs.SPICCR.bit.CLKPOLARITY = 0;
SpibRegs.SPICCR.bit.SPICHAR = (16-1);
SpibRegs.SPICCR.bit.SPILBK = 1;
// Enable master (0 == slave, 1 == master)
// Enable transmission (Talk)
// Clock phase (0 == normal, 1 == delayed)
// SPI interrupts are disabled
SpibRegs.SPICTL.bit.MASTER_SLAVE = 1;
SpibRegs.SPICTL.bit.TALK = 1;
SpibRegs.SPICTL.bit.CLK_PHASE = 0;
SpibRegs.SPICTL.bit.SPIINTENA = 0;
// Set the baud rate
SpibRegs.SPIBRR.bit.SPI_BIT_RATE = SPI_BRR;
// Set FREE bit
// Halting on a breakpoint will not halt the SPI
SpibRegs.SPIPRI.bit.FREE = 1;
// Release the SPI from reset
SpibRegs.SPICCR.bit.SPISWRESET = 1;
}
//
// InitSpiGpio - This function initializes GPIO pins to function as SPI pins.
// Each GPIO pin can be configured as a GPIO pin or up to 3
// different peripheral functional pins. By default all pins come
// up as GPIO inputs after reset.
//
// Caution:
// For each SPI peripheral
// Only one GPIO pin should be enabled for SPISOMO operation.
// Only one GPIO pin should be enabled for SPISOMI operation.
// Only one GPIO pin should be enabled for SPICLK operation.
// Only one GPIO pin should be enabled for SPISTE operation.
// Comment out other unwanted lines.
//
void InitSpiGpio()
{
InitSpiaGpio();
}
//
// InitSpiaGpio - Initialize SPIA GPIOs
//
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.GPAPUD.bit.GPIO24 = 0; // Enable pull-up on GPIO16 (SPISIMOA)
// GpioCtrlRegs.GPAPUD.bit.GPIO5 = 0; // Enable pull-up on GPIO5 (SPISIMOA)
GpioCtrlRegs.GPAPUD.bit.GPIO25 = 0; // Enable pull-up on GPIO17 (SPISOMIA)
// GpioCtrlRegs.GPAPUD.bit.GPIO3 = 0; // Enable pull-up on GPIO3 (SPISOMIA)
GpioCtrlRegs.GPAPUD.bit.GPIO26 = 0; // Enable pull-up on GPIO18 (SPICLKA)
GpioCtrlRegs.GPAPUD.bit.GPIO27 = 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.GPAQSEL2.bit.GPIO24 = 3; // Asynch input GPIO16 (SPISIMOA)
// GpioCtrlRegs.GPAQSEL1.bit.GPIO5 = 3; // Asynch input GPIO5 (SPISIMOA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO25 = 3; // Asynch input GPIO17 (SPISOMIA)
// GpioCtrlRegs.GPAQSEL1.bit.GPIO3 = 3; // Asynch input GPIO3 (SPISOMIA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO26 = 3; // Asynch input GPIO18 (SPICLKA)
GpioCtrlRegs.GPAQSEL2.bit.GPIO27 = 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.GPAMUX2.bit.GPIO24 = 6; // Configure GPIO16 as SPISIMOA
// GpioCtrlRegs.GPAMUX1.bit.GPIO5 = 2; // Configure GPIO5 as SPISIMOA
GpioCtrlRegs.GPAMUX2.bit.GPIO25 = 6; // Configure GPIO17 as SPISOMIA
// GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 2; // Configure GPIO3 as SPISOMIA
GpioCtrlRegs.GPAMUX2.bit.GPIO26 = 6; // Configure GPIO18 as SPICLKA
GpioCtrlRegs.GPAMUX2.bit.GPIO27 = 6; // Configure GPIO19 as SPISTEA
EDIS;
}
//
// End of file
//