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.

Setting SysCtlClockSet for SSIConfigSetExpClk

I am having difficulties setting the SysClk so that I can enable SPI to run at 6.4Mhz.

I have tried many different combinations of dividers etc, but have been unable to get it to run at my required speed.

For example, the below causes SPI to run at an inaccurate 8MHz, i.e. it is not stable..possibly a remainder in the division?

SysCtlClockSet(SYSCTL_SYSDIV_4| SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |SYSCTL_OSC_MAIN);
SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_1, SSI_MODE_MASTER, 6400000, 8);

Any advice on how I get my SPI to run at 6.4Mhz, is appreciated. I am using the Tiva C LaunchPad (TM4C123GXL).

Glenn.

  • Hi Glenn,

         Based from this posts below, there is an issue with SysCtlClockGet().

         problem of running tiva on 80 MHz

         SysCtlClockGet returns strange frequency

    Glenn Vassallo said:
    SysCtlClockSet(SYSCTL_SYSDIV_4| SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |SYSCTL_OSC_MAIN);
    SSIConfigSetExpClk(SSI0_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_1, SSI_MODE_MASTER, 6400000, 8);

    Try these lines below instead. From your SysCtlClockSet parameters, system clock will be 50 MHz.

    SysCtlClockSet(SYSCTL_SYSDIV_4| SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |SYSCTL_OSC_MAIN);
    SSIConfigSetExpClk(SSI0_BASE, 50000000, SSI_FRF_MOTO_MODE_1, SSI_MODE_MASTER, 6400000, 8);

    - kel     

  • Thanks Kel,

    Unfortunately it has the same result.

    Glenn.

  • Hello Glenn,

    Can you check what the value of the SSICR0 and SSICPSR is in both the cases?

    Regards

    Amit

  • Amit Ashara said:
    Can you check what the value of the SSICR0 and SSICPSR is in both the cases?

    Can you let me know where I check these values? 

    Thanks,

    Glenn.

  • Hello Glenn,

    The two registers are at offset 0x0 and 0x10 of the SSI Base Address.

    Regards

    Amit

  • Hi Amit,

    I get the following when I run uint32_t ulTemp1 = HWREG(0x40008000);

    0x0000078F

    00000000000000000000011110001111

    Glenn

  • Hello Glenn,

    The value of SSICR0 register is for what System Clock. Also what is the SSICPSR register value. I would appreciate the table for 50MHz and 80Mhz for the above two registers.

    Regards

    Amit

  • Hi Amit,

    Is my SSICR0 register set correctly for the speed I am wanting?

    Can you provide any more information on the details you have requested? Any steps you can provide are appreciated.

    Thanks, 

    Glenn.

  • Hi Glenn,

    If you allow me here -  Amit suggest the followings: just set a breakpoint after the line setting the SPI speed and then inspect/read the registers mentioned, and this for two cpu frequencies - could be a hardware bug, must be inspected by Amit using internal test programs.

    Regards,

    Petrei

  • Hello Glenn,

    I ran SSI-0 with the following setting

        SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); //80 MHz

        SSIConfigSetExpClk(SSI0_BASE, 80000000, SSI_FRF_MOTO_MODE_3, SSI_MODE_MASTER, 6400000, 8);

    On the Pin PA2 I see 6.67MHz clock when SSI is transmitting

    Also the register value for SSICR0 is 0x587 and SSICPSR is 0x2 for 80MHz operation

    At 50MHz I had to make some changes

        SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN); //80 MHz

        SSIConfigSetExpClk(SSI0_BASE, 50000000, SSI_FRF_MOTO_MODE_1, SSI_MODE_MASTER, 6200000, 8);

    On the Pin PA2 I see 6.27MHz clock when SSI is transmitting

    Also the register value for SSICR0 is 0x387 and SSICPSR is 0x2 for 50MHz operation

    Regards

    Amit

  • Hi Amit,

    Thanks for the update and effort.

    I have tried this out on 3 Tiva C LaunchPads, all provide the same result, one was even a new one just taken out of the box. My code does not set registers anywhere that I am aware of. I am developing for testing purposes inside the TI-RTOS SPI Loopback example, as my actual program runs inside TI-RTOS. However, I am using the standard Tivaware Library and hence my code is similar to the tivaware - examples - ssi - spi_master.c

    I ran the exact same settings you have provided above and get the following results:-

    At 80Mhz

    Clock - PA2 - This is erratic in my LA, it either gives 6Mhz or 8Mhz. My LA is set to 24Mhz resolution (though it is a relatively low budget one)

    MOSI - PA5 - This is closer to the expected result - 6.84Mhz or 6Mhz

    At 50Mhz

    Clock - PA2 - This is erratic in my LA, it either gives 6Mhz or 8Mhz. My LA is set to 24Mhz resolution.

    MOSI - PA5 - This is closer to the expected result - 6.84Mhz, but this seems erratic, with it also 

    Given the results you also got, is it actually possible to run at a stable 6.4Mhz? I am surprised that it is not possible to get something close and stable.

    Glenn.

  • Hello Glenn,

    Exact 6.4Mhz is not possible on TM4C123. The equation to use is

    System Clock = 6.4Mhz*2*N (when N is a value > 1)

    For N=1 this translates 12.8Mhz, N=2 it is 25.6MHz and so on, none of which can be derived 200MHz as either a integer value or integer.5 value.

    Regards

    Amit

  • Hi Amit,

    Thanks for the explanation, I am new to this aspect of micro controllers. Your information has now let me know I need to think of another way forward.

    Basically, I am trying to create a signal with MOSI that provides the correct high and low timings. It may be possible to get the right timing. including SPI speed if I use a word size greater than the 8 bits I am currently using.

    Each bit needs to be 1.25us long in total.

    1 =  0.6us high + 0.65us low   +-150ns  

    0 = 0.25us high + 1us low  +-150ns

    Also, open to any suggestions on how else I can accomplish this :-)

    Glenn.

  • Hello Glenn,

    If the idea is to create a signal with such timing, then why not use the Timer in PWM Mode?

    Regards

    Amit

  • Hi Amit,

    I was trying to use SPI as I have this working with one type of chip that my device works with, so it would have been good to use the same underlying technology with a different chip (the chips are for individually addressable RGB LEDs). The other chip uses Manchester encoding, so nice and easy to just translate an 8bit number into a 16bit Manchester Encoded representation. These new chips are different, so just working out how to get then to work with my device.

    I am certainly open to developing a PWM solution that uses a Timer. If you can point me to any resources or examples to help me get started that would be fantastic!

    Thanks again,

    Glenn.

  • Hello Glenn,

    You can refer to the example of pwm.c

    C:\ti\TivaWare_C_Series-2.1.0.12573\examples\peripherals\timer

    Regards

    Amit

  • Thanks Amit, I appreciate all your help with this!

    Glenn.

  • Hi Amit,

    I've been looking into PWM, and I am unsure I can achieve what I need with this technique .Basically I am trying to work out if I am asking too much from PWM.

    I need to drive a Pin high and low, but the timing on the high and low will be dependent on whether I am wanting to send the input pattern for a 1 or a 0.

    For example: I have the following 8bit number

    0b11001011

    Can I use PWM to send different timings depending on the value of each bit? (In my application I will have many hundreds of bytes to send, and timing has to be with in certain parameters)

    Here are the specs:-

    So as you can see, the Period will be the same, no matter if I have a 0 or a 1, however the Duty Cycle will change depending on whether I have a 0 or 1

    I have worked out how I can determine the bit value and even the duty cycle length based on bit value. But I am having issues getting the right timing, so that it only sends one Pulse per bit.

    Any suggestions or opinion is appreciated.

    Glenn.

  • Hello Glenn

    You are in luck it seems. I just posted the project based on TM4C129 (see my last post)

    http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/360959.aspx

    Regards

    Amit

  • Amit,

    Thank you very much, that is exactly what I am trying to do! 

    Glenn.

  • Hi Amit,

    Would the above settings be the same for SSI_FRF_NMW mode?

    Thanks,
    Kimon
  • Hello Kimon,

    The settings will remain the same for Micro Wire. Note that on TM4C129 the uWire is no longer supported.

    Regards
    Amit