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.

TMS320F280049C: SPI data read shifted

Former Member
Former Member
Part Number: TMS320F280049C

Hi,

I am currently working on a project in which I make two microcontrollers communicate through the spi. In this project I have to send a state from the first microcontroller to the second one in order to control it and keep it in the same state.

In summary I send either state 1 or state 0 by spi.

I noticed during tests that the state read by the slave is sometimes shifted and there is no way to resynchronize the reading without doing a reset, which makes me think that the problem comes from the slave.

So I send you my code here hoping that you can help me (not in order).

//
// spi_slave_init - Configure the SPI for the lead board
//
void spi_slave_init(void)
{
SPI_disableModule(SPIA_BASE); // Disable SPI A to configure and reset
SPI_reset(SPIA_BASE);

SPI_setConfig(SPIA_BASE, DEVICE_LSPCLK_FREQ, // Configure SPI A as SLAVE with 16 bits transfer at 500kHz
SPI_PROT_POL0PHA0,
SPI_MODE_SLAVE, 500000, 16);
SPI_disableLoopback(SPIA_BASE);
SPI_setEmulationMode(SPIA_BASE, SPI_EMULATION_FREE_RUN);

//
// FIFO and interrupt configuration
//
SPI_enableFIFO(SPIA_BASE);
SPI_clearInterruptStatus(SPIA_BASE, SPI_INT_RXFF);
SPI_setFIFOInterruptLevel(SPIA_BASE, SPI_FIFO_TX1, SPI_FIFO_RX1);
SPI_enableInterrupt(SPIA_BASE, SPI_INT_RXFF);

SPI_enableModule(SPIA_BASE); // Enable SPI A to start communication
}

//
// spi_slave_gpio_init - Configure the SPI GPIO for the slave
//
void spi_slave_gpio_init(void)
{
EALLOW;

GPIO_setMasterCore(SPIA_CLK, GPIO_CORE_CPU1);
GPIO_setMasterCore(SPIA_STE, GPIO_CORE_CPU1);
GPIO_setMasterCore(SPIA_SIMO, GPIO_CORE_CPU1);
GPIO_setMasterCore(SPIA_SOMI, GPIO_CORE_CPU1);

GPIO_setDirectionMode(SPIA_CLK, GPIO_DIR_MODE_IN); // Configure SCLK as input
GPIO_setDirectionMode(SPIA_STE, GPIO_DIR_MODE_IN); // Configure Slave Select as input
GPIO_setDirectionMode(SPIA_SIMO, GPIO_DIR_MODE_IN); // Configure SPI Slave Input Master Output as input
GPIO_setDirectionMode(SPIA_SOMI, GPIO_DIR_MODE_OUT); // Configure SPI Slave output Master Input as output

GPIO_setPinConfig(GPIO_56_SPIA_CLK); // Set the pin 56 as SCLK
GPIO_setPinConfig(GPIO_57_SPIA_STE); // Set the pin 57 as Slave Select
GPIO_setPinConfig(GPIO_16_SPIA_SIMO); // Set the pin 16 as SIMO
GPIO_setPinConfig(GPIO_17_SPIA_SOMI); // Set the pin 17 as SOMI

GPIO_setQualificationMode(SPIA_CLK,GPIO_QUAL_SYNC); // No synchronization
GPIO_setQualificationMode(SPIA_STE,GPIO_QUAL_SYNC); // No synchronization
GPIO_setQualificationMode(SPIA_SIMO,GPIO_QUAL_SYNC); // No synchronization
GPIO_setQualificationMode(SPIA_SOMI,GPIO_QUAL_SYNC); // No synchronization

EDIS;
}

void spi_data_received(void)
{
static uint16_t oldSpiDataReceived = 0;

spiDataReceived = SPI_readDataBlockingFIFO(SPIA_BASE); //SPI_receive16Bits(SPIA_BASE, SPI_DATA_BIG_ENDIAN, 0, 0);

if((spiDataReceived == 0)&&(spiDataReceived != oldSpiDataReceived))
{
BUCK_HBridgePwrOnOff = 0;
BUCK_HBridge24vOnOff = 0;
BUCK_Hbridge24vOffState();
BUCK_HbridgePwrOffState();

oldSpiDataReceived = spiDataReceived;
}
else if((spiDataReceived == 1)&&(spiDataReceived != oldSpiDataReceived))
{
//
// Initialize global variables used in solution
//
BUCK_initUserVariables();
BUCK_initProgramVariables();
BUCK_HBridgePwrEnState = HbPwrEnState_Init;

oldSpiDataReceived = spiDataReceived;
}

}

__interrupt void INT_mySPIA_RX_ISR(void)
{
spi_data_received();


SPI_resetRxFIFO(SPIA_BASE);
Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP6);
SPI_clearInterruptStatus(SPIA_BASE, SPI_INT_RXFF);
}

Here is an example of what I can read on the slave when the data is shifted.

I am sending '1' through SPI and i read '32768'.

Thank you in advance for your answer !

  • Lorend,

    As a SPI slave, what are you expecting to receive from master? Is it all 0xFFFF? Are you receiving 0x7FFF? Are you sure both master and slave are configured in sending data in SPI_PROT_POL0PHA0 mode?

    Regards,

    Manoj

  • Former Member
    0 Former Member in reply to Manoj Santha Mohan

    Hi Manoj,

    Thank you very much for your reply,

    I found the issue, it was Hardware. The connection of the STE was bad.

    I have one more question.

    Is it possible to make SPI work without using STE ? In my project only 1 master and 1 slave are communicating.

    I saw in the Technical Reference Manual that not using the STE was not recommended but I would like to use the pin of the STE for another task.

    Thank you, best regards,

    Lorend

  • Is it possible to make SPI work without using STE ? In my project only 1 master and 1 slave are communicating.

    No, you cannot use SPI without using STE pin. If you want to use 3-pin SPI mode, you can consider using SPICLK, SPISTE and SPISIMO (SIMO and SOMI pins are internally connected).