Other Parts Discussed in Thread: C2000WARE
I am trying to communicate to an encoder using SPI, and am running into trouble in getting any sort of output at all. I have to use SPI B due to the architecture of my board, and the microcontroller is the master. As the title mentions, I have also tried using a bitbanging approach using the output pins as GPIO, and it works perfectly well, and I can scope the return signal on the MISO line and get the appropriate communication from the encoder.
The problem is that when I switch off of GPIO to SPI, I am not able to have any sort of output on any on the pins, including the STE and CLK lines. They just stay on whatever default value they were at (depending on if I have the pull up enabled or disabled, which I have tried various combinations of). I currently have a barebones approach without interrupts or FIFO enabled, but have tried both of these options as well with the same effect. I am just trying to get any communication at all before I start to make things more complicated.
Because the bitbanging works, I am assuming I am missing something quite obvious in the setup. I will include absolutely every line of code having to do with SPI, including all setup, so please do let me know if there is anything I am missing or messing up in the foundations! Thank you, and the code is below.
First, I set up the GPIO and peripheral clock. I have tried various pull up enable combinations to no effect, as I mentioned.
CpuSysRegs.PCLKCR8.bit.SPI_B =1; //Motor Encoder Through SPI EALLOW; GpioCtrlRegs.GPBPUD.bit.GPIO58 = 0; // Enable pullup on GPIO58 GpioCtrlRegs.GPBPUD.bit.GPIO59 = 0; // Enable pullup on GPIO59 GpioCtrlRegs.GPBPUD.bit.GPIO60 = 0; // Enable pullup on GPIO60 GpioCtrlRegs.GPBPUD.bit.GPIO61 = 0; // Enable pullup on GPIO61 GpioCtrlRegs.GPBQSEL2.bit.GPIO58 = 3; // asynch input GpioCtrlRegs.GPBQSEL2.bit.GPIO59 = 3; // asynch input GpioCtrlRegs.GPBQSEL2.bit.GPIO60 = 3; // asynch input GpioCtrlRegs.GPBQSEL2.bit.GPIO61 = 3; // asynch input EDIS; GPIO_SetupPinMux(58, GPIO_MUX_CPU1, 6); //SPIB GPIO_SetupPinMux(59, GPIO_MUX_CPU1, 6); GPIO_SetupPinMux(60, GPIO_MUX_CPU1, 6); GPIO_SetupPinMux(61, GPIO_MUX_CPU1, 6);
Then, there are the settings register initialization:
SpibRegs.SPICCR.bit.SPISWRESET = 0; // start reset at 0 SpibRegs.SPICCR.bit.SPICHAR = 0x0F; // 16-bit char bits SpibRegs.SPICCR.bit.CLKPOLARITY = 0; // polarity normal SpibRegs.SPICTL.bit.CLK_PHASE = 1; // delay phase SpibRegs.SPICTL.bit.MASTER_SLAVE = 1; // master mode SpibRegs.SPICTL.bit.TALK = 1; // enable talk SpibRegs.SPIBRR.all =0x000F; // Baud rate SpibRegs.SPICCR.bit.SPISWRESET = 1; // Relinquish SPI from Reset
And finally, the extremely barebones communication loop. I have tried waiting for interrupts, etc. as all the examples indicate to do, but they all end up hanging on that condition. This is occurring at 1KHz:
SpibRegs.SPITXBUF = (Uint16)(0xFFFF); //send all high data to request current motor position
SpiRx = SpibRegs.SPIRXBUF;
Like I mentioned, this causes absolutely no change on any of the lines, including the STE and CLK lines, which stay at default value. Any help would be much appreciated!