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.

TM4C129 ADC

I am trying to do ADC programming  in CMSIS RTOS using keil,

Following is my program.. both threads are working but in adc_rx()  variable "result" is not modifying, that means a to d conversion is not happening.. what would be the problem??

osThreadDef(led_1,osPriorityNormal,1,0);

osThreadDef(adc_rx,osPriorityAboveNormal,1,0);

int main (void) {

osKernelInitialize (); // initialize CMSIS-RTOS
port_init();
adc_init();
thread_1=osThreadCreate(osThread(led_1),NULL);

thread_adc=osThreadCreate(osThread(adc_rx),NULL);

osKernelStart (); // start thread execution 

}

void led_1(void const *arg){
while(1){
GPIOF_AHB->DATA^=0x01;
osDelay(50);
}

}

void led_2(void const *arg){
while(1){
GPIOF_AHB->DATA^=0x010;
osDelay(80);
}

}

void port_init(void){
int i;
SYSCTL->RCGCGPIO|=0x20;
for(i=0;i<20;i++);
GPIOF_AHB->LOCK|=0X4C4F434B;

GPIOF_AHB->AFSEL&=~0x010;
GPIOF_AHB->AMSEL&=~0x010;
GPIOF_AHB->PCTL=0x0;
GPIOF_AHB->DIR|=0x010;
GPIOF_AHB->DEN|=0x010;
}

void adc_rx(void const *arg){
unsigned long result;
while(1){

while((ADC0->SSFSTAT0&0x800)==0){
osDelay(10);
}
result=ADC0->SSFIFO0;
osDelay(10);
}
}


void adc_init(void){
int i;
SYSCTL->RCGCGPIO|=0x10;
for(i=0;i<20;i++);

GPIOE_AHB->AFSEL|=0x0f;
GPIOE_AHB->AMSEL|=0x0f;
GPIOE_AHB->DIR=0x00;
GPIOE_AHB->DEN&=~0x0f;

SYSCTL->RCGCADC|=0x1;
ADC0->SSPRI|=0X3210; 
ADC0->ACTSS&=~0x0f; 
ADC0->EMUX&=0x00; 
ADC0->SSMUX0&=~0XFF; 
ADC0->SSEMUX0&=~0XFF; //
ADC0->SSCTL0|=0X06;
ADC0->SSTSH0|=0x0c;
ADC0->ACTSS|=0x01;

}

  • RTOS AND DRM style coding - that's a complete violation of "KISS."

    Would it not be far faster, easier - for both you & your hapless forum helpers - to

    • "hold off" the RTOS at this stage 
    • use the tried, true, infinitely more readable (and understandable) API

    Once successful - then (and only then) would prove best to ADD Complications!

    Starting with so many variables & complexity insures (most always) delay, frustration & confusion...   (for both you & your helpers)

    You are to be applauded for your (obvious) effort.    And questioned/redirected re: the decision to make the (simple) unduly complex - especially for starting the project w/SO MANY battlefronts in your gunsights.   (RTOS, DRM and ADC...)

    Think KISS - now - next project - ALWAYS!  (unless you wish to admit (welcome, really) pain & suffering)

  • Ohh k.. Thank you Sir..!!
  • Sir was for my Dad - or my Army career. Not required here.

    Note that vendor's Amit has long recommended the API over DRM - for multiple reasons. In a nutshell - the API is far more readable, has been around long enough to have been tried/tested -> proven! DRM - none of the above - each/every use proves an Adventure!

    Does not your plight - and landing here - prove these facts? So (enough) w/the reluctant "Ohhh k..." The API IS BY FAR - best/fastest/easiest way to go! Allez!
  • yeah.. Its easy to use API's but i want to do some basic programming for each of module of m/controller..


    Thanks cb1_mobile
  • Hello Shreyas,

    I want to add to cb1's recommendation of using API's instead of DRMs. It is not just easy to use APIs, using APIs makes it easy to maintain the code, easy to debug and easy to understand. By using DRMs, even the person who wrote the code might not understand their own code after a few months.

    If you don't want to use the APIs (and insist on doing it on your own), at the very least, you should comment each line of your code and use HWREG() API instead of DRMs, for the forum members to be able to help. Otherwise it just takes up too much time to understand the code and then figure out the issue.

    Thanks,
    Sai

  • Well said, Sai!

    Might it be (even) unfair - borderline selfish - for posters - in their (failed) quest - to burden forum helpers & you (pro staff) w/their "overly complex code desires?" Time spent "untangling mostly unreadable DRM" is (necessarily) TIME LOST for engaging (more cooperative) posters - employing the far clearer/safer API.
  • Thank You both cb1 and sai for ur valuable suggestions ,
    actually I am new to this cortex m4 n i m first time using it, I thought it would be better to do DRM for learning the m/controller deeply n I was referring the datasheet for programming and I am doing it alone. As u said its really taking toooooo much time. I am totally agree with this


    Where can i get the API's for Uart, ADC, ethernet, etc???

  • Good for you - believe that's a wise conclusion.

    Search TivaWare\examples\peripherals - there you'll find a "treasure trove" of API tried/tested, code examples.

    Nothing prevents you from reviewing the various MCU Registers - as deeply and/or as long as you desire - (after) the API enables your code to run successfully. (and w/out "devouring" (needlessly) scarce forum "pro-help" resources.)

    As to your DRM based (claimed), "deep learning:" appears "not" (deep enough) for you to avoid crash/burn/uncertainty.  Sorry - hard to consider your (and multiple other DRM users) impasse as, "Deep Learning!"   (deep disappointment, deep frustration, deep misuse of time/effort ring bit more real...)

  • Yeah.. Got some API's.. Working on it... :)

  • Good for you - that's the spirit.

    I recall, "Single-ended ADC" as among the simplest & most straight-forward to, "get you going." Recall KISS - start (and stay) simple - proceed by refinement - (never) by giant hodge-podge (unnecessary mixture) which proves impossible to troubleshoot...
  • I am following your suggestions.. Soon I will give positive reply.. :)

    And I liked the way you give response...

    thank you cb1