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: Transmission with SPI from TMS320F28335 as master and TMS320F28335 as slave (2 boards 1 as master 1 as slave)

Part Number: TMS320F28335
Other Parts Discussed in Thread: C2000WARE

Hi, 

     I am trying to transmit data with SPI from master to slave. Both master and slave are TMS320F28335 but 2 diff boards. When I am transmitting I am not able to receive data. It is getting transmitted from TXBUF to DATA register but after that RXBUF is not receiving data. Can anyone help me with this please. 

THIS MASTER MODE 

#include "Mcu1_Device.h" // DSP2833x Header file Include File
#include "Mcu1_Spi.h"
#include "stdio.h"
#include "stdlib.h"
#include "time.h"

//
// InitSPI - This function initializes the SPI(s) to a known state.
//


UNS16 Data = 0x5555;
UNS16 receivedData; //=0 ;
UNS16 transdata =0, Dataregister = 0;

void InitSpi(void)
{
//
// Initialize SPI-A/B/C/D
//
}

//
// InitSpiGpio - This function initializes GPIO pins to function as SPI pins
//
// Each GPIO pin can be configured as a GPIO pin or up to 3 different
// peripheral functional pins. By default all pins come up as GPIO
// inputs after reset.
//
// Caution:
// For each SPI peripheral
// Only one GPIO pin should be enabled for SPISOMO operation.
// Only one GPIO pin should be enabled for SPISOMI operation.
// Only one GPIO pin should be enabled for SPICLKA operation.
// Only one GPIO pin should be enabled for SPISTEA operation.
// Comment out other unwanted lines.
//
void InitSpiGpio()
{
InitSpiaGpio();
}

//
// InitSpiaGpio - This function initializes GPIO poins to function as SPI pins
//
void InitSpiaGpio()
{
EALLOW;

//
// Enable internal pull-up for the selected pins
// Pull-ups can be enabled or disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.
//
GpioCtrlRegs.GPAPUD.bit.GPIO16 = 1; //Enable pull-up on GPIO16 (SPISIMOA)
GpioCtrlRegs.GPAPUD.bit.GPIO17 = 1; //Enable pull-up on GPIO17 (SPISOMIA)
GpioCtrlRegs.GPAPUD.bit.GPIO18 = 1; //Enable pull-up on GPIO18 (SPICLKA)
GpioCtrlRegs.GPAPUD.bit.GPIO19 = 1; //Enable pull-up on GPIO19 (SPISTEA)

// GpioCtrlRegs.GPBPUD.bit.GPIO54 = 0; //Enable pull-up on GPIO54 (SPISIMOA)
// GpioCtrlRegs.GPBPUD.bit.GPIO55 = 0; //Enable pull-up on GPIO55 (SPISOMIA)
// GpioCtrlRegs.GPBPUD.bit.GPIO56 = 0; //Enable pull-up on GPIO56 (SPICLKA)
// GpioCtrlRegs.GPBPUD.bit.GPIO57 = 0; //Enable pull-up on GPIO57 (SPISTEA)

//
// Set qualification for selected pins to asynch only
// This will select asynch (no qualification) for the selected pins.
// Comment out other unwanted lines.
//
 GpioCtrlRegs.GPAQSEL2.bit.GPIO16 = 3; // Asynch input GPIO16 (SPISIMOA)
 GpioCtrlRegs.GPAQSEL2.bit.GPIO17 = 3; // Asynch input GPIO17 (SPISOMIA)
 GpioCtrlRegs.GPAQSEL2.bit.GPIO18 = 3; // Asynch input GPIO18 (SPICLKA)
 GpioCtrlRegs.GPAQSEL2.bit.GPIO19 = 3; // Asynch input GPIO19 (SPISTEA)

//GpioCtrlRegs.GPBQSEL2.bit.GPIO54 = 3; // Asynch input GPIO16 (SPISIMOA)
//GpioCtrlRegs.GPBQSEL2.bit.GPIO55 = 3; // Asynch input GPIO17 (SPISOMIA)
//GpioCtrlRegs.GPBQSEL2.bit.GPIO56 = 3; // Asynch input GPIO18 (SPICLKA)
//GpioCtrlRegs.GPBQSEL2.bit.GPIO57 = 3; // Asynch input GPIO19 (SPISTEA)

//
// Configure SPI-A pins using GPIO regs
// This specifies which of the possible GPIO pins will be SPI
// functional pins.
// Comment out other unwanted lines.
//
GpioCtrlRegs.GPAMUX2.bit.GPIO16 = 1; // Configure GPIO16 as SPISIMOA
GpioCtrlRegs.GPAMUX2.bit.GPIO17 = 1; // Configure GPIO17 as SPISOMIA
GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 1; // Configure GPIO18 as SPICLKA
GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 1; // Configure GPIO19 as SPISTEA

// GpioCtrlRegs.GPBMUX2.bit.GPIO54 = 1; // Configure GPIO54 as SPISIMOA
// GpioCtrlRegs.GPBMUX2.bit.GPIO55 = 1; // Configure GPIO55 as SPISOMIA
// GpioCtrlRegs.GPBMUX2.bit.GPIO56 = 1; // Configure GPIO56 as SPICLKA
// GpioCtrlRegs.GPBMUX2.bit.GPIO57 = 1; // Configure GPIO57 as SPISTEA

EDIS;
}

