Hello. I am using newest TI-RTOS and am trying to send SPI initialization sequence to MCP3909 energy meter. My code is based on the TI SPI example provided in the CCS. Basically I just changed the MasterTxBuffer and removed the code for RX (loopback).
The SPI seemingly works, I tried at 100kHz and 10MHz, but the output data does not match what I need to send.
For example:
int masterTxBuffer = 0b00000001; // 1
Results in this:
Another example:
int masterTxBuffer = 0b11111111; //255
Result:
int masterTxBuffer = 0b10100100; // 164 = MCP3909 init, output dual channel pre-filter
Result:
SPI example prints correct (expected) decimal value:
SPI initialized SPI: Master: 164 SPI: Done
As you can see, neither output corresponds to data in masterTxBuffer.
Here is my SPI function, slightly modified from TI SPI loopback example:
Void MCPinitFxn (UArg arg0, UArg arg1) { SPI_Handle masterSpi; SPI_Transaction masterTransaction; bool transferOK; /* Initialize SPI handle as default master */ SPI_Params_init(¶ms2); params2.bitRate = 100000; params2.frameFormat = SPI_POL0_PHA0; params2.dataSize = 8; masterSpi = SPI_open(SPI3, ¶ms2); if (masterSpi == NULL) { System_abort("Error initializing SPI\n"); } else { System_printf("SPI initialized\n"); } /* Initialize master SPI transaction structure */ masterTransaction.count = SPI_MSG_LENGTH; masterTransaction.txBuf = (Ptr)masterTxBuffer; masterTransaction.rxBuf = (Ptr)masterRxBuffer; /* Initiate SPI transfer */ transferOK = SPI_transfer(masterSpi, &masterTransaction); if(transferOK) { /* Print contents of master receive buffer */ System_printf("SPI: Master: %d\n", masterTransaction.txBuf); } else { System_printf("SPI: Unsuccessful master SPI transfer"); } /* Deinitialize SPI */ SPI_close(masterSpi); System_printf("SPI: Done\n"); System_flush(); }
What could be the problem?