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.
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
Hi,
There is an example available in driverlib which configures 2 SPI instances - one in master mode ans another in slave mode. This might be helpful to you.
<C2000Ware>\driverlib\f2837xd\examples\cpu1\spi\spi_ex3_external_loopback_fifo_interrupts
Regards,
Veena
Hi Veena,
Thanks so much for this!
Which part of the SPI Network would your quoted example be for? The Master or the Slave?
Also, even after distinguishing the difference, do you know a way that CCS can make two boards run their loaded programs at the same time and monitor them?
Thanks
Hi,
Apologies for the delayed response.
The example configures 1 instance of SPI in master mode an another instance of SPI in slave mode.
To connect 2 boards at a time, you need to gave 2 CCS sessions open. 1 CCS session can only connect to one board at a time.
To differentiate between the boards, you can use 2 different ccxml files and include the serial number of the board in the ccxml. To add serial number in the ccxml, open the ccxml file in the CCS , go to Advanced tab and select "Debug Probe Selection" as "Select by serial number" and enter the serial number of the board. The serial number of the board can be found by running xds100serial.exe (if you are using XDS100 emulator) available in ccs\ccs_base\common\uscif folder
The default value of "Debug Probe Selection" is "Only 1 XDS100 installed". This option assumes only 1 device is connected to the PC using XDS100 emulator and connects to one of the boards randomly. Having a serial number in the ccxml will make sure that the CCS is connected to the board which has a matching serial number
Regards,
Veena