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.

Problem with Generation of SPI-1 Clock in TMS320C6748

Other Parts Discussed in Thread: TMS320C6748

Hi,
We have with us custom built Board. The processor used is TMS320C6748.
We got a code (csl folder) ,which had a generic loop back code for SPI-0. We modified it to work as 3- pin SPI Master Mode for SPI-1 to communicate with another Controller . The code is pasted at the end of this mail. When we execute the code

• The SPIDAT1 register shows correct
• SPIGCR1  register  shows Mater mode & SPI Enabled & Loopback is disabled
• SPIPC0 register  shows SOMIFUN,CLKFUN & SIMOFUN enable

However the Clock is not coming at the Clock PIN.

I configured this clock pin as GPIO and could see the toggling in MSO. Can you please look into the code and tell where we are making mistake.

 

/*
================================================================================
                            INLCUDE FILES
================================================================================
*/

#include <stdio.h>
#include "soc_C6748.h"
#include "cslr_spi.h"
#include "cslr_psc_C6748.h"


#define SPI_NUM_OF_TXBITS   0x08
#define SPI_NEW_DATA_NO   0x01

CSL_SpiRegsOvly  spiRegs=(CSL_SpiRegsOvly)CSL_SPI_1_REGS;


/*
================================================================================
                         LOCAL FUNCTION PROTOTYPES
================================================================================
*/

static void Spi_dev_init();
static void Spi_test();

 

/*------------------------------------------------------------------------------
* void main(void)
------------------------------------------------------------------------------*/
/*
*
*  @Param1 : None
*  @RetVal : None
*  @see    : None
*
*  @Description : This function is the main function for the SPI loop back test
*
*/
void main(void)

{
    /* This function will set up the serial port in the loopback mode and     *
     * write a test string for checking the SPI interface                     */

    printf("\nSPI test started.\n");

    /* now initialise the SPI controller with appropriate settings            */
    Spi_dev_init();

    /* test the SPI interface by sending the data                             */
    Spi_test();

}
/*------------------------------------------------------------------------------
* static void Spi_dev_init(void)
------------------------------------------------------------------------------*/
/*
*
*  @Param1 : None
*  @RetVal : None
*  @see    : refer main()
*
*  @Description :This function initialises the SPI interface in the loopback
*                mode with 8 bit transmission and all timer settings as default.
*/
static void Spi_dev_init(void)
{
    CSL_PscRegsOvly psc0Regs = (CSL_PscRegsOvly)CSL_PSC_1_REGS;
   
    /* deassert SPI0 local PSC reset and set NEXT state to ENABLE             */
    psc0Regs->MDCTL[CSL_PSC_SPI1] = CSL_FMKT( PSC_MDCTL_NEXT, ENABLE )
                                 | CSL_FMKT( PSC_MDCTL_LRST, DEASSERT );
    /* Move SPI0 PSC to Next state                                            */
    psc0Regs->PTCMD = CSL_FMKT(  PSC_PTCMD_GO0, SET );
   
    /* Wait for transition                                                    */
    while ( CSL_FEXT( psc0Regs->MDSTAT[CSL_PSC_SPI1], PSC_MDSTAT_STATE )
            != CSL_PSC_MDSTAT_STATE_ENABLE );
             
    /* First reset the SPI chip                                               */
    spiRegs->SPIGCR0 = CSL_FMK(SPI_SPIGCR0_RESET,
                                            CSL_SPI_SPIGCR0_RESET_IN_RESET);

    /* now bring the chip out of reset state                                  */
    spiRegs->SPIGCR0 = CSL_FMK(SPI_SPIGCR0_RESET,
                                            CSL_SPI_SPIGCR0_RESET_OUT_OF_RESET);

    /* enable the CLKMOD and MASTER bits in the SPI global control reg        */
    spiRegs->SPIGCR1 |=  CSL_FMK( SPI_SPIGCR1_MASTER,0x01)
                                  | CSL_FMK(SPI_SPIGCR1_CLKMOD,0x01);

     /* enable the pins so that they are used for the SPI interface(Multiplex) */
    spiRegs->SPIPC0  = CSL_FMK(SPI_SPIPC0_CLKFUN ,0x01)
                                  | CSL_FMK(SPI_SPIPC0_SOMIFUN ,0x01)
                                  | CSL_FMK(SPI_SPIPC0_SIMOFUN ,0x01);


    /* configure the data format in SPIFMT                                    */
    spiRegs->SPIFMT[0] = CSL_FMK(SPI_SPIFMT_CHARLEN,SPI_NUM_OF_TXBITS)
                                  | CSL_FMK(SPI_SPIFMT_PRESCALE,0x95);

    /* set the preconfigure data format as 0 which is already set above       */
    spiRegs->SPIDAT1 = CSL_FMKT(SPI_SPIDAT1_DFSEL,FORMAT0);

    /* dont use any interrupts hence disable them                             */
    spiRegs->SPIINT0 = CSL_FMKT(SPI_SPIINT0_RXINTENA,DISABLE);

    spiRegs->SPIGCR1 |=  CSL_FMK(SPI_SPIGCR1_ENABLE,0x01)
                                  | CSL_FMK(SPI_SPIGCR1_LOOPBACK,0x00);

}
/*------------------------------------------------------------------------------
* static void Spi_test(void)
------------------------------------------------------------------------------*/
/*
*
*  @Param1 : None
*  @RetVal : None
*  @see    : refer main()
*
*  @Description : This function tests the SPI loop back interface by sending a
*                 string and comparing with the data recieved.
*
*/

static void Spi_test(void)
{
    char *data="A"; /* test string to transmit*/
    char test='n';

 //   while (*data)
  while(1) 
   
    {

        /* write the data to the transmit buffer                              */
        CSL_FINS(spiRegs->SPIDAT1,SPI_SPIDAT1_TXDATA,*data);

//        /* check if data is recieved                                          */
        while ((CSL_FEXT(spiRegs->SPIBUF,SPI_SPIBUF_RXEMPTY))
                                                   == SPI_NEW_DATA_NO);

       test = (CSL_FEXT(spiRegs->SPIBUF,SPI_SPIBUF_RXDATA));


//        if (test == *data)
//        {
//            printf("sent %c recv %c\n",*data,test);
//        }
//        else
//        {
//            printf("ERROR : sent %c recv %c\n",*data,test);
//            printf("\nSPI Loopback test Failed.\n");
//            return;
//        }
 //       data++;
    }
 //   printf("SPI Loopback test success.\n");
}

/*
================================================================================
                            END OF FILE
================================================================================
*/