This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28335: How to use SPI to transmit and receive data one byte at a time?

Part Number: TMS320F28335


Hi team,

Here's an issue from the customer may need your help:

The customer wants to communicate with an energy harvesting chip using SPI, which reads data by sending 1 byte, waiting 2 us, and then receiving 3 bytes. As per the manual, the SPI seems to send 16-bit data for every communication, that is, a single write to TXBUFF triggers a 16-bit shift. It seems possible to use SPICCR.0-3 to control the length of the transmitted data, but when used it is found that it is still shifted by 16 bits at a time.

Using the loopback feature, configure SPICHAR to 7. When calling read and write function: Temp4 = SPIA_SendReciveData(0xD312); , it will get data 0x12D3. And it looks like it's still transmitting 16 bits. However, it should only transfer 12 bits, D3 is ignored, and get the data 0x12 right?

void SPIA_Normal_Init(void)
{
	//Enable the SPI clock and initialize the corresponding GPIO 
	EALLOW;
	SysCtrlRegs.PCLKCR0.bit.SPIAENCLK = 1;   // Enable the SPI-a peripheral clock 
	EDIS;
	InitSpiaGpio();							 // Initialize the GPIO pins for SPIA 

	//Configure the SPI operation and parameter settings, including data format, phase polarity, FIFO functionality 
    //Clear Reset bit resets SPI; clock polity=0: Rising edge transmit, falling edge receive; loopback mode is disabled ;Use 16-bit data length 
	SpiaRegs.SPICCR.bit.SPISWRESET = 0;
	SpiaRegs.SPICCR.bit.CLKPOLARITY = 0;
	SpiaRegs.SPICCR.bit.SPILBK = 1;
	SpiaRegs.SPICCR.bit.SPICHAR = 0x7;
	//Disable receive overflow interrupt; clock phase=1: No delay; master mode; enable transmit function; disable total interrupt 
	SpiaRegs.SPICTL.bit.OVERRUNINTENA = 0;
	SpiaRegs.SPICTL.bit.CLK_PHASE = 1;
	SpiaRegs.SPICTL.bit.MASTER_SLAVE = 1;
	SpiaRegs.SPICTL.bit.TALK = 1;
	SpiaRegs.SPICTL.bit.SPIINTENA = 0;

//	SpiaRegs.SPIFFTX.all=0xE040;				//FIFO transmit is enabled; the TXFIFO transmit interrupt is cleared; the TX FIFO match interrupt is disabled; and the TX FIFO interrupt level is 0 
//	SpiaRegs.SPIFFRX.all=0x204F;				//FIFO reception is enabled; the RXFIFO receive interrupt is cleared; the RX FIFO match interrupt is disabled; and the RX FIFO interrupt level is set to 16 
//	SpiaRegs.SPIFFCT.all=0x0;					//The FIFO transmit delay is set to 0 

	SpiaRegs.SPIBRR =0x007F;					 //Set the communication baud rate = LSPLCK/(SPIBRR+1)或LSPCLK/4:37.5M/128=292.9k
	SpiaRegs.SPICCR.bit.SPISWRESET = 1; 		 //Released from reset 
	SpiaRegs.SPIPRI.bit.FREE = 1;                //Free-running 
}


Uint16 SPIA_SendReciveData(Uint16 dat)
{

	// Transmit data
	SpiaRegs.SPITXBUF=dat;


	// Wait until data is received
	while(SpiaRegs.SPISTS.bit.INT_FLAG !=1);
	DELAY_US(8);

	return SpiaRegs.SPIRXBUF;
}

Could you help check this case? Thanks.

Best Regards,

Cherry