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.

Dynamically change SPI clock

Hello everyone!

I use CCS 6.x with SPI's PSP/BIOS driver for programming C6748 DSP.
Question: how to dynamically change the clock of SPI master. I share one SPI for several slaves, each has different speed and own (separate) tasks.

I will be appreciated for any help

  • I think, you can try the "SpiCalculateClockSettings" and "SpiConfigureNewClkSettings" APIs to configure the clock of SPI.
    C:\ti\biospsp_03_00_01_00\drivers\spi\src\Spi.c

    I haven't tried this but try it out and see whether it fulfill your requirement.

  • ok, I will try.

    Thanks
  • Hi Artem,

    Artem said:
    Question: how to dynamically change the clock of SPI master. I share one SPI for several slaves, each has different speed and own (separate) tasks.


    You can write a separate function something like below and pass the "clock-to-be-set" as a parameter.

    In sofware you must be knowing to which device you are going to communicate with;So accordingly, you can call this clock-configuration-function for each task.

    For example:-
    This code snippet is from C6748 starterware. For more info, refer to the package.

    // in each task insert a function call like this.

    SPIClkConfigure(SOC_SPI_1_REGS, 150000000, 20000000, SPI_DATA_FORMAT0);

    /**
    * \brief - It will configure the prescalar to generate required spi clock\n.
    *
    * \param - baseAdd is Memory Address of the SPI instance used\n.
    * \param - moduleClk is the input clk to SPI module from PLL\n.
    * \param - spiClk is the spi bus speed\n.
    * \param - dataFormat is instance of the data format register used\n.
    *
    * \return none.
    **/
    void SPIClkConfigure(unsigned int baseAdd, unsigned int moduleClk,
    unsigned int spiClk, unsigned int dataFormat)
    {
    unsigned int prescale;

    prescale = (moduleClk/spiClk) - 1;

    HWREG(baseAdd + SPI_SPIFMT(dataFormat)) = \
    (SPI_SPIFMT_PRESCALE & (prescale << SPI_SPIFMT_PRESCALE_SHIFT));
    }
  • Thank you, Shankari.

    I did as you said.
  • Artem,

    You are welcome.