void init_spi() //function for config GPIO and SCI module
{

EALLOW;
SysCtrlRegs.PCLKCR0.bit.SPIAENCLK = 1; // enabiling peripheral clock
EDIS;

// Configure SpI module


SpiaRegs.SPICCR.all = 0x002F;
// SpiaRegs.SPICTL.bit.SPIINTENA =1;
SpiaRegs.SPICTL.bit.TALK = 1; //as master mode  need of talk
SpiaRegs.SPICTL.bit.MASTER_SLAVE = 1; //as master mode make it 1
SpiaRegs.SPIBRR = BRR;
SpiaRegs.SPIFFTX.bit.TXFFIL = 2; //8;
SpiaRegs.SPIFFTX.bit.TXFFIENA = 1;
SpiaRegs.SPIFFTX.bit.TXFIFO = 1;
SpiaRegs.SPIFFTX.bit.SPIFFENA = 1;
SpiaRegs.SPIFFTX.bit.TXFFINTCLR = 1;

//SpiaRegs.SPIFFRX.all = 0x2062; //8;

EALLOW;
// Configure interrupts
PieVectTable.SPITXINTA = &spi_tx_ISR; // Assign ISR to the SCI TX interrupt
//PieVectTable.SPIRXINTA = &spi_Rx_ISR; // Assign ISR to the SCI RX interrupt
//Peripheral intialization
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable the PIE block
PieCtrlRegs.PIEIER6.bit.INTx2 = 1; // here Enabling SCI RX interrupt in PIE group 9 //429 intr
PieCtrlRegs.PIEIER6.bit.INTx1 = 1; // here Enabling SCI TX interrupt in PIE group 9

// This is needed to disable write to EALLOW protected registers
EDIS;
// IER |= 0x0020; // or M_INT6;
EINT; // Enabling interrupt
ERTM; // Enabling Global realtime interrupt DBGM

printf("transmitting\n");
}


