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.

usb and temperature sensor



Hi,

 

I want to read value of embedded temperature sensor on TM4C123Gh6PH. I used usb_dev_serial.c example and added following lines to read chip temperature.

When I programmed the code, it is working but when I disconnected power of the device and power up it again, the usb connection is known as “unknown device”. Can anybody help me to figure out where the problem is?

 Thanks

 

SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

                    ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);

                    ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);

                    ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);

                    ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);

                    ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);

                    ADCSequenceEnable(ADC0_BASE, 1);

 

                    uint32_t ui32ADC0Value[4];

                    volatile uint32_t ui32TempAvg;

                    volatile uint32_t ui32TempValueC;

                    volatile uint32_t ui32TempValueF;

 

 

    while(1)

    {

 

 

       ADCIntClear(ADC0_BASE, 1);

       ADCProcessorTrigger(ADC0_BASE, 1);

       while(!ADCIntStatus(ADC0_BASE, 1, false))

       {

       }

       ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);

       ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;

       ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;

       ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;

}

  • Hello Majid

    The code is fine. If you remove the ADC Conversion code while loop, then does the USB enumerate?

    Secondly, if after power up you connect CCS w/o loading a code, where the does the PC show the processor execution to be?

    Regards
    Amit
  • Hi Amit,
    I removed ADC conversion part in while loop and there are just configuration part as following.
    But still the same problem happens.
    After loading the code, it is working fine. The problem rise up when I power up the board.

    Thanks

    uint32_t ui32ADC0Value[4];
    volatile uint32_t ui32TempAvg;
    volatile uint32_t ui32TempValueC;
    volatile uint32_t ui32TempValueF;
    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
    ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
    ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
    ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
    ADCSequenceEnable(ADC0_BASE, 1);
  • Hello Majid,

    OK so that rules out the while loop. What about the second part of the question in the previous post. Did you try to see where the PC is. Also is the code being Flashed to 0x0 location of Flash?

    Regards
    Amit
  • Hi Amit,
    If I understood you question, you asked me to debug the code and find out exact location of error. But after power up if I want to debug the code, I have to program it, and after programming there is not any problem.
    Thanks
  • Hello Majid.

    Yes. However you do not need to load a program. In File -> New -> Target Configuration create a target configuration "Debug.ccxml" (Debug.ccxml is just a name) and then select the connection and target device

    Then View -> Target Configuration will open a window. In the window expand User Defined to find Debug.ccxml. Right Click the same and select Launch Target Configuration. Once launched, then right click on the same and ask it to "Connect Target". That will allow you to debug w/o loading the program. You can load the symbol file (.out file) and be able to see where the code is looping!!!

    Regards
    Amit
  • Hi Amit,
    I tried to do that but it opens assembly code and the code stay at this line:

    B5F0E7FE LDRLTB R14, [R0, #2046]!

    thanks
  • Hello Majid

    Did you check the NVIC_FAULTSTAT and NVIC_FAULTADDR register to see if there is a Bus Fault and the corresponding Address?

    Regards
    Amit
  • Hello Amit,
    Thanks for your help, the problem is solved. I just added some delay between following lines:

    ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
    SysCtlDelay(80000000 / (100000 * 3));
    ROM_ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);

    I just have one more question, I am using USB in VCB mode, and I am using following function to receive data. When data receive interrupt happens and the program executing the following function, it masks all other interrupts. I tried to unmasked or enable other interrupts like ADC but it did not work. Could you please let me know how can enable other interrupts?

    uint32_t
    RxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue,
    void *pvMsgData)

    Thanks
    Majid
  • Hello Majid

    You meant VCP and not VCB!! Where do you see in the usblib the NVIC entry being disabled before callback is called?

    Regards
    Amut