Hi,
I have been working with the TMS320F28377D module for the past few weeks and was wondering if anyone could help point me in the correct direction for SPI driver development. Currently, I have managed to configure the registers provided by the spi.h files and executing the SPI protocol internally on the TMS320F28377D. This was done by simply reconfiguring the SPI loopback example provided in the ControlSuite CCS projects.
However, my next step involves transmitting and receiving data over to an external module and attempting to communicate with this external module to run some functions the manufacturer has already provided.
Do you know of any references, guides, or datasheets that I should be taking a look at in order to help achieve this goal? I have thoroughly read through the TMS320F28377D technical reference SPI chapter, looked over the TMS320F28377D datasheets, external module datasheets and a variety of other examples. Still, I have been unable to locate a proper way to go about this and I fear that my current SPI development may lead to bit-banging out transmission values.
Any advice?
Thank you.
Also, in case anyone is wondering what I have been working with, here is what I have been working with:
/*
* main.c
*/
#include "F28x_Project.h"
//#include "LTC6804-2.h"
//#include "C:\Users\hoanga\Desktop\DC2100A_Software_and_Users_Guide\DC2100A_Source_AppFW_v_1_2_0_GUI_v1_3_1\DC2100A_Source\Firmware\Source\LTC6804-2.h"
#include <stdio.h>
#include <inttypes.h>
//#include "LTC6804-2.h"
void delay_loop(void);
void spi_xmit(Uint16 a);
void spi_fifo_init(void);
void spi_init(void);
void error(void);
//user
void spi_init_test(void);
void spi_fifo_init_test(void);
void spi_receive(Uint16 a);
void main(void) {
Uint16 sdata; // send data
Uint16 rdata; // received data
// Step 1. Initialize System C.ontrol:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the F2837xD_SysCtrl.c file.
InitSysCtrl();
// Step 2. Initialize GPIO:
// This example function is found in the F2837xD_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example
// Setup only the GP I/O only for SPI-A functionality
// This function is found in F2837xD_Spi.c
InitSpiaGpio();
// Step 3. Clear all __interrupts and initialize PIE vector table:
// Disable CPU __interrupts
DINT;
// Initialize PIE control registers to their default state.
// The default state is all PIE __interrupts disabled and flags
// are cleared.
// This function is found in the F2837xD_PieCtrl.c file.
InitPieCtrl();
// Disable CPU __interrupts and clear all CPU __interrupt flags:
IER = 0x0000;
IFR = 0x0000;
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the __interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in F2837xD_DefaultIsr.c.
// This function is found in F2837xD_PieVect.c.
InitPieVectTable();
// Step 4. Initialize the Device Peripherals:
spi_fifo_init(); // Initialize the Spi FIFO
//FIFO needs to be initialized if DMA were to be utilized
//spi_init(); // init SPI
//spi_fifo_init_test(); //initialize user SPI FIFO
spi_init_test(); //initialize user SPI
// Step 5. User specific code
sdata = 1001;
for(;;)
{
// Transmit data
spi_xmit(sdata);
// Wait until data is received
//while(SpiaRegs.SPIFFRX.bit.RXFFST !=1) { }
printf("%" PRIu16 "\n", sdata);
// Check against sent data
rdata = SpiaRegs.SPIRXBUF;
//if(rdata != sdata) error();
printf("%" PRIu16 "\n", rdata);
SpiaRegs.SPIRXBUF;
}
}
void spi_xmit(Uint16 a)
{
SpiaRegs.SPITXBUF=a;
}
void spi_receive(Uint16 a)
{
SpiaRegs.SPIRXBUF = a; //receiving value from the buffer?
}
void spi_fifo_init()
{
// Initialize SPI FIFO registers
SpiaRegs.SPIFFTX.all=0xE040;
SpiaRegs.SPIFFRX.all=0x2044;
SpiaRegs.SPIFFCT.all=0x0;
}
void spi_fifo_init_test()
{
//SpiaRegs.SPIFFTX.bit.SPIRST = 0; //TX FIFO SPI Reset
SpiaRegs.SPIFFTX.bit.SPIFFENA = 0; //TX FIFO enhancements (what is that?)
SpiaRegs.SPIFFTX.bit.TXFFIENA = 0; //TX FIFO enable (0 = disable; 1 = enabled)
SpiaRegs.SPIFFTX.bit.TXFFIL = 0; //Transmit FIFO Interrupt Level Bits
SpiaRegs.SPIFFTX.bit.TXFFINT = 0; //TX FIFO Interrupt Bit (Read only)
SpiaRegs.SPIFFTX.bit.TXFFINTCLR = 0; //TX FIFO Interrupt Clear
//SpiaRegs.SPIFFTX.bit.SPIRST = 1; //TX FIFO SPI Reset CLEAR
//SpiaRegs.SPIFFTX.bit.TXFFST //TX FIFO status (tells you how many words there are (4 max) )
//SpiaRegs.SPIFFTX.bit.TXFIFO //TX FIFO reset
SpiaRegs.SPIFFRX.bit.RXFFIENA = 0; //RX FIFO Interrupt Enabler (0 = disable; 1 = enabled)
//SpiaRegs.SPIFFRX.bit.RXFFIL = //RX FIFO Interrupt Level Bits
SpiaRegs.SPIFFRX.bit.RXFFINT = 0; //RX FIFO Interrupt Flag
SpiaRegs.SPIFFRX.bit.RXFFINTCLR = 0; //RX FIFO Interrupt Flag Clear
//SpiaRegs.SPIFFRX.bit.RXFFOVF = //RX FIFO overflow flag
//SpiaRegs.SPIFFRX.bit.RXFFOVFCLR = //RX FIFO overflow flag Clear
//SpiaRegs.SPIFFRX.bit.RXFFST = //RX FIFO Receive status
SpiaRegs.SPIFFRX.bit.RXFIFORESET = 1; //RX FIFO Reset
//SPI FIFO Control Register
SpiaRegs.SPIFFCT.bit.TXDLY = 0;
}
void spi_init()
{
SpiaRegs.SPICCR.all =0x000F; // Reset on, rising edge, 16-bit char bits
SpiaRegs.SPICTL.all =0x0006; // Enable master mode, normal phase,
// enable talk, and SPI int disabled.
SpiaRegs.SPIBRR.all =0x007F;
SpiaRegs.SPICCR.all =0x009F; // Relinquish SPI from Reset
SpiaRegs.SPIPRI.bit.FREE = 1; // Set so breakpoints don't disturb xmission
}
void spi_init_test()
{
//Configure the SPI configuration register bits
SpiaRegs.SPICCR.bit.SPISWRESET = 0; //SPI reset initialization
SpiaRegs.SPICCR.bit.CLKPOLARITY = 0; // controls the shift clock polarity refer to page 1990 of the technical documentation for more info
SpiaRegs.SPICCR.bit.HS_MODE = 0; // high speed mode SPI protocol
// need to configure SPI high speed mode with specific MUX values.
//Refer to table 17-4 of the technical reference document for the TMS320F28377D
//4 bits to determine the
//SpiaRegs.SPICCR.bit.SPICHAR = ?? // Character length control bits
//currently set the SPI loopback to 0
SpiaRegs.SPICCR.bit.SPILBK = 0; //SPI Loopback Mode Select
SpiaRegs.SPICCR.bit.SPICHAR = 0x000F; //The number of characters to be shifted in and out as a single character during one shift sequence
SpiaRegs.SPICCR.bit.SPISWRESET = 1; //Relinquish SPI from Reset
//SPI Operation Control Register
SpiaRegs.SPICTL.bit.CLK_PHASE = 0; //help control the CLKPOLARITY sequence
//refer to page 1902 for clarification
//Master mode = 1, Slave mode = 0
SpiaRegs.SPICTL.bit.MASTER_SLAVE = 1; //select the SPI A port to be a master or slave control peripheral
SpiaRegs.SPICTL.bit.OVERRUNINTENA = 0; //Overrun Interrupt Enable
SpiaRegs.SPICTL.bit.SPIINTENA = 0; //control whether SPI will run in ISR or not
SpiaRegs.SPICTL.bit.TALK = 1; //Transmit Enable
//enables 4-pin option, ensure to enable the receiver's SPISTEn input pin --> technical documents notes page 1903
//SCLK speed
//baud rate
SpiaRegs.SPIBRR.bit.SPI_BIT_RATE = 0x00007F; //set the SPI baud rate
//7Fh (R/W) = SPI Baud Rate = LSPCLK/128
}
void delay_loop()
{
long i;
for (i = 0; i < 1000000; i++) {}
}
void spare_code()
{
}
void error(void)
{
asm(" ESTOP0"); // Test failed!! Stop!
for (;;);
}