TMS320C6748: SPI communication with ADS1298

Part Number: TMS320C6748

Tool/software:

Hi Experts,

Good day! 

I am using this code for SPI communication between my microcontroller(TMS320C6748 as master) and Arduino mega 2560(as slave). Where my master is sending some data which is char(a) here to the slave.
My code is running in the CCS but nothing is getting transmitted to the arduino. It is printing some garbage value.
My code is unable to select the slave using chip select because when I, ground the CS line of arduino it start receiving garbage value.

I am using SPI0 and CS line as 4.

#include <stdint.h>
#include <string.h>
#include <\ti\pdk_C6748_2_0_0_0\C6748_StarterWare_1_20_03_03\include\hw\soc_C6748.h>
#include <\ti\pdk_C6748_2_0_0_0\C6748_StarterWare_1_20_03_03\include\hw\hw_psc_C6748.h>
#include <\ti\pdk_C6748_2_0_0_0\C6748_StarterWare_1_20_03_03\include\c674x\c6748\lcdkC6748.h>
#include <\ti\pdk_C6748_2_0_0_0\C6748_StarterWare_1_20_03_03\include\spi.h>
#include <\ti\pdk_C6748_2_0_0_0\C6748_StarterWare_1_20_03_03\include\psc.h>
#include <\ti\pdk_C6748_2_0_0_0\C6748_StarterWare_1_20_03_03\include\c674x\c6748\interrupt.h>
#include <\ti\pdk_C6748_2_0_0_0\C6748_StarterWare_1_20_03_03\drivers\spi.c>
#include <\ti\pdk_C6748_2_0_0_0\C6748_StarterWare_1_20_03_03\drivers\psc.c>
#include <\ti\pdk_C6748_2_0_0_0\C6748_StarterWare_1_20_03_03\system_config\c674x\interrupt.c>
#include <\Users\lakshay data\AppData\Local\Microsoft\Windows\INetCache\IE\Z7RWMKAE\spi[1].c>
#define SIMO_SOMI_CLK_CS        0x00000E10
#define CHAR_LENGTH             0x8
static void SPIConfigDataFmtReg(unsigned int dataFormat);
static void SpiTransfer(void);
static void SetUpInt(void);
static void SetUpSPI(void);
void SPIIsr(void);
volatile unsigned int flag = 1;
unsigned int tx_len;
unsigned int rx_len;
unsigned char tx_data[0];
unsigned char *p_tx;
volatile unsigned char *p_rx;
int main(void)
{
    /* Waking up the SPI1 instance. */
    PSCModuleControl(SOC_PSC_0_REGS, HW_PSC_SPI0, PSC_POWERDOMAIN_ALWAYS_ON,
                     PSC_MDCTL_NEXT_ENABLE);
    /* Performing the Pin Multiplexing for SPI1. */
    SPIPinMuxSetup(0);
    /*
    ** Using the Chip Select(CS) 0 pin of SPI1 to communicate with the Fingerprint Sensor.
    */
    SPI1CSPinMuxSetup(4);
    /* Enable use of SPI1 interrupts. */
    SetUpInt();
    /* Configuring and enabling the SPI1 instance. */
    SetUpSPI();
    while(1){
        tx_len = 1;
        rx_len = 1;
        tx_data[0]='a';
        SpiTransfer();
    }
}
static void SetUpInt(void)
{
    // Setup the ARM or DSP interrupt controller
#ifdef _TMS320C6X
    // Initialize the DSP interrupt controller
    IntDSPINTCInit();
    // Register the ISR in the vector table
    IntRegister(C674X_MASK_INT4, SPIIsr);
    // Map system interrupt to the DSP maskable interrupt
    IntEventMap(C674X_MASK_INT4, SYS_INT_SPI0_INT);
    // Enable the DSP maskable interrupt
    IntEnable(C674X_MASK_INT4);
    // Enable DSP interrupts globally
    IntGlobalEnable();
#endif
}
    static void SetUpSPI(void)
    {
        unsigned char cs  = 0x10;
        unsigned char dcs = 0x10;
        unsigned int  val = SIMO_SOMI_CLK_CS;
        SPIReset(SOC_SPI_0_REGS);
        SPIOutOfReset(SOC_SPI_0_REGS);
        SPIModeConfigure(SOC_SPI_0_REGS, SPI_MASTER_MODE);
        //SPIClkConfigure(SOC_SPI_1_REGS, 150000000, 20000000, SPI_DATA_FORMAT0);
        SPIClkConfigure(SOC_SPI_0_REGS, 150000000, 1000000, SPI_DATA_FORMAT0);
        SPIPinControl(SOC_SPI_0_REGS, 0, 0, &val);
        SPIDefaultCSSet(SOC_SPI_0_REGS, dcs);
        /* Configures SPI Data Format Register */
        SPIConfigDataFmtReg(SPI_DATA_FORMAT0);
         /* Selects the SPI Data format register to used and Sets CSHOLD
          * to assert CS pin(line)
          */
        SPIDat1Config(SOC_SPI_0_REGS, (SPI_CSHOLD | SPI_DATA_FORMAT0), cs);
         /* map interrupts to interrupt line INT1 */
        SPIIntLevelSet(SOC_SPI_0_REGS, SPI_RECV_INTLVL | SPI_TRANSMIT_INTLVL);
        /* Enable SPI communication */
        SPIEnable(SOC_SPI_0_REGS);
    }
    static void SPIConfigDataFmtReg(unsigned int dataFormat)
    {
        /* Configures the polarity and phase of SPI clock */
        /*
        SPIConfigClkFormat(SOC_SPI_1_REGS,
                           (SPI_CLK_POL_HIGH | SPI_CLK_INPHASE),
                           dataFormat);
        */
        SPIConfigClkFormat(SOC_SPI_0_REGS,
                           (SPI_CLK_POL_LOW | SPI_CLK_INPHASE),
                           dataFormat);
        /* Configures SPI to transmit MSB bit First during data transfer */
        SPIShiftMsbFirst(SOC_SPI_0_REGS, dataFormat);
        /* Sets the Charcter length */
        SPICharLengthSet(SOC_SPI_0_REGS, CHAR_LENGTH, dataFormat);
    }
    static void  SpiTransfer(void)
    {
        p_tx = &tx_data[0];
       // p_rx = &rx_data[0];
        SPIIntEnable(SOC_SPI_0_REGS, (SPI_RECV_INT | SPI_TRANSMIT_INT));
        while(flag);
        flag = 1;
        /* Deasserts the CS pin(line) */
        SPIDat1Config(SOC_SPI_0_REGS, SPI_DATA_FORMAT0, 0x10);
    }
    void SPIIsr(void)
    {
        unsigned int intCode = 0;
    #ifdef _TMS320C6X
        IntEventClear(SYS_INT_SPI0_INT);
    #endif
        intCode = SPIInterruptVectorGet(SOC_SPI_0_REGS);
        while (intCode)
        {
            if(intCode == SPI_TX_BUF_EMPTY)
            {
                tx_len--;
                SPITransmitData1(SOC_SPI_0_REGS, *p_tx);
                p_tx++;
                if (!tx_len)
                {
                    SPIIntDisable(SOC_SPI_0_REGS, SPI_TRANSMIT_INT);
                }
            }
            if(intCode == SPI_RECV_FULL)
            {
                rx_len--;
                *p_rx = (char)SPIDataReceive(SOC_SPI_0_REGS);
                p_rx++;
                if (!rx_len)
                {
                    flag = 0;
                    SPIIntDisable(SOC_SPI_0_REGS, SPI_RECV_INT);
                }
            }
            intCode = SPIInterruptVectorGet(SOC_SPI_0_REGS);
        }
    }


Thank you in advance for your support.

Best regards,
Jonathan