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.

Problem while testing TMS470 as SPI Slave

Hi,

I am using TMS470 platform and testing SPI in slave mode. I wanted to read the data sent by Master.

Configurations:

Master: Aardvark SPI host adapter

Slave: TMS470

Master Buad rate: 125 Khz

Slave Buad rate: 100 Khz (Configured less than the Master baud rate)

Master SS Polarity: Active high

Below is my SPI configuration & ISR source code.

Problem:

I am facing below problems

1. I am sending 6 bytes from Master, But sometimes(not every time) only 4 bytes are received by TMS.

2. Data received in slave is not proper (It would be following scenarios, sometimes only last 4 bytes will be proper or all bytes are not proper, sometimes all are proper)

3. Known data(0xAAAA) sent from Slave also not received in Master properly, there are data corruption.

For me it looks like, there may be some problem with baud rate configuration. Could someone help me to get rid of this problem ?

If someone had source code, Kindly share with me.

Thanks in advance.

// Formula to calculate PRESCALE from baudrate

// x is in Khz

#define SPI_BAUDRATE(x) (((ICLK/1000) / (x)) - 1) // Return the prsecale value from the baudrate (x) in Khz

#define O_SPICTRL1_PRESCALE 5

#define M_SPICTRL1_PRESCALE 0x00001FE0

#define M_SPICTRL1_CHARLEN 0x0000001F

#define V_SPICTRL2_POLARITY_falling 0x0002

#define V_SPICTRL2_PHASE_nodelay 0

#define M_SPIPCx_SCS 0x10

#define M_SPIPCx_SOMI 0x08

#define M_SPIPCx_SIMO 0x04

#define M_SPIPCx_SICLK 0x02

#define V_SPICTRL3_OVRNINTEN_On 0x0008

#define V_SPICTRL3_RXINTEN_On 0x0002

UWord32 CharLen=16; //16-bits

UWord32 ClkSpeed=100; //in Khz

Void SPI_configurel()

{

UWord8 PrescaleVal;

UWord32 TempRegVal;

UWord32 Speed;

UWord32 MinBaud;

UWord32 MaxBaud;

//Procedure:

// 1) Clear SPIENA to 0 to enter in configuration mode

// 2) Select the desire Char lenght

// 3) Select the Baud Rate

// 4) Select the frame format

// 5) Configure the pin to works in SPI

// 6) Conf the IT and enable if in MASTER

// 7) Enable RX interrupt

//8) Set SPIENA To 1 to exit conf mode

//**********************************************************************************

// 1) Clear SPIENA to 0 to enter in configuration mode

SPICTRL2(this->mModID) = 0; // Reset the Register ENTER in Confmoide (Cell in reset);

// 2) Select the desire Char lenght

TempRegVal = (M_SPICTRL1_CHARLEN & CAST(UWord32)(CharLen));

// End MISRA rule 43 correction

// 3) Select the Baud Rate

PrescaleVal = CAST(UWord8) (SPI_BAUDRATE(Speed));

TempRegVal |= CAST(UWord32)(PrescaleVal << O_SPICTRL1_PRESCALE) & M_SPICTRL1_PRESCALE;

SPICTRL1(CAST(UWord32)(this->mModID)) = TempRegVal;

// 4) Select the frame format

TempRegVal = V_SPICTRL2_POLARITY_falling;

TempRegVal |= V_SPICTRL2_PHASE_nodelay; // no phase

TempRegVal |= V_SPICTRL2_CLKMOD_Ext| V_SPICTRL2_MASTER_Slave;

SPICTRL2(this->mModID) = TempRegVal;

// 5) Configure the pin to works in SPI

TempRegVal = M_SPIPCx_SICLK; // Clk is always used

TempRegVal |= M_SPIPCx_SCS; // Chip select

TempRegVal |= M_SPIPCx_SIMO; // MOSI

TempRegVal |= M_SPIPCx_SOMI; // MISO

SPIPC6(this->mModID) = TempRegVal;

// 6) Conf the IT and enable if in MASTER

SPIBUF(this->mModID); // Dummy read of SPIBUF to clear flags

// 7) Enable RX interrupt

SPICTRL3(this->mModID) |= V_SPICTRL3_OVRNINTEN_On | V_SPICTRL3_RXINTEN_On;

// 8) Set SPIENA To 1 to exit conf mode

SPICTRL2(this->mModID) |= V_SPICTRL2_SPIEN_ON;

}

rx_isr()

{

UWord32 ReadReg;

ReadReg = SPIBUF(this->mModID); // Read the 16-bit data

SPIDAT0(this->mModID) = 0xAAAA; // Perform dummy write

memcpy(&transmissionBuffer[count],&value,sizeof(UWord16)); // Copy the data to buffer

count += sizeof(UWord16);

}

Thanks & Regards,

Uvais.

  • Hi Uvais,

    To work as Slave Baudrate ( prescale need not be configured) so i guess baud rate is not an issue,
    1) Can be Clk mode or polarity issue - Please check the Master's clk mode and polarity and match the slave configuration.  
    2) Can be the delay configuration between transfers..

    Sorry i have not worked much on TMS470R1X series of devices..

    Please be aware that the TMS470R1 Series (including the TMS470R1VF48 device) is not recommended for new designs.  Please see the full 'NRDN' notice here.

    Soon TI will be launching the new TMS470M series of microcontrollers.  This series will feature greater ARM CPU performance and a similar peripherial set to the TMS470R1 Series of microcontrollers.  Please come back soon for more information about the TMS470M Series of microcontrollers.  The product preview for the first two microcontrollers in the TMS470M series is available here: TMS470MF0660x - SPNS157. The TMS470M Series Technical Reference Manual is available here: TMS470M TRM.

    If you are just getting started with the TMS470R1VF48 microcontroller, I would highly recommend looking into using one of the TMS470M Series of microcontrollers instead. 

    Regards
    Prathap