void spi_tx(void)
{
//if (SpiaRegs.SPISTS.bit.INT_FLAG != 1) //checking tx is ready for data
if(SpiaRegs.SPIFFTX.bit.TXFFST == 0) //tx empty and ready for new data
{
printf("ready to transmit\n"); //print status of tx
SpiaRegs.SPITXBUF = Data;

// } //sending data over sci-a
}
else
{
printf("transmitter is not ready");
}
transdata = SpiaRegs.SPITXBUF; //reads transmitting data from SCITXBUF
printf("transmitter data: 0x%X\n",transdata);

Dataregister= SpiaRegs.SPIDAT;
printf("data in register is: 0x%X\n",Dataregister);



//ISR for transmit interrupt
interrupt void spi_tx_ISR()
{
//Clearing interrupt flag
SpiaRegs.SPIFFTX.bit.TXFFINTCLR = 1;
// Acknowledge this interrupt to receive more interrupts from group 9
PieCtrlRegs.PIEACK.all |= PIEACK_GROUP6;
}

THIS IS SLAVE MODE 

void init_spi() //function for config GPIO and SCI module
{

EALLOW;
SysCtrlRegs.PCLKCR0.bit.SPIAENCLK = 1; // enabiling peripheral clock
EDIS;

// Configure SpI module


SpiaRegs.SPICCR.all = 0x002F;
// SpiaRegs.SPICTL.bit.SPIINTENA =1;
SpiaRegs.SPICTL.bit.TALK = 0; //as SLAVE mode NO need of talk
SpiaRegs.SPICTL.bit.MASTER_SLAVE = 0; //as SLAVE mode make it 0
SpiaRegs.SPIBRR = BRR;

SpiaRegs.SPIFFRX.all = 0x2062;    //8;

EALLOW;
// Configure interrupts

PieVectTable.SPIRXINTA = &spi_Rx_ISR; // Assign ISR to the SCI RX interrupt
//Peripheral intialization
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // Enable the PIE block
PieCtrlRegs.PIEIER6.bit.INTx2 = 1; // here Enabling SCI RX interrupt in PIE group 9 //429 intr
//PieCtrlRegs.PIEIER6.bit.INTx1 = 1; // here Enabling SCI TX interrupt in PIE group 9

// This is needed to disable write to EALLOW protected registers
EDIS;
// IER |= 0x0020; // or M_INT6;
EINT; // Enabling interrupt
ERTM; // Enabling Global realtime interrupt DBGM

printf("transmitting\n");
}

void spi_Rx(void)
{


UNS16 start_time = clock();
printf("ready to receive\n");
receivedData = SpiaRegs.SPIRXBUF; //anil //reading received data

printf("receivedData : 0x%X\n", receivedData);

}

//ISR for reception interrupt
interrupt void spi_Rx_ISR()
{
//clearing overflow flag
SpiaRegs.SPIFFRX.bit.RXFFOVFCLR = 1;
// SpiaRegs.SPIFFRX.bit.RXFFOVFCLR = 1; //clearing overflow flag
SpiaRegs.SPIFFRX.bit.RXFFINTCLR = 1; //clearing interrupt flag

// Acknowledge this interrupt to receive more interrupts from group 9
PieCtrlRegs.PIEACK.all |= PIEACK_GROUP6; // Acknowledge interrupt to clear flag
}

Calling both TX and RX function in main.c and giving data globally in main.c 

and also can please tell me in two targets from which pin to which pin i need to connect like SIMO to SOMI or SIMO to SIMO and SOMI to SOMI. were to connect this SPICLKA pin is it CLKA to CLKA only?and as i am having only one slave do i need to connect SPISTEA pin from master to slave.? 

Can you please help me as soon as possible. 

Thanks & Regards,
Chaya 

  • and also can please tell me in two targets from which pin to which pin i need to connect like SIMO to SOMI or SIMO to SIMO and SOMI to SOMI. were to connect this SPICLKA pin is it CLKA to CLKA only?and as i am having only one slave do i need to connect SPISTEA pin from master to slave.? 

    If this is unclear to you, then likely this is the reason you are not receiving data. 

    SIMO (slave in, master out) would connected to SOMI (slave out, master in)

    SIMO (slave in, master out) would connected to SIMO

    SOMI (slave out, master in) would connected to SOMI

    CLKs would connect to each other.

    SPISTE pins would connect together. 

  • Hi, 

    Thank you for your reply. 

    It means i shouldn't connect SIMO to SOMI only? is my understanding correct? 

    i need to connect like SIMO to SIMO only. CLK to ground. 

    but in manual they given like CLK is connected CLK only in another target. 

  • It means i shouldn't connect SIMO to SOMI only? is my understanding correct? 

    Sorry, I made a mistake in my previous reply. You should connect the SOMI to SOMI and SIMO to SIMO. I have edited this in my previous response. The SPICLK pins connect to each other.

  • Hi,

    I had tried connecting pins like this only I am not able to receive data still. but in TXBUF and DATA register I am seeing data. 

    I tried to see waveform with oscilloscope for CLOCK and MOSI, to make sure where transmission is happening are not. even in that am not able to see waveform. 

    I tried connecting pin SIMO to SIMO, SOMI to SOMI, CLK to CLK and STE to ground (as to make it low) 

    I am doing like in two separate systems like one is having master code and one is having slave code connecting them to TMS320F28335 (2 targets) and connecting GPIO pins. 

    please can you help me with this. 

    Thanks & Regards,

    Chaya 

  • STE to ground (as to make it low) 

    May I ask why you are ground STE? This will make the SPI interface always active which can make it susceptible to noise. It's better if the master device drives STE on the slave device. 

    I tried to see waveform with oscilloscope for CLOCK and MOSI, to make sure where transmission is happening are not. even in that am not able to see waveform. 

    I looks like you have the SPI in reset. SPISWRESET needs to be 1 for SPI to operate. You also set a reserved bit. 

    Fullscreen
    1
    SpiaRegs.SPICCR.all = 0x002F;
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    You can also try this example on the master device:

    C:\ti\c2000\C2000Ware_5_00_00_00\device_support\f2833x\examples\spi_loopback

    The example will run in loopback mode by default. You'll want to modify the line below to disable loopback and see pin activity.

    Loopback:

    SpiaRegs.SPICCR.all =0x009F;

    No loopback:

    SpiaRegs.SPICCR.all =0x008F;

  • Hi, 

    Thank you So much for help. 

    I am connecting STE to ground because in document they mentioned like "An active SPISTE will not allow the slave to receive data." (in sec9.2.1). 

    so, i tried by connecting ground. 

    Now i had enabled reset bit. 

    When i am trying with loopback now data is getting transmitted and received. With hardware connection also I am able to transmit the data. 

    Thank you so much

    Thanks & Regards,

    Chaya 

  • I am connecting STE to ground because in document they mentioned like "An active SPISTE will not allow the slave to receive data." (in sec9.2.1). 

    This is correct, however, you would normally only activate SPISTE during an SPI transaction. If you keep SPISTE grounded all the time, the SPI slave will always be listening for data. This is not always desirable.