Part Number: LAUNCHXL-F280025C
Other Parts Discussed in Thread: C2000WARE
Hi,
I'm a beginner with C & C2000. I'm trying to control the individual bytes sent through SPI - I'd like to be able to define each byte that is sent and how many times. At the moment though, every way I've tried results in a loop with the SPI module repeatedly sending the same byte.
I've started with the C2000 examples, specifically spi_ex1_loopback. I've added one GPIO input to trigger the data transmission, removed rData and disabled loopback mode. One of my code trials below:
// Included Files
#include "driverlib.h"
#include "device.h"
#include "board.h"
// Main
void main(void)
{
uint16_t sData = 0; // Send data
uint16_t sData2 = 0; // Send data
uint16_t sData3 = 0; // Send data
int counter = 0;
Device_init();// Initialize device clock and peripherals
Device_initGPIO();// Disable pin locks and enable internal pullups.
Interrupt_initModule();// Initialize PIE and clear PIE registers. Disables CPU interrupts.
Interrupt_initVectorTable();// Initialize the PIE vector table with pointers to the shell Interrupt
Board_init();// Board initialization
EINT;// Enable Global Interrupt (INTM)
ERTM;// Enable realtime interrupt (DBGM)
while(1)// Loop forever. Suspend or place breakpoints to observe the buffers.
{
counter++;
// Transmit data
SPI_writeDataNonBlocking(mySPI0_BASE, sData);// sent 1 byte of sData
SPI_writeDataNonBlocking(mySPI0_BASE, sData2);// then send 1 byte of SData2
SPI_writeDataNonBlocking(mySPI0_BASE, sData3);// then send 1 byte of SData3
if (GPIO_readPin(myGPIO0) == 0) { //when the input goes low, 1 byte of sData, sData2 and sData3 should be transmitted
if (counter == 1){ // send only during the first loop
sData = 100000;
sData2 = 200000;
sData3 = 4555;
}
else { //if counter != 1 send nothing
sData = 0;
sData2 = 0;
sData3 = 0;
}
}
else { // if myGPIO0 == 1 send nothing
sData = 0;
sData2 = 0;
sData3 = 0;
}
}
}
//
// End File
//
This code ends up sending only 'sData' repeatedly rather than 'sData', 'sData2' and 'sData3' once each. I checked all the other SPI examples and opened spi.h but couldn't find how to do this.
Any suggestions and examples would be appreciated!
Thanks
- Michael