Bernard 7 Posted December 21, 2012 Share Posted December 21, 2012 Hello, Here is a ino file that allow to display temperature from LM4F120 internal sensor. It is based on example from TI workbook , ported a la mode Energia. Nothing spectacular. I am slowly learning ARM and I wanted to share. /* Read internal temperature sensor of LM4F120 Stellaris Launchpad Example from TI LM4F120 workbook A la mode Energia */ #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/debug.h" #include "driverlib/sysctl.h" #include "driverlib/adc.h" #include "Energia.h" unsigned long ulADC0Value[4]; volatile unsigned long ulTempAvg; volatile unsigned long ulTempValueC; volatile unsigned long ulTempValueF; void setup() { Serial.begin(9600); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS); // 250 ADCSequenceDisable(ADC0_BASE, 1); 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); } void loop() { ADCIntClear(ADC0_BASE, 1); ADCProcessorTrigger(ADC0_BASE, 1); while(!ADCIntStatus(ADC0_BASE, 1, false)) { } ADCSequenceDataGet(ADC0_BASE, 1, ulADC0Value); ulTempAvg = (ulADC0Value[0] + ulADC0Value[1] + ulADC0Value[2] + ulADC0Value[3] + 2)/4; ulTempValueC = (1475 - ((2475 * ulTempAvg)) / 4096)/10; ulTempValueF = ((ulTempValueC * 9) + 160) / 5; Serial.println(ulTempValueC); delay(300); } Salutations. Bernard energia, sirri, Rickta59 and 3 others 6 Quote Link to post Share on other sites
energia 485 Posted December 22, 2012 Share Posted December 22, 2012 Thanks for sharing. This is a great example of how to use the Stellarisware drive lib in Energia! Quote Link to post Share on other sites
sirri 28 Posted September 21, 2013 Share Posted September 21, 2013 it is working on the first try.. thanks a lot.. i have a stellaris launchpad as well now and i want to explore its abilites (especially pros against msp430's) .. now i will test it on raspberry pi, writing a simple python code.. yay^_^ Quote Link to post Share on other sites
phaseform 3 Posted February 1, 2014 Share Posted February 1, 2014 I'm not having any luck getting this to compile for my lm4f120. Are there libraries that need to be added, if so where can I find them?! "Energia.h" was used as an example library?!thanks! Quote Link to post Share on other sites
energia 485 Posted February 1, 2014 Share Posted February 1, 2014 If you are using Energia 11 and get something like the below then move #include "Energia.h" to the top as the first include. The reason is that the new driverlib depends on stdint.h and stdbool.h. Energia.h includes these. As an alternative, you can also include stdbool.h and stdint.h before any of the drivelib includes. In file included from sketch_feb01a.ino:10:0: /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/debug.h:49:41: error: 'uint32_t' has not been declared In file included from sketch_feb01a.ino:11:0: /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/sysctl.h:614:8: error: 'uint32_t' does not name a type /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/sysctl.h:615:8: error: 'uint32_t' does not name a type /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/sysctl.h:616:8: error: 'uint32_t' does not name a type /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/sysctl.h:617:37: warning: 'SysCtlPeripheralPresent' initialized and declared 'extern' [enabled by default] /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/sysctl.h:617:37: error: 'uint32_t' was not declared in this scope /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/sysctl.h:618:35: warning: 'SysCtlPeripheralReady' initialized and declared 'extern' [enabled by default] /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/sysctl.h:618:35: error: 'uint32_t' was not declared in this scope /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/sysctl.h:619:37: error: variable or field 'SysCtlPeripheralPowerOn' declared void /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/sysctl.h:619:37: error: 'uint32_t' was not declared in this scope /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/sysctl.h:620:38: error: variable or field 'SysCtlPeripheralPowerOff' declared void /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/sysctl.h:620:38: error: 'uint32_t' was not declared in this scope /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/sysctl.h:621:35: error: variable or field 'SysCtlPeripheralReset' declared void /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/sysctl.h:621:35: error: 'uint32_t' was not declared in this scope /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/sysctl.h:622:36: error: variable or field 'SysCtlPeripheralEnable' declared void /Applications/Energia.app/Contents/Resources/Java/hardware/lm4f/cores/lm4f/driverlib/sysctl.h:622:36: error: 'uint32_t' was not declared in this scope ........ sketch_feb01a.ino: In function 'void setup()': sketch_feb01a.ino:24:44: error: 'SysCtlPeripheralEnable' was not declared in this scope sketch_feb01a.ino:25:44: error: 'SysCtlADCSpeedSet' was not declared in this scope sketch_feb01a.ino:26:34: error: 'ADCSequenceDisable' was not declared in this scope sketch_feb01a.ino:27:62: error: 'ADCSequenceConfigure' was not declared in this scope sketch_feb01a.ino:28:55: error: 'ADCSequenceStepConfigure' was not declared in this scope sketch_feb01a.ino:32:33: error: 'ADCSequenceEnable' was not declared in this scope sketch_feb01a.ino: In function 'void loop()': sketch_feb01a.ino:36:27: error: 'ADCIntClear' was not declared in this scope sketch_feb01a.ino:37:35: error: 'ADCProcessorTrigger' was not declared in this scope sketch_feb01a.ino:39:42: error: 'ADCIntStatus' was not declared in this scope sketch_feb01a.ino:43:47: error: 'ADCSequenceDataGet' was not declared in this scope Quote Link to post Share on other sites
sexton 0 Posted February 3, 2014 Share Posted February 3, 2014 The code below works in Energia 10,compiles in 11 but does nothing.Can anyone tell why? /* Read internal temperature sensor of LM4F120 Stellaris Launchpad Example from TI LM4F120 workbook A la mode Energia */ #include "Energia.h" #include "inc/hw_memmap.h" #include "inc/hw_types.h" #include "driverlib/debug.h" #include "driverlib/sysctl.h" #include "driverlib/adc.h" unsigned long ulADC0Value[4]; volatile unsigned long ulTempAvg; volatile unsigned long ulTempValueC; volatile unsigned long ulTempValueF; volatile unsigned long tt; volatile unsigned long tc; void setup() { Serial.begin(9600); pinMode(RED_LED, OUTPUT); pinMode(GREEN_LED, OUTPUT); pinMode(BLUE_LED, OUTPUT); SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0); SysCtlADCSpeedSet(SYSCTL_ADCSPEED_125KSPS); // 250 ADCSequenceDisable(ADC0_BASE, 1); 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); } void loop() { ADCIntClear(ADC0_BASE, 1); ADCProcessorTrigger(ADC0_BASE, 1); while(!ADCIntStatus(ADC0_BASE, 1, false)) { } ADCSequenceDataGet(ADC0_BASE, 1, ulADC0Value); ulTempAvg = (ulADC0Value[0] + ulADC0Value[1] + ulADC0Value[2] + ulADC0Value[3] + 2)/4; ulTempValueC = (1475 - ((2475 * ulTempAvg)) / 4096); ulTempValueF = ((ulTempValueC * 9) + 160) / 5; Serial.println(ulTempValueC); for (int tc =1;tc <=ulTempValueC/100;tc ++) dot(); tt=ulTempValueC%100; for (int ttt =1;ttt <=abs(tt/10);ttt ++) gdot(); for (int tc =1;tc <=ulTempValueC%10;tc ++) bdot(); delay(3000); } void dot() { digitalWrite(RED_LED, HIGH); delay(250); digitalWrite(RED_LED, LOW); delay(250); } void gdot() { digitalWrite(GREEN_LED, HIGH); delay(250); digitalWrite(GREEN_LED, LOW); delay(250); } void bdot() { digitalWrite(BLUE_LED, HIGH); delay(250); digitalWrite(BLUE_LED, LOW); delay(250); } Quote Link to post Share on other sites
energia 485 Posted February 5, 2014 Share Posted February 5, 2014 Odd, this should work as it worked on Energia 10. It seems to hang after ADCSequenceDisable(ADC0_BASE, 0); I will have to look into this with a debugger. sexton 1 Quote Link to post Share on other sites
yezo 1 Posted April 14, 2014 Share Posted April 14, 2014 I added this: SYSCTL_RCGC0_R |= SYSCTL_RCGC0_ADC0; ROM_ADCHardwareOversampleConfigure(ADC0_BASE, 64); Before the ADCSequenceDisable line and it works ok. sexton 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.