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.

TMS570LS1224: SPI communication

Part Number: TMS570LS1224
Other Parts Discussed in Thread: HALCOGEN, TMS5701224

i have tms570ls1224 development board.

i want to configure SPI3 through halcogen .please guide me.

  • Hello,

    1. HALCoGen --> Driver Enable: enable SPI3

    2. HALCoGen-->SPI3-->SPI3 Global: configure mode, clock

    3. HALCoGen-->SPI3-->SPI3 Data Format: Data formats 0, 1, 2, and 3 can be configured through SPIFMTx control registers.

    4. HALCoGen-->SPI3-->SPI3 Delay: Youc an use the default

    5. Save project, generate code

    http://www.ti.com/lit/an/spna121b/spna121b.pdf

  • Thank you so much for your reply.I have TMS570LS1224PGE microcontroller i want to setup SPI

    in master mode and another board acts as a slave mode.so how to setup master for the same through HALCOGEN,through interrupt method.

    and is it necessary to Toggle chip select pin.

  • Hello,

    Please use the HALCOGen example to learn how to configure SPI in HALCoGen.

  • https://e2e.ti.com/cfs-file/__key/communityserver-discussions-components-files/312/0871.spi3_5F00_test.7z

  • This is my setup is it correct or not please check once.

    my halcogen version is 04.07.01

  • Hello,

    The attached file contains only *.hcg file. The *.dil file is where the settings are stored.

    To use interrupts you have to enable SPI1 High/Low interrupt in VIM module.

    In HALCoGen examples folder you can find "example_spi_Master_Slave.c" file where you can see how to use SPI module.

    Best regards,
    Miro

  • Hello,

    Please, set all unused SPI3 pins as GIO from SPI3-->SPI3 Port Tab. All other setting looks fine for me.

    You should check timing diagrams of both Master and Slave and select appropriate SPI Mode ( polarity and phase ) for SPI3.

    Clocking Modes and timing diagrams for TMS570LS1224 are shown in TRM, Section 28.2.7

  • If set all unused SPI3 pins as GIO .cs is not toggling.

    is it necessary to activate RXINT in SPI GLOBAL.

    Because reception is not happening.

    please guide me.

  • Hello,

    If you use CS[0] as SPI functional pin, you can configure CS[5~1] as GIO. 

    You don't have to enable RXINT. 

  • Right now i am using cs[2].for chip select.

    but if i select any cs pin as a gio.cs[0] to cs[5].and i selected cs[2] as a spi.

    it is not working.

    Please check once where am i doing mistake.

    6354.spi3_integr_test.zip

  • Hello,

    The SPI3 is not enabled in your HALCoGen configuration.

    Please uncheck "Enable MibSPI driver" and Check "Enabe SPI3 driver". 

  • I have Enabled this. but there is no response in SOMI pin.

  • Hello,

    Please check the WRCOMM commands and RDCOMM commands used in your project, and make sure your code follows the protocol defined in LTC6813 datasheet.

  • LTC6813 requires that clock phase=1 and clock polarity=1:

  • Yes, same code is working on STM32F429 development board.

    There is no issue in LTC file.

    sir how to set clock phase and clock polarity in HALCOGEN ?

    i have already set cpha and cpol is 1 in LTC board.

  • HalCoGen: SPI3-->SPI3 data formats

  • Yes i did cpol=1,cpha=0

    And cpol=1,cpha=1

    cpol=0,cpha=1

    For master communication.

    But there is nothing coming in SOMI pin.

    Now what should i check..?

  • I need 1 lakh ic.so please help me.

  • Hello Gautam,

    Please make sure that the LTC is transmitting data to TMS570. 

    1. Is SPI EN used in your setup? If this signal is used, an active-low signal from the slave on the SPIENA pin allows the master SPI to drive the clock pulse stream. A high signal tells the master to hold the clock signal (and delay SPI activity).

    2. If the LTC requires the CS LOW between COMMANDS transmitting and the following data write/read, you may need to set the CSHOLD bit for SPI_write_read() and SPI_Write_xx() functions.

  • Hello ,

    1. No i am not using SPI EN.

    2.I am using cs[2] as a gio.because i want at the time of send and receive command cs is low.after cs will high.   

    3.My clock is not working fine.what should i do ?

  • if i am using like this,some response is coming in SOMI pin.but not correct response.

    cs_low();

    spiSendAndGetData(spiREG3,&dataconfig1_t,dataLen,&tx_dat,rx_data);

    while(SpiRxStatus(spiREG3) ==1);
    delay_sec(1);
    cs_high();

  • Hello,

    What do you mean "My clock is not working fine"?

    The SPI master has to provide clock for slave to transmit data back to the master. The master sends commands to slave, and needs to send dummy data to deliver clock to slave.

    If the slave wants to send 2 bytes data back, the master needs to send 2 bytes dummy data after the commands.

  • Hello 

    Now all are working fine .but only i am able to read 2 battery data.

    Please review once.

    2476.spi3_integr_test.zip

  • Hello,

    The SPI driver works now: you can transmit data and receive data correctly. How many data are expected from the slave? As I said, if the slave will transfer 6 bytes data, the master has to send 8 bytes dummy data. 

    BTW, you may need add wait (WDELAY) between reading the data from each battery. Please check with ITC support about the delay.

  • i want  transmit each time 1 byte like uint8.

    but in spiSendData function required uint16.

    so i had changed data types  uint8 to uint16.

    is any error due to this?

    if yes then what should i do? 

    2.I want to send data through interrupt and receive through polling method.

    Please guide me how to do.

    some output is coming correctly.

  • If the device only supports byte (uint8), you have to modify charlen in SPI driver to 8, and change uint16 to uint8 in SPI driver manually. For example:

    uint32 spiTransmitData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff)

    -->

    uint32 spiTransmitData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint8 * srcbuff)

  • I have done this things also. 

    but this type of output is coming.whole output is not coming.

    so what should i do.

  • Hi,

    Now, there is no problem for TMS570 SPI to write and read data. I think the protocol commands defined in slave datasheet are not used correctly in your code to get the whole output. I don't have this kind of slave device, so I am not able to help you debug the code.  

  • Thank  you so much for your support. 

    How to change spi baudrate through spi init function.

    example if i want to make speed as a 500kbps.

    Not through Halcogen.

  • Hello,

    You can change the baudrate by changing the prescale value in SPI data format register (SPIFMT).

    BR = VCLK/(PRESCALE+1)

  • Hello,

    Can You help me configure MIBSPI3 as a master mode .which is transmit data from interrupt method and receive data from Polling method.through HALCOGEN.

  • Hello,

    Can you please open a new thread for this new question?

  • Thanks for your reply.

    Yes i can.but my previous issue did't solve.

    so i am trying to check with Mibspi.

  • Hii QJ Wang,

    If u don't mind ,i am ready to give you remote access of my system.

    By the help of this please resolve my issue.

    Because it is very urgent for me.

  • Hii QJ Wang,

    Please respond.

  • Hello,

    I am sorry that I am not able to access your PC to debug your code. As I said, your SPI code can transmit data and receive data. To receive correct data from the slave, you have to follow the protocol defined the slave datasheet. 

  • Hello,

    I want to know about SPI3DELAYS configuration through HALCOGEN.

    Please see once ,is it correct.

  • Hello,

    The diagram you attached is not aligned well.

    1. C2TDELAY (Chip-select-active to transmit-start delay): default value is 2*VCLK period, tC2TDELAY = (C2TDELAY + 2) × VCLK Period.

        tC2TDELAY = 150 if C2TDELAY = 10 if VCLK=80MHz

    2. T2CDELAY (Transmit-end-to-chip-select-inactive-delay): default value is 1*VCLK period. tT2CDELAY = (T2CDELAY +1) × VCLK Period.

        tT2CDELAY = 125 if T2CDELAY = 10 if VCLK=80MHz

    3. T2EDELAY (Transmit-data-finished to ENA-pin-inactive time-out): the default value is  0, tT2EDELAY = T2EDELAY*SPIclock

        tT2EDELAY = 19.210 if T2EDELAY = 6, SPIClk=

    4. C2EDELAY (Chip-select-active to ENA-signal-active time-out): the default value is  0, tC2EDELAY = C2EDELAY*SPIclock

  • Hi,

    so what should i do.

  • I configured spi3 as a master. and took cs2 as a chip select.but when i send data through spi send function then cs pin is pin is not working.

    How to activate cs2 pin

     spiSendData(spiREG3,&dataconfig1_t,6,tx_Data);

    spiDAT1_t dataconfig1_t;
    dataconfig1_t.CS_HOLD = true;
    dataconfig1_t.WDEL = false;
    dataconfig1_t.DFSEL = SPI_FMT_0 ;
    dataconfig1_t.CSNR = SPI_CS_2 ;

  • Please make sure the SPI3 is checked under "Driver Enable".

    For SPI communication, refer to SPI chapter in TRM (SPNU515C).

  • hi Wang,

    My spi is working ,that is why some result is coming.

    I have already enabled  spi driver .

    please check and please give me a proper solution.because till date my issue did't resolve.

  • Sorry. What is your real question?

  • Hi Wang,

    Again i am explaining what is my problem.

    1-> I have TMS5701224 dev board.and LTC6813 (DC2350A-B) slave and LTC6820(1941D) interface board.

    Now i am trying to interface LTC6813 to TMS570LS1224 dev board through ISOSPI communication.

    But unfortunately i am able to read only few data which is showing in attachement.

    so i want your help where i am wrong.

    2-> When i am interfacing with other controller like STM32F429.Then it is working fine.

  • Hello,

    As I said, I don't the protocol required by LTC6813 device.

    Does the wakeup_idle(TOTAL_IC) return the correct data?

    Which function is used to read the data showed in your post? How many bytes data are expected? What should be the correct data values?

  • Hi Wang,

    As i discussed earlier NO first 4 byte it receiving 0xff .I attached one screen short for this.

    And 8 byte of data i am expecting.

    for sending i am using this.

    void spi_write_array(uint8_t len, // Option: Number of bytes to be written on the SPI port
    uint8_t data[] //Array of bytes to be written on the SPI port
    )
    {
    spiDAT1_t dataconfig1_t;
    dataconfig1_t.CS_HOLD = false;
    dataconfig1_t.WDEL = false;
    dataconfig1_t.DFSEL = SPI_FMT_0 ;
    dataconfig1_t.CSNR = SPI_CS_2 ;

    p=len;
    //while(HAL_SPI_GetState(&hspi6)!=HAL_SPI_STATE_READY);
    cs_low();
    // HAL_SPI_Transmit(&hspi1,data,len,5000);
    //for(p=0;p<len;p++)
    //data1[p]=data[p];
    spiSendData(spiREG3,&dataconfig1_t,len,data);
    delay_ms(10);
    //delay_sec(1);
    cs_high();

    }

    And i am receiving for this.

    void spi_write_read(uint8_t tx_Data[],//array of data to be written on SPI port
    uint8_t tx_len, //length of the tx data arry
    uint8_t *rx_data,//Input: array that will store the data read by the SPI port
    uint8_t rx_len //Option: number of bytes to be read from the SPI port
    )
    {
    int i;
    spiDAT1_t dataconfig1_t;
    dataconfig1_t.CS_HOLD =false;
    dataconfig1_t.WDEL = false;
    dataconfig1_t.DFSEL = SPI_FMT_0 ;
    dataconfig1_t.CSNR = SPI_CS_2 ;
    n=tx_len;
    //while ((HAL_SPI_GetState(&hspi6) != HAL_SPI_STATE_READY));
    cs_low();
    spiSendData(spiREG3,&dataconfig1_t,6,tx_Data);
    //delay_ms(1);
    //delay_sec(1);
    spiGetData(spiREG3,&dataconfig1_t,rx_len,rx_data);
    //spiSendAndGetData(spiREG3,&dataconfig1_t,16,tx_Data, rx_data);
    delay_ms(10);
    //while(SpiRxStatus(spiREG3) ==1);
    //delay_sec(1);

    cs_high();
    //delay_ms(500);*/
    //HAL_SPI_Transmit(&hspi1,tx_Data,tx_len,5000);

    ////cs_high();
    //HAL_SPI_Receive(&hspi1,rx_data,rx_len,5000);
    //cs_low();
    // spiSendData(spiREG3,&dataconfig1_t,tx_len,tx_Data);

    /* for( n=0;n<=tx_len;n++)
    tx1_Data[n]=tx_Data[n];
    delay_ms(500);
    cs_high();
    delay_ms(500);
    cs_low();
    spiGetData(spiREG3, &dataconfig1_t, rx_len, rx_data);
    delay_ms(500);
    cs_high();*/

    for( i=0;i<=rx_len;i++)
    rx1_data[i]=rx_data[i];
    for( i=0;i<=tx_len;i++)
    tx1_Data[i]=tx_Data[i];
    }

  • Hello,

    While writing any command to LTC6813-1, the command bytes CMD0 and CMD1 (see Table 37 and Table 38) and the PEC bytes PEC0 and PEC1 are sent in the following order: CMD0, CMD1, PEC0, PEC1

    The commands are listed in Table 36 (command codes).

    Did you follow the protocols defined in LTCx device?

    What commands do you use for starting the ADC conversion and reading the ADC data?

  • Hi,

    //Starts cell voltage conversion
    void LTC681x_adcv( uint8_t MD, //ADC Mode
    uint8_t DCP, //Discharge Permit
    uint8_t CH //Cell Channels to be measured
    )
    {
    uint8_t cmd[2];
    uint8_t md_bits;
    md_bits = (MD & 0x02) >> 1;
    cmd[0] = md_bits + 0x02;
    md_bits = (MD & 0x01) << 7;
    cmd[1] = md_bits + 0x60 + (DCP<<4) + CH;
    cmd_68(cmd);
    }

    //This function will block operation until the ADC has finished it's conversion
    uint32_t LTC681x_pollAdc()
    {
    uint32_t counter = 0;
    uint8_t finished = 0;
    uint8_t current_time = 0;
    uint8_t cmd[4];
    uint16_t cmd_pec;


    cmd[0] = 0x07;
    cmd[1] = 0x14;
    cmd_pec = pec15_calc(2, cmd);
    cmd[2] = (uint8_t)(cmd_pec >> 8);
    cmd[3] = (uint8_t)(cmd_pec);


    spi_write_array(4,cmd);

    while ((counter<200000)&&(finished == 0))
    {
    current_time = spi_read_byte(0xff);
    if (current_time>0)
    {
    finished = 1;
    }
    else
    {
    counter = counter + 10;
    }
    }

    return(counter);
    }

    //Generic function to write 68xx commands. Function calculated PEC for tx_cmd data
    void cmd_68(uint8_t tx_cmd[2])
    {
    static uint8_t cmd[4];
    uint16_t cmd_pec = 0x00;
    //uint8_t md_bits;
    cmd[0] = tx_cmd[0];
    cmd[1] = tx_cmd[1];
    cmd_pec = pec15_calc(2, cmd);
    cmd[2] = (uint8_t)(cmd_pec >> 8);
    cmd[3] = (uint8_t)(cmd_pec);

    spi_write_array(4,cmd);
    }

    //Reads and parses the LTC681x cell voltage registers.
    uint8_t LTC681x_rdcv(uint8_t reg, // Controls which cell voltage register is read back.
    uint8_t total_ic, // the number of ICs in the system
    cell_asic *ic // Array of the parsed cell codes
    )
    {
    int8_t pec_error = 0;
    uint8_t *cell_data;
    uint8_t c_ic = 0;
    uint8_t cell_reg;
    uint32_t current_ic;
    cell_data = (uint8_t *) malloc((NUM_RX_BYT*total_ic)*sizeof(uint8_t));

    if (reg == 0)
    {
    for (cell_reg = 1; cell_reg<ic[0].ic_reg.num_cv_reg+1; cell_reg++) //executes once for each of the LTC6811 cell voltage registers
    {
    LTC681x_rdcv_reg(cell_reg, total_ic,cell_data );
    for (current_ic = 0; current_ic<total_ic; current_ic++)
    {
    if (ic->isospi_reverse == false)
    {
    c_ic = current_ic;
    }
    else
    {
    c_ic = total_ic - current_ic - 1;
    }
    pec_error = pec_error + parse_cells(current_ic,cell_reg, cell_data,
    &ic[c_ic].cells.c_codes[0],
    &ic[c_ic].cells.pec_match[0]);
    }
    }
    }

    else
    {
    LTC681x_rdcv_reg(reg, total_ic,cell_data);

    for ( current_ic = 0; current_ic<total_ic; current_ic++)
    {
    if (ic->isospi_reverse == false)
    {
    c_ic = current_ic;
    }
    else
    {
    c_ic = total_ic - current_ic - 1;
    }
    pec_error = pec_error + parse_cells(current_ic,reg, &cell_data[8*c_ic],
    &ic[c_ic].cells.c_codes[0],
    &ic[c_ic].cells.pec_match[0]);
    }
    }
    LTC681x_check_pec(total_ic,CELL,ic);
    free(cell_data);
    return(pec_error);
    }

    //This function will block operation until the ADC has finished it's conversion
    uint32_t LTC681x_pollAdc()
    {
    uint32_t counter = 0;
    uint8_t finished = 0;
    uint8_t current_time = 0;
    uint8_t cmd[4];
    uint16_t cmd_pec;


    cmd[0] = 0x07;
    cmd[1] = 0x14;
    cmd_pec = pec15_calc(2, cmd);
    cmd[2] = (uint8_t)(cmd_pec >> 8);
    cmd[3] = (uint8_t)(cmd_pec);


    spi_write_array(4,cmd);

    while ((counter<200000)&&(finished == 0))
    {
    current_time = spi_read_byte(0xff);
    if (current_time>0)
    {
    finished = 1;
    }
    else
    {
    counter = counter + 10;
    }
    }

    return(counter);
    }