Other Parts Discussed in Thread: MOTORWARE, CONTROLSUITE, DRV8301
I'm trying to use my Launch XL 28069M as a spi slave to be controlled by an arduino. I'm a beginner in this so I've done my best to read through the user guide here and step through the motorware drivers to infer how it should be implemented, and have come up with almost nothing.
The goal eventually is to use the arduino to command motor data to the c2000, but for now I just want to get the two devices talking. For the arduino I'm sending at 1Mhz, outputting on the falling edge, with normal phase and MSB first. I know the SPI from the arduino is working because I've verified it with another device.
Here is the code I've created, I'm using the drivers from motorware, and am bypassing the HAL drivers because it added too much complexity, in my opinion, for what I want t do. This code compiles and runs without any infinite loops, but when watching the SPI registers in CCS debugger mode, nothing changes.
I've also tried sending data using the other function, and the same story happens, nothing changes in the registers and nothing happens when I scope the pins.
And just for good measure, I have meticulously verified that I'm plugged into the right places.
#include "sw\drivers\spi\src\32b\f28x\f2806x\spi.h"
#include "sw/drivers/gpio/src/32b/f28x/f2806x/gpio.h"
//globals
SPI_Handle spiHandle;
GPIO_Handle gpioHandle;
//sets up the SPIA bus
void setupSpiA()
{
spiHandle = SPI_init((void *)SPIA_BASE_ADDR,sizeof(SPI_Obj));
uint16_t var = 12;
var++;
var++;
SPI_reset(spiHandle);
SPI_setMode(spiHandle,SPI_Mode_Slave);
SPI_setClkPolarity(spiHandle,SPI_ClkPolarity_OutputRisingEdge_InputFallingEdge);
SPI_enableTx(spiHandle);
SPI_enableTxFifoEnh(spiHandle);
SPI_enableTxFifo(spiHandle);
SPI_setTxDelay(spiHandle,0x0018);
SPI_setBaudRate(spiHandle,(SPI_BaudRate_e)(0x000d));
SPI_setCharLength(spiHandle,SPI_CharLength_16_Bits);
SPI_setSuspend(spiHandle,SPI_TxSuspend_free);
SPI_enable(spiHandle);
return;
}
void setupGPIOforSpiA(){
// SPIA SIMO
gpioHandle = GPIO_init((void *)GPIO_BASE_ADDR,sizeof(GPIO_Obj));
GPIO_setMode(gpioHandle,GPIO_Number_16,GPIO_16_Mode_SPISIMOA);
// SPIA SOMI
GPIO_setMode(gpioHandle,GPIO_Number_17,GPIO_17_Mode_SPISOMIA);
// SPIA CLK
GPIO_setMode(gpioHandle,GPIO_Number_18,GPIO_18_Mode_SPICLKA);
// SPIA CS
GPIO_setMode(gpioHandle,GPIO_Number_19,GPIO_19_Mode_SPISTEA_NOT);
}
//function for writing to spi
void sendOverSpi(uint16_t input){
uint16_t send;
send = input;
// reset the Rx fifo pointer to zero
SPI_resetRxFifo(spiHandle);
SPI_enableRxFifo(spiHandle);
// write the command (time N)
SPI_write(spiHandle,send);
return;
}
//function for reading from spi
uint16_t getFromSpi(){
uint16_t ret;
static volatile uint16_t WaitTimeOut = 0;
volatile SPI_FifoStatus_e RxFifoCnt = SPI_FifoStatus_Empty;
// reset the Rx fifo pointer to zero
SPI_resetRxFifo(spiHandle);
SPI_enableRxFifo(spiHandle);
// wait for two words to populate the RX fifo, or a wait timeout will occur
while((RxFifoCnt < SPI_FifoStatus_1_Word) && (WaitTimeOut < 0xff))
{
RxFifoCnt = SPI_getRxFifoStatus(spiHandle);
WaitTimeOut++;
}
//read the spi word
ret = SPI_read(spiHandle);
return ret;
}
int main(void) {
uint16_t thing = 0;
//setup spi
setupSpiA();
thing = 1;
setupGPIOforSpiA();
thing = 2;
while(1){
thing = getFromSpi();
}
return 0;
}
any thoughts?