Other Parts Discussed in Thread: C2000WARE
Hi there folks
I need to send data over SPI from one LAUNCHXL-F28379D to another LAUNCHXL-F28379D.
I am however confused at how to configure my second LAUNCHXL-F28379D to function as a slave given that the code in the main file looks like it' specifically for Mster function.
Following the example code titled spi_loopback_cpu01, I have changed the following elements of code in the F2837xDSpi.c file:
// Enable master (0 == slave, 1 == master) // Enable transmission (Talk) // Clock phase (0 == normal, 1 == delayed) // SPI interrupts are disabled SpiaRegs.SPICTL.bit.MASTER_SLAVE = 0; SpiaRegs.SPICTL.bit.TALK = 1; SpiaRegs.SPICTL.bit.CLK_PHASE = 0; SpiaRegs.SPICTL.bit.SPIINTENA = 0;
And then I see this in the main Example_2837xDSpi_FFDLB.c file:
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
//
sdata=21; // We just wanted to see if this fella would send something and then we'd bring back the counter functionality
spi_xmit(sdata);
//
// Wait until data is received
while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { }
// Check against sent data
rdata = SpiaRegs.SPIRXBUF;
if(rdata != sdata)
{
error();
}
}
}
What part of this section of code should I change so that my slave reads and returns whatever it receives?
Chur