Tool/software: TI-RTOS
I have code for SPI based off off the examples in SPI.h.
I'm not getting any errors, but when I check to see if SPI is working on the oscilloscope, there is nothing coming out of the clock, or mosi pins when transmit is called.
This is my code:
/* XDCtools Header files */ #include <xdc/std.h> #include <xdc/runtime/System.h> /* BIOS Header files */ #include <ti/sysbios/BIOS.h> #include <ti/sysbios/knl/Task.h> /* TI-RTOS Header files */ #include <ti/drivers/PIN.h> #include <ti/drivers/UART.h> /* Example/Board Header files */ #include "Board.h" #include <stdint.h> /* SPI Header files */ #include <ti/drivers/SPI.h> #include <ti/drivers/spi/SPICC26XXDMA.h> #include <ti/drivers/dma/UDMACC26XX.h> #define TASKSTACKSIZE 768 Task_Struct task0Struct; Char task0Stack[TASKSTACKSIZE]; /* Pin driver handle */ static PIN_Handle ledPinHandle; static PIN_State ledPinState; PIN_Config ledPinTable[] = { Board_LED0 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, Board_LED1 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, PIN_TERMINATE }; SPI_Handle handle; SPI_Params params; SPI_Transaction transaction; uint8_t txBuf[] = "Hello World"; // Transmit buffer uint8_t rxBuf[11]; // Receive buffer Void taskFxn(UArg arg0, UArg arg1) { while (1) { /* Toggle LED */ PIN_setOutputValue(ledPinHandle, Board_LED0, 0); Task_sleep((UInt)arg0); PIN_setOutputValue(ledPinHandle, Board_LED0, 1); if (! SPI_transfer(handle, &transaction)){ PIN_setOutputValue(ledPinHandle, Board_LED1, 0); } Task_sleep((UInt)arg0); } } int main(){ Task_Params taskParams; /* Call board init functions */ Board_initGeneral(); SPI_init(); /* Construct heartBeat Task thread */ Task_Params_init(&taskParams); taskParams.arg0 = 1000000 / Clock_tickPeriod; taskParams.stackSize = TASKSTACKSIZE; taskParams.stack = &task0Stack; Task_construct(&task0Struct, (Task_FuncPtr)taskFxn, &taskParams, NULL); // Init SPI and specify non-default params SPI_Params_init (¶ms); params.bitRate = 1000000; params.frameFormat = SPI_POL1_PHA1; params.mode = SPI_MASTER; // Configure the transaction transaction.count = sizeof(txBuf); transaction.txBuf = txBuf; transaction.rxBuf = rxBuf; /* Open LED pins */ ledPinHandle = PIN_open(&ledPinState, ledPinTable); if(!ledPinHandle) { System_abort("Error initializing board LED pins\n"); } PIN_setOutputValue(ledPinHandle, Board_LED0, 1); PIN_setOutputValue(ledPinHandle, Board_LED1, 1); System_printf("Starting the example\nSystem provider is set to SysMin. " "Halt the target to view any SysMin contents in ROV.\n"); /* SysMin will only print to the console when you call flush or exit */ System_flush(); // Open the SPI and perform the transfer handle = SPI_open(Board_SPI0, ¶ms); /* Start BIOS */ BIOS_start(); return (0); }