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.

Clock Matching from tm4c129 to tm4c123

I was successful in using dht-11 sensor with tm4c129, but when i tried the same code on tm4c123 it entered in infinite loop. I think the problem is due to the clock because, the other part of the code is the same.

I am using sysctlclock freqset((sysctl_xtal_25Mhz | sysctl_osc_main| sysctl_use pll | sysctl_cfg_vco480), 40000000);on TM4C129 this is giving me clk frq of 40Mhz.

SysCtlClockSet(SYSCTL_SYSDIV_5| SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ); on TM4C123 this gives me frq of 40Mhz when i do syscltclockget();

I still dont get value on TM4C123. what might be the reason? is it due to the vco?

How to get similar functionality like sysctlclock freqset using SysCtlClockSet?

 

  • Hello Ankeet

    Ankeet Gugale said:

    I am using sysctlclock freqset((sysctl_xtal_25Mhz | sysctl_osc_main| sysctl_use pll | sysctl_cfg_vco480), 40000000);on TM4C129 this is giving me clk frq of 40Mhz.

    SysCtlClockSet(SYSCTL_SYSDIV_5| SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ); on TM4C123 this gives me frq of 40Mhz when i do syscltclockget();

    If you are getting 40MHz with the TM4C123 on calling the function SysCtlClockGet, then what is the issue?

  • Hello Amit,

    Following is the code in which i have interfaced dht 11 sensor with tm4c129 and tm4c123.
    when i interface dht with tm4c129 i am getting the values , but when i am interfacing it with tm4c123 it is not working.
    i have changed the clock API as mentioned in my last post.
    what might be the reason? will u pls help me out?

    /*
    * main.c
    */
    #include <stdint.h>
    //#include <stdio.h>
    #include <stdbool.h>
    //#include <string.h>
    #include <stdlib.h>
    #include "inc/hw_memmap.h"
    #include "inc/hw_ints.h"
    #include "driverlib/gpio.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/interrupt.h"
    //#include "driverlib/uart.h"
    #include "driverlib/debug.h"
    #include "inc/hw_gpio.h"
    #include "inc/hw_types.h"
    #include "inc/hw_sysctl.h"
    #include "driverlib/timer.h"
    #include "utils/ustdlib.h"

    int temp;
    int humidity;
    int32_t TemperatureHumidity[2],count=0;

    void ConfigureUART(void)
    {
    SysCtlPeripheralEnable(SYSCTL_PERIPH_UART5);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

    //UART RX and TX Configure UART
    GPIOPinConfigure(GPIO_PE4_U5RX);
    GPIOPinConfigure(GPIO_PE5_U5TX);
    //GPIO C6 and C7 as UART function ,they must be configured for use as peripheral
    GPIOPinTypeUART(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5);
    //UARTConfigSetExpClk(UART5_BASE, SysCtlClockGet(),115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |UART_CONFIG_PAR_NONE));
    UARTEnable(UART5_BASE);
    }
    int ReadDHT()
    {
    // bit buffers & timeout
    char bitcount;
    char byte;
    char bits[5] = {0,0,0,0,0};
    unsigned int bitints[6];
    long timerval;


    unsigned int loopCnt = 10000;

    #define MY_PIN_PERIPH SYSCTL_PERIPH_GPIOA
    #define MY_PIN_PORTBASE GPIO_PORTA_BASE
    #define MY_PINNR GPIO_PIN_5

    #define MY_TIMER_PERIPH SYSCTL_PERIPH_TIMER0
    #define MY_TIMERBASE TIMER0_BASE
    #define MY_TIMER TIMER_B

    SysCtlPeripheralEnable(MY_TIMER_PERIPH);
    TimerConfigure(MY_TIMERBASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_ONE_SHOT);


    SysCtlPeripheralEnable(MY_PIN_PERIPH);

    GPIOPinTypeGPIOOutput(MY_PIN_PORTBASE, MY_PINNR);


    GPIOPinWrite(MY_PIN_PORTBASE, MY_PINNR, 0x0);

    // #loops = loops_per_us*time_in_us = time in us * loops/us = time_in_us *(clockfreq/10000000)
    SysCtlDelay((SysCtlClockGet()/3)/30 ); // -> 30 ms

    GPIOPinTypeGPIOInput(MY_PIN_PORTBASE, MY_PINNR);


    loopCnt = SysCtlClockGet()/100;
    while(GPIOPinRead(MY_PIN_PORTBASE, MY_PINNR))
    {
    loopCnt = loopCnt -1;
    if (loopCnt == 0)
    return 0;
    }


    loopCnt = SysCtlClockGet()/100;
    while(!(GPIOPinRead(MY_PIN_PORTBASE, MY_PINNR))) //0
    {
    loopCnt = loopCnt -1;
    if (loopCnt == 0)
    return 0;
    }

    loopCnt = SysCtlClockGet()/100;
    while(GPIOPinRead(MY_PIN_PORTBASE, MY_PINNR))
    {
    loopCnt = loopCnt -1;
    if (loopCnt == 0)
    return 0;
    }

    // start receiving 40 bits
    char i;
    bitcount = 7;
    byte = 0;

    int conta = 0;
    int timerval2=0;

    int largest = 0;
    int lowest = 99999;

    for (i=0; i < 40; i++)
    {
    loopCnt = SysCtlClockGet()/100;
    while(!(GPIOPinRead(MY_PIN_PORTBASE, MY_PINNR)))
    {
    loopCnt = loopCnt -1;
    if (loopCnt == 0)
    return 0;
    }


    TimerDisable(MY_TIMERBASE, MY_TIMER);
    TimerConfigure(MY_TIMERBASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_B_ONE_SHOT);
    TimerLoadSet(MY_TIMERBASE, MY_TIMER, SysCtlClockGet()/4000);
    TimerEnable(MY_TIMERBASE, MY_TIMER);
    timerval = TimerValueGet(MY_TIMERBASE, MY_TIMER);

    loopCnt = SysCtlClockGet()/100;
    while(GPIOPinRead(MY_PIN_PORTBASE, MY_PINNR))
    {
    loopCnt = loopCnt -1;
    if (loopCnt == 0)
    return 0;
    }

    timerval2 = TimerValueGet(MY_TIMERBASE, MY_TIMER);


    conta = timerval - timerval2;

    if (conta>largest)
    largest = conta;

    if (conta<lowest)
    lowest = conta;

    if ((conta) > (1000))
    bits[byte] |= (1 << bitcount);
    if (bitcount == 0)
    {
    bitcount = 7;
    byte++;
    }else{
    bitcount--;
    }
    }

    bitints[0] = ((unsigned int) bits[0] & (0x000000FF));
    bitints[1] = ((unsigned int) bits[1] & (0x000000FF));
    bitints[2] = ((unsigned int) bits[2] & (0x000000FF));
    bitints[3] = ((unsigned int) bits[3] & (0x000000FF));
    bitints[4] = ((unsigned int) bits[4] & (0x000000FF));

    if(((bitints[0] + bitints[1] + bitints[2] + bitints[3]) & (0x000000FF)) == bitints[4]){
    temp = bitints[2];
    humidity = bitints[0];
    return 1;
    }else{
    return 0;
    }

    }

    void main(void) {
    SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |SYSCTL_XTAL_16MHZ);

    ConfigureUART();

    //UARTprintf("Its runing at : %d\n",SysCtlClockGet());
    while(1){
    SysCtlDelay(SysCtlClockGet()/ 3);

    if(ReadDHT() == 0)
    {
    temp=0;
    humidity=0;
    UARTCharPut(UART5_BASE,'E');
    }
    else
    {
    // UARTprintf("Temp %d !\n",temp);
    // UARTprintf("Hum %d !\n",humidity);
    TemperatureHumidity[0]=temp;
    TemperatureHumidity[1]=humidity;
    UARTCharPut(UART5_BASE,TemperatureHumidity[count]);
    count++;
    }
    }

    }


    Thank You in advance.
  • Hello Ankeet

    The UART configuration line in your code is commented!!!

    //UARTConfigSetExpClk(UART5_BASE, SysCtlClockGet(),115200,(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |UART_CONFIG_PAR_NONE));