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.

TMS320C6678: Changing SPI module clock frequency

Part Number: TMS320C6678

Hi,

I was running the SPI basic example test project for C6678 in which I transmit predefined data and the receive using SPI from NOR_flash memory. I am using Processor SDK 5.2. I put a breakpoint in the Board_initSPI function to see the SPI clock frequency. I ran the simulation and in the variables windows, I saw that sysclock frequency is "4294967295" and the SPI module input clock frequency is "166666666". I am not able to understand why the system clock frequency is so high. From the datasheet, I found out that maximum clock frequency is 1400 MHz. I need the SPI clock frequency to be somewhere between 10-20 MHz because the device from which the board is gonna interface with afterwards has its SPI module frequency less than 20 MHz. How can I change the SPI clock frequency? And to operate SPI in chipselect mode, should I change the "pinMode" to 0 and "csNum" to 1?

I am attaching a screenshot of the debug window for reference.

Thank You

  • Harshul Agarwal said:
    I saw that sysclock frequency is "4294967295" and the SPI module input clock frequency is "166666666". I am not able to understand why the system clock frequency is so high.

    The sysclock frequency of "4294967295" is the special value of BOARD_SYS_CLK_DEFAULT, which the stub function in ti-processor-sdk-rtos-c667x-evm-05.03.00.07\pdk_c667x_2_0_13\packages\ti\board\src\boardStub.c stores in socInfo->sysClock. The value of BOARD_SYS_CLK_DEFAULT isn't actually used to configure the SPI clock.

    Harshul Agarwal said:
    How can I change the SPI clock frequency?

    The bitRate field in the params argument of SPI_open is used to set the SPI clock frequency, where the SPI prescaler is set by dividing the SPU module input clock frequency by the requested bitRate.

    For the SPI_BasicExample_C6678_c66xTestProject the bitRate returned by the SPI_Params_init() call is 1000000 (i.e. 1MHz) which gets passed to Board_flashOpen() to initialise the SPU module. You should be able to modify the spi_test() function in the SPI_BasicExample_C6678_c66xTestProject example to set the spiParams.bitRate prior to the call to Board_flashOpen() to change the SPI clock frequency.

  • Thanks Chester for clearing this. I want to just confirm 1 more thing."SPI_v0_HWAttrs_s" function, to use 4-pin chip select mode, should I set "pinMode = 1" and "csNum = 0"?

    Regards,

  • HArshul,

    Please  refer to the file  SPI_v0.h located at  pdk_c667x_2_0_13\packages\ti\drv\spi\src\v0. This  file contains the description of the pinmux and  Chip select Number setting. pinMode of 1 corresponds to 4 pin mode setup and the CsNum= 0 selects chip select 0.

    Hope this clarifies the SPI driver HWAttr configuration setup. To modify the default you can use the following APIs  "

    SPI_v0_HWAttrs spi_cfg;
    
    SPI_socGetInitCfg(0, &spi_cfg);  //Read port 0 SPI configuration
    spi_cfg.inputClkFreq = socInfo.sysClock/SPI_MODULE_CLOCK_DIVIDER;
    spi_cfg.pinMode =1;
    spi_cfg.CsNum=0;
    SPI_socSetInitCfg(0, &spi_cfg);
    SPI_Params_init(&spiParams);
    boardHandle = Board_flashOpen(BOARD_FLASH_ID_NORN25Q128A13ESF40F,  0,  (void *)(&spiParams));

    Regards,

    Rahul