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.

CC3220SF-LAUNCHXL: CC3220SF-LAUNCHXL

Part Number: CC3220SF-LAUNCHXL

Hi,

I have a peripheral which needs to change the SPI clock frequency after writing a command to it, the same is shown in the below figure. 

Is there a simple way to do this with TI libraries?

Thank you,

Kishore.

  • Hi Kishore,

    Why you not send eight dummy bytes via SPI?

    Jan
  • Hi Jan,

    I need to send two commands first is data and then just the clock with a different frequency, both needs to happen without changing CS signal.
    From the above figure, I need to send the exact command 11000010(0xC2) then without changnig the CS to low, I need to change the clock frequency for next 65 cycles.


    Thank you,
    Kishore.
  • Hi Kishore,

    Really frequency need to be different? Are you sure? Because easiest way could be to set frequency to reference clock and with same frequency send first command 0xC2 also.

    Jan
  • Hi Kishore,

    To switch the SPI clock speed, you will need to first close and then reopen the SPI interface with the new clock rate. This can be done by changing .bitRate in your SPI open parameters.

    Since you mentioned that the CS signal must not be de-asserted during the switch, the simplest way to ensure that is to make the CS signal a SW controlled GPIO. To do so, set the SPI peripheral into 3 wire mode, with SW controlled CS. The SPI CS settings are done in CC3200SF_LAUNCHXL.c, in the spiCC3220SDMAHWAttrs struct. Please use the following settings:

        {
            .baseAddr = GSPI_BASE,
            .intNum = INT_GSPI,
            .intPriority = (~0),
            .spiPRCM = PRCM_GSPI,
            .csControl = SPI_SW_CTRL_CS,
            .csPolarity = SPI_CS_ACTIVELOW,
            .pinMode = SPI_3PIN_MODE,
            .turboMode = SPI_TURBO_OFF,
            .scratchBufPtr = &spiCC3220SDMAscratchBuf[CC3220SF_LAUNCHXL_SPI1],
            .defaultTxBufValue = 0,
            .rxChannelIndex = UDMA_CH6_GSPI_RX,
            .txChannelIndex = UDMA_CH7_GSPI_TX,
            .minDmaTransferSize = 10,
            .mosiPin = SPICC32XXDMA_PIN_07_MOSI,
            .misoPin = SPICC32XXDMA_PIN_06_MISO,
            .clkPin = SPICC32XXDMA_PIN_05_CLK,
            .csPin = SPICC32XXDMA_PIN_NO_CONFIG
        }

    Then, configure a GPIO in the gpioPinConfigs struct of the same file. If you wanted to keep CS on pin8, then configure GPIO17 as an output. With that, you can use a GPIO_write() to assert CS when needed in your code.

    Let me know if you need more clarification or have further questions on this topic.

    Regards,

    Michael

  • Hi Michael,

    Thanks for this suggestion, I will try this.
    I also have a doubt, I am using 4PIN mode for previous SPI write/read. will this change affect the previous write/read?
    do I need to change CS pin for every SPI write?

    Thank you,
    Kishore.
  • Hi Kishore,

    The 3PIN setting is done in a struct that is set at compile time. Thus, this change will affect all SPI functionality. You will need to manually toggle the CS GPIO when needed. This does not necessarily mean that you need to toggle the CS pin for every SPI word in a transfer. Some peripherals are able to handle CS asserted continuously for multi-word transfers. You will have to take a look at the datasheet for your peripheral to see what it expects.

    Regards,
    Michael
  • Hi Michael,

    I have made the CS change for other SPI operations, Its working as is used to.
    As per your suggestion I am able to change the frequency of the clock without changing the CS pin.
    I need continuous clock cycles for 65 cycles, I tried increasing transaction.count variable before calling SPI_transfer() function.
    But the maximum number of consequtive clocks I am getting is 32.

    Is there any way that I can get continuous clock cycles without having idle time.

    Thank you,
    Kishore.
  • Hi Kishore,

    There is no way to get the SPI controller to send more than 32 consecutive clocks without a small delay. This is since the max size of a SPI word supported is 32 bits, and after that the SPI controller will need to get the next 32bit word ready to transmit.

    At this point, you will likely need to use a PWM signal to send the consecutive clocks that you need. Take a look at the pwmled2 example for how to use the PWM peripheral.

    Regards,
    Michael
  • Hi Michael,

    1) I am using pin 5 (GPIO_14 ) as my SPI clock, can I produce PWM waveform on this pin.

    If I can use PWM on the same line, please suggest how can I do it.

    2) Another way is, Instead of using SPI libraries, I am using all 4 pins as GPIOs. I am able to write and read data, mainly I can vary clock just after writing 0xC2 command, the problem with this is the GPIO toggling is it's not consistent, I am not meeting the timing, my requirement is, I need 32us for each cycle. sometimes I am getting 32us and sometimes I am getting 31.8us.

    Please see the below snapshots for the same

    The delay in the code is the same between the toggles. still, I see the time differences.

    Is it because of the latencies added by GPIO_toggle function. If so can you suggest me any alternate methods?

    Thank you,

    Kishore.

  • Hi Kishore,

    Given that the peripheral that have is using the SPI clock signal as the reference clock for its calibration, I don't think that you will want to use GPIO toggling in software as you will most likely be unable to get the timing within the tolerances of your device. I suggest setting up the PWM.

    Unfortunately, pin 5 cannot be configured as a PWM pin. You will need to use another pin that does support being configured as PWM. If you look at Table 16-7 of the TRM:
    www.ti.com/.../swru465.pdf
    You'll see the various multiplexing capabilities of each pin. For example, pin1 can be configured as a PWM output.

    Regards,
    Michael
  • This is of great help! Thank you Michael.