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: MibSPI Communication - Msater and Slave Configuration

Part Number: TMS570LC4357
Other Parts Discussed in Thread: HALCOGEN

TI Team,

I'm facing some issue in getting my MibSPI work. I want to use 4 pin MibSPI 1 for communication i.e. MOSI, MISO, CLK, ENA. Following is the configuration:

  1. Master Device:
    1. Master Mode: Enabled
    2. Internal Clock: Enabled
    3. Wait for Enable: Enabled
    4. Transfer Group 0: CS_NONE, Length 16
    5. SOMI[1]: GPIO : Output
    6. SOMI[0]: SPI : Input
    7. SIMO[1]: GPIO : Output
    8. SIMO[0]: SPI : Output
    9. CLK : SPI : Output
    10. ENA : SPI : Input
  2. Slave Device:
    1. Master Mode: Disabled
    2. Internal Clock: Disabled
    3. Wait for Enable: Enabled
    4. Transfer Group 0: CS_NONE, Length 16
    5. SOMI[1]: GPIO : Output
    6. SOMI[0]: SPI : Output
    7. SIMO[1]: GPIO : Output
    8. SIMO[0]: SPI : Input
    9. CLK : SPI : Input
    10. ENA : SPI : Output

/* 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 */

Issue: Not able to receive data on slave device

Query: I think there is some problem with ENA pin enabling for data transmission. How shall I incorporate ENA related program to my code? 

Regards,

