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.

TMS570LC4357: TMS570LC4357 :: MibSPI master and slave communication

Part Number: TMS570LC4357
Other Parts Discussed in Thread: HALCOGEN,

TI Team,

I'm having a simple query regarding MibSPI communication between two launch pads (LaunchXL2-TMS570LC4357). One board is configured as a master and another board is configured as a slave. HALCoGen configuration for Master is as shown in the images below:

Slave configuration is also same but two differences:

  • Master Mode chebox is unchecked
  • Internal Clock checkbox is unchecked 

Both the boards are connected through external headers as shown in the image below:

The HL_sys_main.c file for master and slave are as follows:

/* USER CODE BEGIN (0) */
/* USER CODE END */

/* Include Files */

#include "HL_sys_common.h"

/* USER CODE BEGIN (1) */
#include "HL_mibspi.h"
#define data_length 16
unsigned long counter1 = 0;
bool transmit_flag = 0;
/* USER CODE END */

/** @fn void main(void)
*   @brief Application main function
*   @note This function is empty by default.
*
*   This function is called after startup.
*   The user can use this function to implement the application.
*/

/* USER CODE BEGIN (2) */
/* USER CODE END */

int main(void)
{
/* USER CODE BEGIN (3) */
    uint16 tx_data[data_length] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};

    uint16 rx_data[data_length] = {0};

    _enable_IRQ_interrupt_();

    mibspiInit();

    mibspiEnableGroupNotification(mibspiREG1, 0, 1);

    // mibspiEnableLoopback(mibspiREG1, Analog_Lbk);

    while(1)
    {
        if(transmit_flag == 0)
        {
            mibspiSetData(mibspiREG1, 0, &tx_data[0]);
            mibspiTransfer(mibspiREG1, 0);
            transmit_flag=1;
        }
        /* if(mibspiIsTransferComplete (mibspiREG1, 0))
        {
            transmit_flag=0;
        }*/
    }
    // while(!(mibspiIsTransferComplete (mibspiREG1, 0)));

    // mibspiGetData(mibspiREG1, 0, &rx_data[0]);

    while(1);
    /* USER CODE END */

    return 0;
}


/* USER CODE BEGIN (4) */
void mibspiGroupNotification(mibspiBASE_t *mibspi, uint32 group)
{
    printf("\n Transfer %d completed!!", counter1);
    printf("\n");
    counter1++;
    transmit_flag = 0;
}
/* USER CODE END */

/* USER CODE BEGIN (0) */
/* USER CODE END */

/* Include Files */

#include "HL_sys_common.h"

/* USER CODE BEGIN (1) */
#include "HL_mibspi.h"
#define data_length 16
unsigned char rx_data[data_length] = {0};
unsigned long counter1 = 0;
bool receive_flag = 1;          // this value is initialized to 1 becasue, the SPI transfer function shall only execute when the data is received.
                                // Hence, the moment any data is received on SPI receive buffer, Group Notification function will execute.
                                // This will set the flag value to 0 and then the received data will be processed.
/* USER CODE END */

/** @fn void main(void)
*   @brief Application main function
*   @note This function is empty by default.
*
*   This function is called after startup.
*   The user can use this function to implement the application.
*/

/* USER CODE BEGIN (2) */
/* USER CODE END */

int main(void)
{
/* USER CODE BEGIN (3) */

    _enable_IRQ_interrupt_();

    mibspiInit();

    mibspiEnableGroupNotification(mibspiREG1, 0, 1);

    while(1)
    {
        // if(receive_flag == 0)
        {
            mibspiTransfer(mibspiREG1, 0);
            // receive_flag = 1;
        }
    }
/* USER CODE END */

    return 0;
}


/* USER CODE BEGIN (4) */
void mibspiGroupNotification(mibspiBASE_t *mibspi, uint32 group)
{
    uint16 *data;
    data = &rx_data[0];
    mibspiGetData(mibspi, group, data);
}
/* USER CODE END */

