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.

CCS/TMS570LS1224: Working with SPI module

Part Number: TMS570LS1224
Other Parts Discussed in Thread: HALCOGEN

Tool/software: Code Composer Studio

Hello,

I am using TMS570LS1224 micro controller I found that SPI section in HalcoGens supports four different words for transferring.My question is that is it possible to use SPI1 and SPI2 four making 8 different packets of data?

If yes,how can I specify in my code that which SPI is for a specific word?

If no,is there any way to produce more than 4 packets of data?

  • Hello Nika,

    Yes, SPI module supports 4 independent data formats (data word length, bit rate, polarity, phase). Each word transmitted can select one of the 4 data formats to use via the bits DFSEL[1:0] in the control field of SPIDAT1.

    Data formats 0, 1, 2, and 3 can be configured through SPIFMTx control registers. The 4 data formats are independent. SPI1 and SPI2 are independent SPI modules.

    Same data format can be supported on multiple chip selects.

    This is the sample code of data format configuration for SPI1:

    /** - Data Format 0 */
    spiREG1->FMT0 = (uint32)((uint32)0U << 24U) /* wdelay */
    | (uint32)((uint32)0U << 23U) /* parity Polarity */
    | (uint32)((uint32)0U << 22U) /* parity enable */
    | (uint32)((uint32)0U << 21U) /* wait on enable */
    | (uint32)((uint32)0U << 20U) /* shift direction */
    | (uint32)((uint32)0U << 17U) /* clock polarity */
    | (uint32)((uint32)0U << 16U) /* clock phase */
    | (uint32)((uint32)79U << 8U) /* baudrate prescale */
    | (uint32)((uint32)16U << 0U); /* data word length */

    /** - Data Format 1 */
    spiREG1->FMT1 = (uint32)((uint32)0U << 24U) /* wdelay */
    | (uint32)((uint32)0U << 23U) /* parity Polarity */
    | (uint32)((uint32)0U << 22U) /* parity enable */
    | (uint32)((uint32)0U << 21U) /* wait on enable */
    | (uint32)((uint32)0U << 20U) /* shift direction */
    | (uint32)((uint32)0U << 17U) /* clock polarity */
    | (uint32)((uint32)0U << 16U) /* clock phase */
    | (uint32)((uint32)79U << 8U) /* baudrate prescale */
    | (uint32)((uint32)16U << 0U); /* data word length */

    /** - Data Format 2 */
    spiREG1->FMT2 = (uint32)((uint32)0U << 24U) /* wdelay */
    | (uint32)((uint32)0U << 23U) /* parity Polarity */
    | (uint32)((uint32)0U << 22U) /* parity enable */
    | (uint32)((uint32)0U << 21U) /* wait on enable */
    | (uint32)((uint32)0U << 20U) /* shift direction */
    | (uint32)((uint32)0U << 17U) /* clock polarity */
    | (uint32)((uint32)0U << 16U) /* clock phase */
    | (uint32)((uint32)79U << 8U) /* baudrate prescale */
    | (uint32)((uint32)16U << 0U); /* data word length */

    /** - Data Format 3 */
    spiREG1->FMT3 = (uint32)((uint32)0U << 24U) /* wdelay */
    | (uint32)((uint32)0U << 23U) /* parity Polarity */
    | (uint32)((uint32)0U << 22U) /* parity enable */
    | (uint32)((uint32)0U << 21U) /* wait on enable */
    | (uint32)((uint32)0U << 20U) /* shift direction */
    | (uint32)((uint32)0U << 17U) /* clock polarity */
    | (uint32)((uint32)0U << 16U) /* clock phase */
    | (uint32)((uint32)79U << 8U) /* baudrate prescale */
    | (uint32)((uint32)16U << 0U); /* data word length */

    Please refer to the HALCoGen SPI example code for data format selection. For example:

    spiDAT1_t dataconfig1_t,  dataconfig1_t;

    dataconfig1_t.CS_HOLD = FALSE;
    dataconfig1_t.WDEL = TRUE;
    dataconfig1_t.DFSEL = SPI_FMT_0;
    dataconfig1_t.CSNR = 0xFE;

    spiSendAndGetData(spiREG1, &dataconfig1_t, 2, TX_Data_Slave, RX_Data_Slave);

    dataconfig2_t.CS_HOLD = FALSE;
    dataconfig2_t.WDEL = TRUE;
    dataconfig2_t.DFSEL = SPI_FMT_1;
    dataconfig2_t.CSNR = 0xFE;

    spiSendAndGetData(spiREG2, &dataconfig2_t, 2, TX_Data_Slave, RX_Data_Slave);

  • Thanks a lot QJ Wang for your detailed guidance,

    Can I use these codes for mibSPI module too?

    MibSPI module section in HalcoGen,there is a part for data format and also a part for mibSPI transfer module but both has length part.What is the different?

  • Hello,

    The MibSPI module on TMS570 devices supports multi-buffered mode (MibSPI) and compatibility mode (regular SPI). The data format defined in SPIFMTx registers can be used for SPI mode and MibSPI mode. 

    The charlen field in FMTx register specifies the number of bits (2 to 16) in the data word. This value directs the SPI state machine to count the number of bits received and transmitted to determine when a complete word is transferred.

    In MibSPI, the data word format is selected via DFSEL field in TXRAM register. In SPI mode, it is selected via DESEL field of SPIDAT1 register.