Sameer

  • Hi Sameer,

    We started working on your issue and will provide an update soon.

    --

    Thanks & regards,
    Jagadish.

  • Okay. I'll wait for your response. 

    Thanks,

    Sameer

  • Hello Jagadish,

    did you get a chance to look into this?

  • Hi Sameer,

    I am trying to create one example with ENA, i want to test it and update you.

    --

    Thanks & regards,
    Jagadish.

  • HI Sameer,

    As i told you, i created one example project with ENA.

    Can you please test it and update me. I don't have setup with me right now to test it.

    MibSPI_Master_with_ENA_TEST_LC4357.zip

    MibSPI_Slave_with_ENA_TEST_LC4357.zip

    --

    Thanks & regards,
    Jagadish.

  • Thanks for sharing the files Jagadish. I'll check and get back to you.

    Regards,

    Sameer

  • Hello Jagadish,

    I had gone through your example. It apparently did not work for me. Upon analysing, I found few queries: 

    • TG length for master and slave is not same. for master it is 128 bytes, whereas for slave it is 8 bytes. In the code, Tx and Rx array created is of 10 bytes.
    • for Master, Wait for Enable has been checked whereas for slave, it is unchecked. 

    Can any of this be one of the reason for the example to not work at my end?

    I again studied TRM and created project with 4 pin MibSPI of my own. It is sill not working. Can you please check it? The attachment includes sys_main.c for master and slave and HCG file for master and slave.

    Please let me know if any other details is required on this from my end. 

    ENA pin .zip

    Thanks,

    Sameer.

  • Hi Sameer,

    I will verify and update you.

    --

    Thanks & regards,
    Jagadish.

  • Thanks for the acknowledgement Jagadish. By mistake I hit the "This resolved my issue" button. Can you please undo it?

    Also, shall I expect any update by tomorrow?

    Regards,

    Sameer

  • By mistake I hit the "This resolved my issue" button. Can you please undo it?

    No problem.

    Also, shall I expect any update by tomorrow?

    Sure, i will try to provide an update by tomorrow.

  • Hi Sameer,

    Here are the working projects.

    8446.MibSPI_Master_with_ENA_TEST_LC4357.zip

    6064.MibSPI_Slave_with_ENA_TEST_LC4357.zip

    Basically, i found two issues for not working of my previous projects.

    1. If you are using TMS570LC4357 HDK board then you should be make sure the DIP_SWITCH_4's 1 and 4 buttons are in OFF

    This is important because the SPI ENA pin is connected to the one De-Mux and it has a multiple functions, so to connect this ENA pin to the J9 connector we should OFF the 1 and 4 buttons.

       

    2. Some times i found only some part of the data is moving into the end buffer "rx_data1" even though Mib SPI Rx buffer receiving all the data.

    And after debugging i found it is due to the missing of RXEMPTY flag verification in the "mibspiGetData" function.

    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.

    After making sure of above two things i was successfully received the data between MibSPI master and Slave.

    --

    Thanks & regards,
    Jagadish.

  • Thanks for sharing the projects Jagadish. I'll check and get back to you. 

    Since I'm using LaunchXL2, 1st point is not applicable to my development. 

    Point 2 I checked in my code and the line was not there. Is it required to be added manually? 

    Regards,

    Sameer

  • Hi Sameer,

    Point 2 I checked in my code and the line was not there. Is it required to be added manually? 

    Yes, it is required to add manually.

    --

    Thanks & regards,
    Jagadish.

  • One more query Jagadish. Your implementation does not use MIBSPI interrupts. Whereas the one that I shared was involving interrupts (through ENABLE Group Notification) So, if I want to use interrupts for my implementation, then also I need to add this line to the code?

    Thanks & Regards,

    Sameer

  • Hi Sameer,

    One more query Jagadish. Your implementation does not use MIBSPI interrupts. Whereas the one that I shared was involving interrupts (through ENABLE Group Notification) So, if I want to use interrupts for my implementation, then also I need to add this line to the code?

    It would be better to use it for interrupt code,

    The condition i added will just check whether the new data is available or not in the corresponding TG buffer before reading that data. So, it would be better to add it.

    --

    Thanks & regards,
    Jagadish.

  • Hello Jagadish,

    I think the project that you shared worked at my end as well. I'd still like to carry out following modifications in it and give you final confirmation:

    • Implement the same for interrupt based configuration
    • implement the same for 256 bytes transfer
    • Implementation at a higher baud rate.

    For the current implementation, I have a query associated though. While we've kept everything same, why there is difference in the transfer rate from master device to the slave device and vice versa? Please refer to the screenshots below. As it can be seen, maser is leading the slave by 3-4 loops of 50 transfers. 

      

    Thanks and Regards,

    Sameer

  • Hello Jagadish,

    In continuation to my previous query, if I pause execution of Slave device, the master device should no transmit, is it correct (as it will not be receiving enable signal)? However, in my case, even though the slave execution was paused (in the debug perspective), the master kept on transmitting.

    On the contrary, when I pause the execution of Master device, the slave pauses automatically.

    Is it because we have enabled "Wait for ENA" in HALCoGen for Master and not for Slave?

    Another point as I debugged this further:

    While I removed ENA cable running from my master board to slave board, the code continued running. Both the devices continued sending and receiving the data. So I think there is some issue.

    Thanks and Regards,

    Sameer

  • Hi Sameer,

    As it can be seen, maser is leading the slave by 3-4 loops of 50 transfers. 

    I have to do analysis for this, is it possible for you to share your complete project?

    if I pause execution of Slave device, the master device should no transmit, is it correct (as it will not be receiving enable signal)?

    Yes, it should, but make sure the default state of the ENA pin you configured.

    On Master side, make sure to enable Pull-up.

    On slave side, make sure to keep DOUT=1 and pull-up enabled.

    After doing above modifications now test it, if still issue exists then i will do testing at my end and provide you an update.

    --

    Thanks & regards,
    Jagadish.

  • Hello Jagadish,

    Apologies for the delay in response from my side. 

    Please find the projects attached herewith:

    MibSPI1_Master_Jagadish.zip

    MibSPI1_Slave_Jagadish.zip

    Yes, it should, but make sure the default state of the ENA pin you configured.

    On Master side, make sure to enable Pull-up.

    On slave side, make sure to keep DOUT=1 and pull-up enabled.

    After doing above modifications now test it, if still issue exists then i will do testing at my end and provide you an update.

    I tried this thing today. However, there is an issue associated. While the pin for ENA is in pulled-down mode, Master-Slave communication occurs as I had acknowledged in my previous reply. But when I changed it to pull-up as suggested, the transfer does not start at all. The code waits at while statement in the execution. Can you please check this on your end?

    Thanks and Regards,

    Sameer

  • hello Jagadish,

    Could you look into this?

    Regards,

    Sameer

  • Hi Sameer,

    Working on your issue and will provide an update by the end of the day.

    --
    Thanks & regards,
    Jagadish.

  • Hi Sameer,

    if I pause execution of Slave device, the master device should no transmit, is it correct (as it will not be receiving enable signal)?

    My apologies for previous answer,

    actually, pausing debug won't bring the ENA pin value to the logic High.

    Actually SPIENA will work as below

    It will go to the active low after we are writing data into the SPIDAT0 register and once the data shifted it will come back to the high again. This is the behavior for SPI but for MibSPI again it is different

    For MibSPI it is going into Active low after calling the function "mibspiTransfer"

    Because this will enable the data transfer right.

    But what i am observing is after transferring all the data the ENA pin is not coming back to the logic high.

    It is coming back only after we are calling the function "mibspiReset".

    --

    Thanks & regards,
    Jagadish.

  • Thanks for the clarity Jagadish. 

    So, for my implementation, how do I make it work? That is, once the Master received ENA signal from slave, then only it transmits otherwise it waits for the signal from slave?

    Also, could you analyse the project that I shared? Putting the pin to PULLUP (on master side) it does not transmit the data at all!

    Thanks and Regards,

    Sameer.

  • Hi Sameer,

    Also, could you analyse the project that I shared? Putting the pin to PULLUP (on master side) it does not transmit the data at all!

    Here are the working master and slave codes at my end.

    Compare them with your project once:

    0841.MibSPI_Master_with_ENA_TEST_LC4357.zip

    5810.MibSPI_Slave_with_ENA_TEST_LC4357.zip

    In this project i enabled pullup on master side.

    If still issue exists then i will again try to debug your project at my side once.

    --
    Thanks & regards,
    Jagadish.

  • Hi Sameer,

    So, for my implementation, how do I make it work? That is, once the Master received ENA signal from slave, then only it transmits otherwise it waits for the signal from slave?

    If slave calls the function "mibspiTransfer" means then slave ready for communication with master. So call this function in slave side after slave ready, once slave calls this function then master will send the clock and its data and in parallel with that slave will also sends its data to the master. In this way both can exchange the data.

    --

    Thanks & regards,
    Jagadish.

  • Hello Jagadish,

    Thanks for sharing the project files. I also evaluated the codes at my end and found the following:

    1. If ENA is set to pullup on master side, then data transfer between master and slave does not get start at all. While I changed it to Pull-down state in HALCoGen, then the same code works. 
      1. is there anything I'm missing during the execution? Please find the steps below for my execution process:
        1. Master and Slave both: change project properties: set debugger to XDS110 and compiler version to TI V20.2.5.LTS.
        2. Master and Slave both: change flash settings to Necessary Sectors only. 
        3. Master only: run the project in debug mode.
        4. Slave only: run the project in debug mode. 
      2. I've also tried swapping the execution sequence i.e. D first and C later. However, it made no difference. 
    2. if we are resetting the slave device then why do we need to clear the Rx buffer separately?
    3. Please find my projects attached below:
      1. in my project also, the communication works till ENA for master is pulled down. The moment I pull it up, the communication stops. Video is attached for your reference (showing communication during pull-down state). And when ENA is pulled down, it has no impact on 4-pin MibSPI. i.e. if I remove ENA connection, the data transfer continues. 
      2. another strange thing which I specified previously is, when I start master first, the communication runs smoothly. If I start slave device first, then master frequency is halved. i.e. for every single transmit by master, slave transmits two times. 

    MibSPI_Master_with_ENA_H1.zip

    MibSPI_Slave_with_ENA_H1.zip

    Please let me know if you need anything on this from my side to help me fix this issue.

    Best Regards,

    Sameer.

  • Hi Sameer,

    If ENA is set to pullup on master side, then data transfer between master and slave does not get start at all. While I changed it to Pull-down state in HALCoGen, then the same code works. 

    If it is working only after changing to pulldown means, then this ENA line actually not driven by slave. I mean your communication will work even though you completely removed the ENA line between Master and Slave(You can see the same behavior without ENA line too).

    The same code working on my side so there might not be any code issues, can you please check hardware connectivity properly?

    If still issue not rectified then we will plan one live debugging session, if possible, on your side. I will be available between 10AM to 7PM on IST, just create on meeting and share the details.

    --

    Thanks & regards,
    Jagadish.

  • Hello Jagadish,

    Many thanks for the help. I think my issue got resolved upto a great extent. I think HALCoGen was the issue. I reinstalled it and the code started working.

    Catch: It is working partially only. Following is the concerns:

    • Master is able to transmit. 
    • Slave is receiving whatever the master is transmitting. 
    • Slave is able to transmit.
    • Master is not able to receive whatever the salve is transmitting. 
    • I checked this for 4-5 times. Out of which only once it ran properly. Apart from that, it never ran. 
    • I'm posting my HL_sys_main.c files, HALCoGen files for master and slave. Can you please check? Also attached is the video for your reference. I think, since everything is kept same for your project as well as mine, just replacing the main.c file would make it quick for you to check. 

    Please let me know if anything is required on this from my side. 

    P.S.: under mibspiGetData() function, I've added the line that you recommended. 

    Master:

    /** @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 8
    
    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);
    
        counter1++;
    
        transmit_flag = 0;
    
        mibspiGetData(mibspi, group, &rx_data);
    
        // if(counter1 % 100 == 0)
    
        {
    
            printf("\n =============================>>> Transmitted data is :: %d !!", tx_data[data_length-1]);
    
            printf("\n");
    
            printf("\n Received Data is :: %d", rx_data[data_length-1]);
    
            printf("\n");
    
        }
    
    }
    
    /* USER CODE END */

    Slave:

    /** @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 8
    
    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+5;
    
        }
    
    }
    
    /* 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+5;
    
                /*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)
    
    {
    
        counter1++;
    
        transmit_flag = 0;
    
        mibspiGetData(mibspi, group, &rx_data);
    
        // if(counter1 % 100 == 0)
    
        {
    
            printf("\n =============================>>> Transmitted data is :: %d !!", tx_data[data_length-1]);
    
            printf("\n");
    
            printf("\n Received Data is :: %d", rx_data[data_length-1]);
    
            printf("\n");
    
            // mibspiReset(mibspiREG1);
    
        }
    
    }
    
    /* USER CODE END */

    Video of MibSPI transfer between master and slave (use VLC media player to play):

    4pin_mibspi.zip

    Many Thanks and Regards,

    Sameer

  • Hello Jagadish,

    Could you look into this?

    Thanks,

    Sameer.

  • Hi Sameer,

    Let's plan one live debugging session, just share your screen and show the issue in the call.

    Just let me know your free time tomorrow.

    I will be available from 10AM to 6PM in Indian Standard Time(IST).

    --

    Thanks & regards,
    Jagadish.

  • Hello Jagadish,

    I've internet connectivity issues with my CCS system and hence it is not possible to share my screen. Is it okay if I capture the videos and share it over here? If yes, what all you'd want me to capture?

    Is there any other way possible for you to help me resolve this issue?

    Thanks & Regards,

    Sameer

  • Hi Sameer,

    Videos wouldn't help much.

    It would be easy to discuss over the call by doing screenshare. In our organization we are using webex for meetings, if you are using same in your organization too we can make a call and discuss the issue, even though you are using any other meeting app that would be fine for me i can download and do the call.

    --
    Thanks & regards,
    Jagadish.

  • Hello Jagadish,

    I think the last answer is for some other post?

    Regards,

    Sameer

  • I think the last answer is for some other post?

    You are right.

  • Hello Jagadish,

    As discussed over call, I tried implementing your suggestions. please find the response as follows:

    1. Try running the code from a single computer.
      1. Whether it is same computer or different, it doesn't matter. I tried running the debug session from a single computer as you suggested. However, the result remain the same. 
      2. The thing that I observed is slave device is not getting sufficient time to come back from its ISR and hence counter value for Slave transmit does not increase. 
    2. Important Observation:
      1. Observation 1: whether it's a single computer or two different computers, if the Slave device gets sufficient time between two transmissions, then the entire thing works as desired. I achieved this by introducing one printf line in master ISR call. Hence, by the time master prints a new line, slave completes its ISR and increments its counter and then sends it. 
      2. Observation 2: if we add an additional line in slave ISR, then master will keep on sending the data without slave ready signal and hence slave will never come out of ISR execution resulting into sending same value again and again. 
      3. Observation 3: If we run the master code first and then slave, then issue remains as usual because master is not allowing slave to get out of ISR. however, if slave is ran first and then master then the execution runs properly. 

    Please suggest further action.

    Regards,

    Sameer 

  • Hi Sameer,

    Thanks for the details,

    I will again test and will provide an update by tomorrow.

    --

    Thanks & regards,
    Jagadish.

  • Hello Jagadish, 

    Along with the previous queries, can you please also suggest modifications required to implement the same for 256  bytes transfer through MibSPI? I think I'm able to communicate using 4-pin MibSPI. I'd still provide you with final confirmation on it after running some more tests. 

    Please note that for MIBSPI loopback implementation, I've already implemented 256 bytes transfer (referance post: https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1206854/faq-tms570lc4357-how-to-enable-256-buffers-extended_buf_ena-feature-of-mibspi/4553473#4553473).

    While implementing 3-pin MibSPI, I could not transfer more than 128 bytes at once despite following steps provided in above-mentioned post (https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1213532/tms570lc4357-tms570lc4357-mibspi-master-and-slave-communication/4709365#4709365).

    Thanks and Regards,

    Sameer.

  • Hi Sameer,

    My first doubt is that, please confirm you are using MibSPI1 for both Master and slave in TMS570LC4357 controllers.

    Except MibSPI1, no other MibSPI will support for 256 buffers. So we should use only MibSPI1 on both master and slave sides.

    If you are doing above thing correctly then please use below Master and slave projects as reference:

    4666.MIBSPI1.zip

    MibSPI1_Extended_buffer_testing_slave_LC4357.zip

    The only difference from your projects should be CS0 and ENA. In above projects i used CS0 and i didn't configure ENA but remaining everything is same and this is working. So please take above projects as reference and do the necessary modifications.

    And also please make sure to configure all the settings i mentioned in below FAQ because these settings are mandatory for extended buffer mode.

    (14) [FAQ] TMS570LC4357: How to enable 256 BUFFERS/EXTENDED_BUF_ENA Feature OF MibSPI? - Arm-based microcontrollers forum - Arm-based microcontrollers - TI E2E support forums

    --

    Thanks & regards,
    Jagadish.

  • Hello Jagadish,

    Thanks for the prompt response. I understand that only MibSPI 1 can support extended buffers and hence using MibSPI 1 only

    I'll try to evaluate the projects provided by you and get back to you at the earliest. 

    The only difference from your projects should be CS0 and ENA. In above projects i used CS0 and i didn't configure ENA but remaining everything is same and this is working. So please take above projects as reference and do the necessary modifications.

    Is there any reason why I cannot use MibSPI in 4 pin mode with ENA and without CS0? Because this is how I implemented previous project and considering actual development in mind, ENA will be requierd for my end application.

    And also please make sure to configure all the settings i mentioned in below FAQ because these settings are mandatory for extended buffer mode.

    (14) [FAQ] TMS570LC4357: How to enable 256 BUFFERS/EXTENDED_BUF_ENA Feature OF MibSPI? - Arm-based microcontrollers forum - Arm-based microcontrollers - TI E2E support forums

    Yes, I did follow all these things. 

    Thanks and Regards,

    Sameer.

  • Hi Sameer,

    Is there any reason why I cannot use MibSPI in 4 pin mode with ENA and without CS0? Because this is how I implemented previous project and considering actual development in mind, ENA will be requierd for my end application.

    There is no reason, you can use ENA. As i have a project with CS0, so i did modifications in my existing projects. But you can use ENA instead of CS0.

    --

    Thanks & regards,
    Jagadish.

  • Hello Jagadish,

    Many thanks for the help. I am now able to use it for 256 size buffers. I did not use CS0 though. I continued with 4 pin MibSPI (MOSI, MISO, CLK and ENA). The code seems to be working just fine. 

    I still have one query though. Is it anyhow possible to customise this code for using Dynamic Memory Allocation? 

    1. In the first version of code, I'm declaring tx_data[256] and rx_data[256] . The end - to - end MibSPI communication works fine at 10000 kHz baudrate.
    2. In the second version of code, I'm declaring the tx_data as char* and allocating its memory dynamically while keeping the rest of the things same. In this case, there is some random data transfer taking place. Attached is the code for your ready reference. 

    /* 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 256
    unsigned long counter1 = 0;
    bool transmit_flag = 0;
    
    // uint16 tx_data[data_length] = {0};
    char *tx_data;
    
    uint16 rx_data[data_length] = {0};
    
    void load_data_function()
    {
        tx_data = (char*)malloc(data_length*sizeof(char));
        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)
        {
            if(transmit_flag == 0)
            {
                tx_data[data_length-1] = counter1+10;
                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)
    {
        counter1++;
        transmit_flag = 0;
        mibspiGetData(mibspi, group, &rx_data);
        if(counter1 % 100 == 0)
        {
            printf("\n Transmitted data is :: %d !!", tx_data[data_length-1]);
            printf("\n Received Data is :: %d", rx_data[data_length-1]);
        }
    }
    /* USER CODE END */
    

    Can you please guide?

    Thanks and Regards,

    Sameer.

  • Hi Sameer,

    Apologies for the late reply.

    I guess previously you send and receive data with 16bit frames, but now why you are declaring tx_data pointer with 8 bit size?

    And what is the format you selected 8bit or 16bit?

    --

    Thanks & Regards,
    Jagadish.

  • Hello Jagadish,

    Apologies for mistake in specifying the datatype. It's 16 bit only. So there is no change in it with reference to my previous implementation.

    The thing that I'm trying to implement here is dynamic memory allocation for the data to be transmitted. For the current implementation, I used to declare tx_data as a static array of 256 bytes. However, I want it do be dynamic. Now, declaring a variable as a dynamic variable, allocating required memory for it is what I've already implemented. The only problem is how to send it through mibspiSetData and mibspiTransfer functions. That's where I need your help.

    Please let me know if any other input on this is required from my side.

    Regards,

    Sameer

  • Hi Sameer,

    For tracking purpose, i am adding our mail conversation here.

    RE EXTERNAL TI E2E reply.zip

    Good to hear that your issue resolved.

    --

    Thanks & regards,
    Jagadish.