Problem Statement:

  • Master program seems to be working fine as I'm able to see the transmited data on oscilloscope and on CCS console as well/
  • I'm not able to receive any data in Slave device.

I think there is some minor mistake in either HALCoGen config for Slave device or logical mistake in HL_sys_main.c file for slave. Can someone please help?

Regards,

Trivedi

  • HI Trivedi,

    If the SPI enable signal is not used, the MibSPI master should wait for 6 VCLK cycles before sending the SPI clock to begin the transaction. 

  • Thanks for the prompt response Wang!

    If the SPI enable signal is not used, the MibSPI master should wait for 6 VCLK cycles before sending the SPI clock to begin the transaction. 

    I had referred to the TRM for TMS570LC4357 device and had idea on this thing. I again referred to the TRM and noted the following in continuation to my query:

    • To configure the device in slave mode, only CLKMOD and MASTER bits are required to be cleared. This can be done through:
      • HALCoGen  ---> MIBSPI1 ---> MIBSPI1 Global ---> Master Mode and Internal Clock Check boxes. 
      • Question 1: Is this understanding correct or there is something else as well which need to be considered?
    • Question 2: If I want to use 3 pin MibSPI mode (MOSI, MISO and SCLK only, without CS and ENA pins), then what modification is required in my code that I shared earlier?
    • Question 3: If I want to use 4 pin MibSPI mode, i.e. MOSI, MISO, SCLK and ENA pins, then what shall be my HALCoGen configuration? Shall I check "wait for Enable" checkbox in master and slave configuration both?

    Regards,

    Trivedi

  • one more question Wang!

    Since my implementation is based on Interrupt, does this 6 VCLK really matter? Should it not generate the interrupt as soon as it receives the data, be it after 6 VLCK or 60 VCLK?

    And also, since VCLK is 75 MHz and SCLK is around 1 MHz, there would be many VCLK completed before SCLK starts. 

    Regards,

    Trivedi

  • Question 1: Is this understanding correct or there is something else as well which need to be considered?

    You are correct. The SPI clock is provided by SPI master.

    Question 2: If I want to use 3 pin MibSPI mode (MOSI, MISO and SCLK only, without CS and ENA pins), then what modification is required in my code that I shared earlier?

    In Mispi slave mode, only the SPI nCS pins can trigger a Transfer Group (TG). For 3-pin mode, just TG0 can be triggered. The PRST field of TGxCTRL should be cleared to 0.

    Question 3: If I want to use 4 pin MibSPI mode, i.e. MOSI, MISO, SCLK and ENA pins, then what shall be my HALCoGen configuration? Shall I check "wait for Enable" checkbox in master and slave configuration both?

    Yes, "wait for enable" should be checked in master side. Same as #2, only TG0 is used to receive data.

  • Without extra 6 vclk cycles delay, the slave may not transfer correct data.

  • Hello Wang,

    In Mispi slave mode, only the SPI nCS pins can trigger a Transfer Group (TG). For 3-pin mode, just TG0 can be triggered. The PRST field of TGxCTRL should be cleared to 0.

    This still did not answer my question. I understood that in 3 pin mode, I can use only TG0 for MibSPI communication. If you look at my code in the initial query, I'm using TG0 only. However, I'm still not receiving any data. I've enabled Group Notification for MibSPI communication for TG0. Hence, if after 6 VCLK Master sends clock and data, TMS570 Slave shall be able to receive data and an interrupt shall be generated as soon as the data is received. However, I'm not able to do so.

    I've gone through TRM that suggests the same. But I'm still not thorough with the understanding:

    • How do I clear PRST?
    • How frequent do I need to clear the PRST field?

    Do you have any example project for TMS570LC4357 working in Slave configuration? Can you share it?

    Regards,

    Trivedi

  • Also, as highlighted in my screenshot, the Chip Select has been highlighted as CS_0, for three pin mode, shall it be CS_None ?

  • Hi Trivedi,

    For 3-pin mode, please configure CS0 of SPI slave as GIO mode?

    mibspiREG1->PC0 = (uint32)((uint32)0U << 0U)     /* SCS[0] */
                                    | (uint32)((uint32)0U << 1U)     /* SCS[1] */
                                    | (uint32)((uint32)0U << 2U) /* SCS[2] */
                                    | (uint32)((uint32)0U << 3U) /* SCS[3] */
                                    | (uint32)((uint32)0U << 4U) /* SCS[4] */
                                    | (uint32)((uint32)0U << 5U) /* SCS[5] */
                                    | (uint32)((uint32)0U << 8U) /* ENA */
                                    | (uint32)((uint32)1U << 9U) /* CLK */
                                    | (uint32)((uint32)1U << 10U) /* SIMO */
                                    | (uint32)((uint32)1U << 11U); /* SOMI */

  • Hello Wang,

    I'm still not able to understand the point. As per my understanding on MibSPI configuration, I've prepared a PPT and a Doc. Can you please go through the same and let me know the way out? 

    P.S. : PPT and DOC would be much more helpful to understand the concept in systematic manner and hence asking you to suggest a response based on it.

    Regards,

    H C Trivedi

  • Hi Trivedi,

    I did not see the ppt and doc files. 

    This is the three-pin mode configuration:

    Did you miss the MISO signal on your diagram?

  • Apologies for the missing attachment Wang. Please find the same attached herewith. 

    MibSPI communication for TMS570.pptx

    MibSPI documentation.docx

    Did you miss the MISO signal on your diagram?

    No Wang. I did not miss the MISO pin. 

    Thanks and Regards,

    Trivedi 

  • Hi Trivedi,

    Your code looks fine. Since CS is not used, please select CS_None as mentioned in you message.

    Also, as highlighted in my screenshot, the Chip Select has been highlighted as CS_0, for three pin mode, shall it be CS_None ?

  • Thanks for the reply Wang. This thing worked and I was able to see the data on slave device. In continuation to your reply and my implementation, I'm still having following queries:

    1. The Master and The Slave program does not run autonomously. i.e. I have to enter the debug mode for master and slave both and then carry out step by step execution to see the results. If I press play button and see the execution of code, it stops in the middle somewhere. Also, the data received by slave is not correct in that case. 
    2. The code that worked had 16 bytes as TG0. If I configure TG0 to 128 bytes, then the slave device shows some random values. I need to scale this code for 256 bytes TG0.

    Please find the attached c files and erroneous data reception screenshot attached herewith.

    TI E2E forum didn't allow me to upload HALCoGen file. 

    /** @file HL_sys_main.c 
    *   @brief Application main file
    *   @date 11-Dec-2018
    *   @version 04.07.01
    *
    *   This file contains an empty main function,
    *   which can be used for the application.
    */
    
    /* 
    * Copyright (C) 2009-2018 Texas Instruments Incorporated - www.ti.com  
    * 
    * 
    *  Redistribution and use in source and binary forms, with or without 
    *  modification, are permitted provided that the following conditions 
    *  are met:
    *
    *    Redistributions of source code must retain the above copyright 
    *    notice, this list of conditions and the following disclaimer.
    *
    *    Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in the 
    *    documentation and/or other materials provided with the   
    *    distribution.
    *
    *    Neither the name of Texas Instruments Incorporated nor the names of
    *    its contributors may be used to endorse or promote products derived
    *    from this software without specific prior written permission.
    *
    *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    */
    
    
    /* USER CODE BEGIN (0) */
    /* USER CODE END */
    
    /* Include Files */
    
    #include "HL_sys_common.h"
    
    /* USER CODE BEGIN (1) */
    
    #include "HL_system.h"
    #include "HL_mibspi.h"
    #include "HL_sys_core.h"
    
    #define data_length 128
    
    uint16 rx_data[data_length] = {0};
    unsigned long counter1 = 0;
    
    /* USER CODE END */
    
    /** @fn void main(void)
    *   @brief Application main function
    *   @note This function is empty by default.
    *
    *   This function is called after startup.
    *   The user can use this function to implement the application.
    */
    
    /* USER CODE BEGIN (2) */
    /* USER CODE END */
    
    int main(void)
    {
    /* USER CODE BEGIN (3) */
    
        _enable_IRQ_interrupt_();
    
        mibspiInit();
    
        mibspiEnableGroupNotification(mibspiREG1, 0, 1);
    
        while(1)
        {
            mibspiTransfer(mibspiREG1, 0);
        }
    
    /* USER CODE END */
    
        return 0;
    }
    
    
    /* USER CODE BEGIN (4) */
    
    void mibspiGroupNotification(mibspiBASE_t *mibspi, uint32 group)
    {
        uint16 i=0;
        uint16 *data;
        if(mibspi==mibspiREG1)
        {
            data = &rx_data[0];
            mibspiGetData(mibspi, group, data);
        }
        else
        {
            printf("\n Incorrect MibSPI TG received!!");
            printf("\n");
        }
        printf(" received counter number is %d", rx_data[data_length-1]);
        printf("\n\n");
    }
    
    /* USER CODE END */
    

    /** @file HL_sys_main.c 
    *   @brief Application main file
    *   @date 11-Dec-2018
    *   @version 04.07.01
    *
    *   This file contains an empty main function,
    *   which can be used for the application.
    */
    
    /* 
    * Copyright (C) 2009-2018 Texas Instruments Incorporated - www.ti.com  
    * 
    * 
    *  Redistribution and use in source and binary forms, with or without 
    *  modification, are permitted provided that the following conditions 
    *  are met:
    *
    *    Redistributions of source code must retain the above copyright 
    *    notice, this list of conditions and the following disclaimer.
    *
    *    Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in the 
    *    documentation and/or other materials provided with the   
    *    distribution.
    *
    *    Neither the name of Texas Instruments Incorporated nor the names of
    *    its contributors may be used to endorse or promote products derived
    *    from this software without specific prior written permission.
    *
    *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    */
    
    
    /* USER CODE BEGIN (0) */
    /* USER CODE END */
    
    /* Include Files */
    
    #include "HL_sys_common.h"
    
    /* USER CODE BEGIN (1) */
    
    #include "HL_system.h"
    #include "HL_mibspi.h"
    #include "HL_sys_core.h"
    
    #define data_length 128
    
    uint16 rx_data[data_length] = {0};
    unsigned long counter1 = 0;
    
    /* USER CODE END */
    
    /** @fn void main(void)
    *   @brief Application main function
    *   @note This function is empty by default.
    *
    *   This function is called after startup.
    *   The user can use this function to implement the application.
    */
    
    /* USER CODE BEGIN (2) */
    /* USER CODE END */
    
    int main(void)
    {
    /* USER CODE BEGIN (3) */
    
        _enable_IRQ_interrupt_();
    
        mibspiInit();
    
        mibspiEnableGroupNotification(mibspiREG1, 0, 1);
    
        while(1)
        {
            mibspiTransfer(mibspiREG1, 0);
        }
    
    /* USER CODE END */
    
        return 0;
    }
    
    
    /* USER CODE BEGIN (4) */
    
    void mibspiGroupNotification(mibspiBASE_t *mibspi, uint32 group)
    {
        uint16 i=0;
        uint16 *data;
        if(mibspi==mibspiREG1)
        {
            data = &rx_data[0];
            mibspiGetData(mibspi, group, data);
        }
        else
        {
            printf("\n Incorrect MibSPI TG received!!");
            printf("\n");
        }
        printf(" received counter number is %d", rx_data[data_length-1]);
        printf("\n\n");
    }
    
    /* USER CODE END */
    

    BR,

    Trivedi

  • HI Trivedi,

    When TG0 has 128 buffers, the TX complete interrupt is not generated after the transfer is complete. Please refer to the device errata: MIBSP#136

  • Hello Wang,

    When TG0 has 128 buffers, the TX complete interrupt is not generated after the transfer is complete. Please refer to the device errata: MIBSP#136

    I tried to implement this, however, it is not showing me the intended results. Please see the screenshots below. LTGPEND register which had initial value of 0x7F ub LPEND field, is now updated to 0x80. For this, I've added following piece of code in HL_mibspi.c.

    After adding this line, I could see the value in LPEND field as 0x80. I hope this is what you asked me to implement to enable 128 byte TG0 MIBSPI transfer.

    However, still the data being received is incorrect. Please fin the same in the images below:

    Also attached is screen recording for your ready reference. 

    Part 1:

    Part 2:

    Also, if you see, for slave device, the value of register LTGPEND has been updated to 0x01008000. Earlier it was 0x00008000. Is this still correct?

    ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    Another thing, I've to use breapoints to get MibSPI work. Continuous transmission and reception is not working. Please find the videos attached below for your reference. 

    part1:

    Part 2:

    I hope I'm clear with both the queries. Please let me know if you want me to elaborate my queries further or require any further inputs from my side. 

    BR,

    Trivedi

  • Note: if videos do not play on browser, try playing them through VLC media player after downloading them.

  • Why is you SPI master configured for loopback? 

    For SPI slave, you don't write any data to SPI transfer group. 

     mibspiSetData(...)

  • Why is you SPI master configured for loopback? 

    Just for my reference/verification only. It doesn't have anything to do with my end application.

    For SPI slave, you don't write any data to SPI transfer group. 

     mibspiSetData(...)

    Is it mandatory? I just want to receive data on slave device. Will it not work?

  • One more thing:

    mibspiREG1->TGCTRL[1U] = (uint32)((uint32)1U << 30U)                          /* oneshot */
                                                   | (uint32)((uint32)0U << 29U)                          /* pcurrent reset */
                                                   | (uint32)((uint32)TRG_ALWAYS << 20U)      /* trigger event */
                                                   | (uint32)((uint32)TRG_DISABLED << 16U)   /* trigger source */
                                                   | (uint32)((uint32)128U << 8U);             /* start buffer */

  • Hello Wang,

    mibspiREG1->TGCTRL[1U] = (uint32)((uint32)1U << 30U)                          /* oneshot */
                                                   | (uint32)((uint32)0U << 29U)                          /* pcurrent reset */
                                                   | (uint32)((uint32)TRG_ALWAYS << 20U)      /* trigger event */
                                                   | (uint32)((uint32)TRG_DISABLED << 16U)   /* trigger source */
                                                   | (uint32)((uint32)128U << 8U);             /* start buffer */

    I could not understand what you were suggesting here. It is exactly like this in HL_mibspi.c file (please refer to the image attached). Still I'm facing issues in implementing 128 byte MibSPI transfer. 

    Can you please suggest the workaround? Please let me know if any input is required on this from my side. 

    BR,

    Trivedi

  • Hi Trivedi,

    I just run a test on LS12x launchpad: MibSPI1 is configured as master, and MibSPI3 is slave. TG0 is used, and its size is 128.

    TMS570LS1224_MibSPI1_MibSPI3_noDMA.zip

  • Hello Wang,

    Are you sure this does not use DMA for its implementation? Cause I could see a lot of DMA related statements ? I just scanned the code once, and while I was trying to understand it, I got this query.

    BR

    Trivedi

  • sys_main_no_DMA.c is used in this example. 

    sys_main_dma.c is excluded from the built.

  • Hello Wang,

    As discussed, please find my points below:

    1. include some delay after every transfer:
      1. I did introduce some delay and found that it isn't the delay that was causing the problem. I tried adding Tx (setdata) and Rx (getdata) commands to both, Master and Slave and it started working.=> successfully completed this query.
    2. I'm still struggling with 128 bytes or more length of data transfer. Whatever I specified in point 1 is valid for length up to 127 bytes only. Can you please help me here. For your reference, attached are my HALCoGen files (over email) and sys_main.c files for master and slave both.
    3. I tried implementing ENA based code as we had discussed. Still not able to make it work. Can you please check?

    Attachments:

    Slave code:

    /** @file HL_sys_main.c 
    *   @brief Application main file
    *   @date 11-Dec-2018
    *   @version 04.07.01
    *
    *   This file contains an empty main function,
    *   which can be used for the application.
    */
    
    /* 
    * Copyright (C) 2009-2018 Texas Instruments Incorporated - www.ti.com  
    * 
    * 
    *  Redistribution and use in source and binary forms, with or without 
    *  modification, are permitted provided that the following conditions 
    *  are met:
    *
    *    Redistributions of source code must retain the above copyright 
    *    notice, this list of conditions and the following disclaimer.
    *
    *    Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in the 
    *    documentation and/or other materials provided with the   
    *    distribution.
    *
    *    Neither the name of Texas Instruments Incorporated nor the names of
    *    its contributors may be used to endorse or promote products derived
    *    from this software without specific prior written permission.
    *
    *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    */
    
    
    /* USER CODE BEGIN (0) */
    /* USER CODE END */
    
    /* Include Files */
    
    #include "HL_sys_common.h"
    
    /* USER CODE BEGIN (1) */
    #include "HL_mibspi.h"
    #define data_length 127
    unsigned long counter1 = 0;
    bool transmit_flag = 0;
    
    //uint16 tx_data[data_length] = {50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65};
    
    uint16 tx_data[data_length] = {0};
    uint16 rx_data[data_length] = {0};
    
    void load_data_function()
    {
        unsigned int l = 0;
        for(l=0; l<=data_length; l++)
        {
            tx_data[l] = l+50;
        }
    }
    
    /* USER CODE END */
    
    /** @fn void main(void)
    *   @brief Application main function
    *   @note This function is empty by default.
    *
    *   This function is called after startup.
    *   The user can use this function to implement the application.
    */
    
    /* USER CODE BEGIN (2) */
    /* USER CODE END */
    
    int main(void)
    {
    /* USER CODE BEGIN (3) */
    
        _enable_IRQ_interrupt_();
    
        mibspiInit();
    
        mibspiEnableGroupNotification(mibspiREG1, 0, 1);
    
        load_data_function();
    
        // mibspiEnableLoopback(mibspiREG1, Analog_Lbk);
    
        while(1)
        {
            unsigned int counter3 = 0, counter2 = 0;
            if(transmit_flag == 0)
            {
                tx_data[data_length-1] = counter1+20;
                for(counter2 = 0; counter2<=10000; counter2++)
                {
                    ;
                }
                mibspiSetData(mibspiREG1, 0, tx_data);
                mibspiTransfer(mibspiREG1, 0);
                transmit_flag=1;
            }
        }
    /*
        mibspiSetData(mibspiREG1, 0, tx_data);
        mibspiTransfer(mibspiREG1, 0);
        transmit_flag=1;*/
    
        while(1);
        /* USER CODE END */
    
        return 0;
    }
    
    
    /* USER CODE BEGIN (4) */
    void mibspiGroupNotification(mibspiBASE_t *mibspi, uint32 group)
    {
        printf("\n Transmitted data is :: %d !!", tx_data[data_length-1]);
        printf("\n");
        counter1++;
        transmit_flag = 0;
        mibspiGetData(mibspi, group, &rx_data);
        printf("\n =============================>>> Received Data is :: %d", rx_data[data_length-1]);
        printf("\n");
    }
    /* USER CODE END */
    

    Master code:

    /** @file HL_sys_main.c 
    *   @brief Application main file
    *   @date 11-Dec-2018
    *   @version 04.07.01
    *
    *   This file contains an empty main function,
    *   which can be used for the application.
    */
    
    /* 
    * Copyright (C) 2009-2018 Texas Instruments Incorporated - www.ti.com  
    * 
    * 
    *  Redistribution and use in source and binary forms, with or without 
    *  modification, are permitted provided that the following conditions 
    *  are met:
    *
    *    Redistributions of source code must retain the above copyright 
    *    notice, this list of conditions and the following disclaimer.
    *
    *    Redistributions in binary form must reproduce the above copyright
    *    notice, this list of conditions and the following disclaimer in the 
    *    documentation and/or other materials provided with the   
    *    distribution.
    *
    *    Neither the name of Texas Instruments Incorporated nor the names of
    *    its contributors may be used to endorse or promote products derived
    *    from this software without specific prior written permission.
    *
    *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
    *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
    *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
    *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
    *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
    *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
    *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
    *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    */
    
    
    /* USER CODE BEGIN (0) */
    /* USER CODE END */
    
    /* Include Files */
    
    #include "HL_sys_common.h"
    
    /* USER CODE BEGIN (1) */
    #include "HL_mibspi.h"
    #define data_length 127
    unsigned long counter1 = 0;
    bool transmit_flag = 0;
    
    uint16 tx_data[data_length] = {0};
    
    uint16 rx_data[data_length] = {0};
    
    void load_data_function()
    {
        unsigned int l = 0;
        for(l=0; l<=data_length; l++)
        {
            tx_data[l] = l+20;
        }
    }
    /* USER CODE END */
    
    /** @fn void main(void)
    *   @brief Application main function
    *   @note This function is empty by default.
    *
    *   This function is called after startup.
    *   The user can use this function to implement the application.
    */
    
    /* USER CODE BEGIN (2) */
    /* USER CODE END */
    
    int main(void)
    {
    /* USER CODE BEGIN (3) */
    
        _enable_IRQ_interrupt_();
    
        mibspiInit();
    
        mibspiEnableGroupNotification(mibspiREG1, 0, 1);
    
        // mibspiEnableLoopback(mibspiREG1, Analog_Lbk);
    
        load_data_function();
    
        while(1)
        {
            unsigned int counter3 = 0, counter2 = 0;
            if(transmit_flag == 0)
            {
                tx_data[data_length-1] = counter1+10;
                for(counter2 = 0; counter2<=20000; counter2++)
                {
                    ;
                }
                mibspiSetData(mibspiREG1, 0, tx_data);
                mibspiTransfer(mibspiREG1, 0);
                transmit_flag=1;
            }
        }
    /*
        mibspiSetData(mibspiREG1, 0, tx_data);
        mibspiTransfer(mibspiREG1, 0);
        transmit_flag=1;*/
    
        while(1);
        /* USER CODE END */
    
        return 0;
    }
    
    
    /* USER CODE BEGIN (4) */
    void mibspiGroupNotification(mibspiBASE_t *mibspi, uint32 group)
    {
        // printf("\nTransfer %d completed!!", counter1);
        printf("\n =============================>>> Transmitted data is :: %d !!", tx_data[data_length-1]);
        printf("\n");
        counter1++;
        transmit_flag = 0;
        mibspiGetData(mibspi, group, &rx_data);
        printf("\n Received Data is :: %d", rx_data[data_length-1]);
        printf("\n");
    }
    /* USER CODE END */
    

    BR,

    Trivedi

  • Hello Wang,

    Did you get a chance to look into this?

  • Have you found the solution for master-slave SPI communication? I didn't have two LC43x boards to do the test.

  • No Wang. After the meeting, I tried everything that we discussed and also posted the updates here. I'm still facing the issue.

    BR,

    H C Trivedi

  • Hi Trivedi,

    I noticed one bug in the "mibspiGetData" function in my testings. I mean below highlighted line is required before reading each element from mibSPI buffer

    while(ram->rx[start].flags & (1 << 15));

    What i noticed if this line is not present is, some times no data elements are reading into the destination buffer and i can see the data elements only one doing line by line debug. And sometimes i could see only partial data.

    If above highlighted line is not present then we are just moving entire Mib SPI Rx buffer data to the destination buffer without even verifying whether the new data received or not, because of this sometimes some bytes are moving as zeros to the destination buffer.

    If we add this line then we can make sure that new data received before moving into the destination buffer.

    Add this line into both master and slave side in "mibspiGetData" function like as shown above, and see the result.

    --

    Thanks & regards,
    Jagadish.