Rei Vilo 695 Posted November 8, 2013 Author Share Posted November 8, 2013 @@RobLewis Just add || defined(__MSP430F5529__) to obtain #if defined(__MSP430G2452__) || defined(__MSP430G2553__) || defined(__MSP430G2231__) || defined(__MSP430F5529__) or even better, replace the whole block by // Core library - MCU-based #include "Energia.h" if you plan to use the library solely on the MSP430 LaunchPads developer_bt 1 Quote Link to post Share on other sites
developer_bt 1 Posted December 3, 2013 Share Posted December 3, 2013 Hello, Why when using a Stellaris / TivaC lanchpad appears oscillation in the value of the humidity? ?o work with Stellaris / TivaC I made the following changes: // Core library - MCU-based #include "Energia.h" while (digitalRead(_pin) == laststate) { counter++; delayMicroseconds(2); //change! if (counter == 255) { break; } } if ((i >= 4) && (i%2 == 0)) { // shove each bit into the storage bytes data[j/8] <<= 1; if (counter > 12) //change! data[j/8] |= 1; j++; } } Code is the following: #include "Energia.h" // Include application, user and local libraries #include "DHT22_430.h" #define DHTPIN PD_0 //Stellaris //#define DHTPIN P1_4 //MSP430 DHT22 mySensor(DHTPIN); boolean flag; void setup() { Serial.begin(9600); Serial.println("\n\n\n*** DHT22 test starts"); Serial.println("PUSH2 to end"); pinMode(PUSH2, INPUT_PULLUP); mySensor.begin(); } void loop() { delay(2000); // for Stellaris a lower value has a greater deviation // Reading temperature or humidity takes about 250 milliseconds! // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor) flag = mySensor.get(); int32_t h = mySensor.humidityX10(); int32_t t = mySensor.temperatureX10(); // check if returns are valid, if they are NaN (not a number) then something went wrong! if (!flag) { Serial.println("Failed to read from DHT"); } else { Serial.print(h); Serial.print(","); Serial.println(t); } if (digitalRead(PUSH2)==LOW) { Serial.println("\n\n*** End"); Serial.end(); while(true); // endless loop } } The deviation is more than 1% and sometimes more . I've tried multiple lanchpad: MSP430 (2530), MSP430 (5529) but the problem appears only with Stellaris and TivaC! Are problem is the library or there are too many noise power from the PC? I do not have an oscilloscope to see what the problem is. I know that this is MSP430 forum but will ask if anyone has time to test the library with Stellaris. The output is as follows. MSP430: 491,222 494,222 496,222 496,222 495,222 494,222 494,222 492,222 491,222 491,222 490,222 490,222 490,222 491,222 490,222 489,222 489,222 489,222 490,222 490,222 490,222 489,222 489,222 489,222 490,222 491,221 492,222 493,221 494,221 494,222 494,221 493,222 493,221 494,222 494,222 493,221 491,221 490,221 490,221 490,221 490,221 489,221 490,221 490,221 491,221 492,221 492,221 492,221 493,221 494,221 495,221 494,221 494,221 493,221 492,220 492,221 492,221 493,221 494,221 495,221 TivaC: 492,221 494,221 495,221 494,221 493,221 506,221 498,221 499,221 499,221 499,221 498,221 511,221 499,221 499,221 498,221 497,221 495,221 504,221 496,221 497,221 497,221 495,221 494,221 503,221 492,221 491,221 492,221 495,221 494,221 505,221 495,221 495,221 497,221 496,221 497,221 508,221 501,221 500,221 502,221 500,221 498,221 506,221 494,221 495,221 494,222 492,221 491,221 501,221 489,221 490,221 493,221 494,221 494,222 503,221 492,221 493,221 493,221 492,222 490,222 501,221 491,221 490,221 490,221 489,221 493,221 502,221 491,221 490,221 489,221 489,221 487,221 499,221 491,221 Thank you in advance Quote Link to post Share on other sites
icserny 9 Posted December 3, 2013 Share Posted December 3, 2013 if (counter > 12) //change! This value of 12 may not be sufficiently large. The best solution is to gather some statistics (see my previous comment in #27). developer_bt 1 Quote Link to post Share on other sites
developer_bt 1 Posted December 3, 2013 Share Posted December 3, 2013 This value of 12 may not be sufficiently large. The best solution is to gather some statistics (see my previous comment in #27). Thank you very much icserny! I tried your method. The results for delayMicroseconds(3); and if (counter > 10) are as follows: 6 6 6 6 6 6 6 17 17 6 17 17 17 6 7 6 6 6 6 6 6 6 6 6 18 17 6 18 18 7 18 6 18 6 6 17 6 7 18 17 40 1, B8, 0, DA, 93 =? 193 RH% 44.0 % oC 21.8 *C 6 7 6 6 6 6 6 17 17 6 18 17 17 6 6 6 6 6 6 6 6 6 6 5 18 18 6 18 18 6 18 6 18 6 6 17 6 6 18 17 40 1, B8, 0, DA, 93 =? 193 RH% 44.0 % oC 21.8 *C 6 6 6 6 6 6 6 17 17 6 17 17 17 6 6 6 6 6 7 6 6 6 6 6 17 17 6 17 17 6 18 6 18 6 6 17 6 6 18 18 40 1, B8, 0, DA, 93 =? 193 RH% 44.0 % oC 21.8 *C 6 7 6 6 6 6 6 17 17 17 6 6 6 17 6 6 6 6 6 6 6 6 6 6 17 18 6 17 17 6 17 6 17 6 6 18 18 18 18 17 40 1, C4, 0, DA, 9F =? 19F RH% 45.2 % oC 21.8 *C 6 7 6 6 6 6 6 17 17 6 18 17 17 6 6 6 6 6 6 6 6 6 6 5 18 18 6 18 18 6 18 6 18 6 6 17 6 6 18 17 40 1, B8, 0, DA, 93 =? 193 RH% 44.0 % oC 21.8 *C 6 6 6 6 6 6 6 17 17 6 17 17 17 6 7 6 6 6 6 6 6 6 6 6 18 17 6 18 18 7 18 6 18 6 6 17 6 7 18 17 40 1, B8, 0, DA, 93 =? 193 RH% 44.0 % oC 21.8 *C For a long time now I have stable readings in comparison with the previous time, but still there are. However using the MSP430 with the following settings has no peak value of humidity. Will someone please try to Stellaris / TivaC. Quote Link to post Share on other sites
icserny 9 Posted December 4, 2013 Share Posted December 4, 2013 I have made a trial by using the TivaC Launchpad card (delayMicroseconds(2); and if (counter > 15) were used). I can confirm that sometimes there are unusual results: 1, 2B, 1, D, 3A =? 3A Humidity: 29.9 % Temperature: 26.9 *C8 7 8 7 8 7 8 227 8 22 7 22 8 22 218 8 8 8 7 8 7 228 7 8 7 22 22 8 217 8 22 22 22 8 22 7401, 2B, 1, D, 3A =? 3AHumidity: 29.9 % Temperature: 26.9 *C8 8 8 8 7 8 7 228 7 22 8 22 7 22 227 8 8 8 8 7 8 218 8 7 8 22 22 7 228 7 22 22 22 7 22 8401, 2B, 1, D, 3A =? 3AHumidity: 29.9 % Temperature: 26.9 *C8 8 7 8 7 8 7 228 7 22 22 8 7 22 228 8 8 7 8 7 8 227 8 7 8 22 22 7 228 22 7 8 7 8 22 7401, 33, 1, D, 42 =? 42Humidity: 30.7 % Temperature: 26.9 *C==============8 8 7 8 7 8 7 228 7 22 8 22 22 7 77 8 7 8 7 8 8 228 7 8 8 22 22 8 227 8 22 22 22 7 22 22401, 2C, 1, D, 3B =? 3BHumidity: 30.0 % Temperature: 26.9 *C8 8 7 8 7 8 7 228 7 22 8 22 22 7 77 8 7 8 7 8 8 228 7 8 8 22 22 8 227 8 22 22 22 7 22 22401, 2C, 1, D, 3B =? 3BHumidity: 30.0 % Temperature: 26.9 *C Quote Link to post Share on other sites
developer_bt 1 Posted December 4, 2013 Share Posted December 4, 2013 I really surprising why it only happens with TivaC / Stellaris Launchpad, while normally works with msp430g2553 and MSP430F5529 launchpad. Do you have any idea what could be the problem? Quote Link to post Share on other sites
icserny 9 Posted December 4, 2013 Share Posted December 4, 2013 UNfortunately I know too little about Tiva microcontrollers. Quote Link to post Share on other sites
developer_bt 1 Posted December 5, 2013 Share Posted December 5, 2013 This library I tested with Arduino, msp430g2553 and MSP430F5529 launchpad and it works great. Most likely the problem is the speed of the CPU, TivaC running on 80Mhz. Do not use specific peripherals, so the problem is likely to program execution speed. How can I reduce the frequency of 16Mhz? Quote Link to post Share on other sites
Rei Vilo 695 Posted December 5, 2013 Author Share Posted December 5, 2013 @@developer_bt Do you have a logic analyser to record the data and investigate the speed? Quote Link to post Share on other sites
developer_bt 1 Posted December 5, 2013 Share Posted December 5, 2013 Hello @@Rei Vilo! I have a logic analyzer, tomorrow or over the weekend will do testing and posting results. To inform you that I managed to knock off frequency of 40Mhz! Now I have a more stable readings, (delayMicroseconds(2); and if (counter > 6) were used). To reduce the frequency more of the following link : http://forum.stellarisiti.com/topic/1582-change-system-clock-stellaris-howto/ Reducing the frequency is as follows: First make a backup of the original files. 1) change board.txt (energia_dir)\hardware\lm4f\boards.txt ###################################################### # Tiva C TM4C1233H6PM 80MHz # with launchpad ###################################################### lpTivaC-1.name=Tiva C w/ TM4C1233H6PM (80MHz) lpTivaC-1.upload.maximum_size=262144 lpTivaC-1.build.mcu=cortex-m4 lpTivaC-1.build.f_cpu=80000000L lpTivaC-1.build.core=lm4f lpTivaC-1.build.variant=stellarpad lpTivaC-1.ldscript=lm4fcpp.ld ###################################################### # Tiva C TM4C1233H6PM 40MHz # with launchpad ###################################################### lpTivaC-2.name=Tiva C w/ TM4C1233H6PM (40MHz) lpTivaC-2.upload.maximum_size=262144 lpTivaC-2.build.mcu=cortex-m4 lpTivaC-2.build.f_cpu=40000000L lpTivaC-2.build.core=lm4f lpTivaC-2.build.variant=stellarpad lpTivaC-2.ldscript=lm4fcpp.ld 2) change wireing.c, (energia_dir)\hardware\lm4f\cores\lm4f\wiring.c /* ************************************************************************ * wiring.c * * Arduino core files for MSP430 * Copyright (c) 2012 Robert Wessels. All right reserved. * * *********************************************************************** Derived from: wiring.c - Partial implementation of the Wiring API for the ATmega8. Part of Arduino - http://www.arduino.cc/ Copyright (c) 2005-2006 David A. Mellis This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "Energia.h" #include "inc/hw_ints.h" #include "inc/hw_timer.h" #include "driverlib/rom.h" #include "driverlib/sysctl.h" #include "driverlib/timer.h" #define TICKS_PER_SECOND 100 #define TICK_PERIOD_MS (1000 / SYSTICKS_PER_SECOND) static unsigned long milliseconds = 0; void timerInit() { // // Run at system clock at 80MHz // #if F_CPU >= 80000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 50000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_4|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 40000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 25000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_8|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 16000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_12_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 8000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_25|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #elif F_CPU >= 4000000 ROM_SysCtlClockSet(SYSCTL_SYSDIV_50|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #else ROM_SysCtlClockSet(SYSCTL_SYSDIV_2_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN); #endif // // SysTick is used for delay() and delayMicroseconds() // //ROM_SysTickPeriodSet(0x00FFFFFF); ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / TICKS_PER_SECOND); ROM_SysTickEnable(); // //Initialize Timer5 to be used as time-tracker since beginning of time // ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER5); //not tied to launchpad pin ROM_TimerConfigure(TIMER5_BASE, TIMER_CFG_PERIODIC_UP); ROM_TimerLoadSet(TIMER5_BASE, TIMER_A, ROM_SysCtlClockGet()/1000); ROM_IntEnable(INT_TIMER5A); ROM_TimerIntEnable(TIMER5_BASE, TIMER_TIMA_TIMEOUT); ROM_TimerEnable(TIMER5_BASE, TIMER_A); ROM_IntMasterEnable(); } unsigned long micros(void) { volatile unsigned int conMz = ROM_SysCtlClockGet()/1000/1000; // return (milliseconds * 1000) + (HWREG(TIMER5_BASE + TIMER_O_TAV) / 80); return (milliseconds * 1000) + (HWREG(TIMER5_BASE + TIMER_O_TAV) / conMz); } unsigned long millis(void) { return milliseconds; } /* Delay for the given number of microseconds. Assumes a 1, 8 or 16 MHz clock. */ void delayMicroseconds(unsigned int us) { volatile unsigned int conMz = ROM_SysCtlClockGet()/1000/1000; volatile unsigned long elapsedTime; unsigned long startTime = HWREG(NVIC_ST_CURRENT); do{ elapsedTime = startTime-(HWREG(NVIC_ST_CURRENT) & 0x00FFFFFF); } // while(elapsedTime <= us*80); while(elapsedTime <= us*conMz ); } void delay(uint32_t milliseconds) { unsigned long i; for(i=0; i<milliseconds; i++){ delayMicroseconds(1000); } } void Timer5IntHandler(void) { ROM_TimerIntClear(TIMER5_BASE, TIMER_TIMA_TIMEOUT); milliseconds++; } Will you please test if this really works, in order to determine whether this is indeed the problem Quote Link to post Share on other sites
developer_bt 1 Posted December 7, 2013 Share Posted December 7, 2013 I found the problem! It is about configuring the system clock which is used to generate delays for functions: delay() and delayMicroseconds(). The change should be made in the core library wiring.c. You can use the change in the previous post but for a 80Mhz may simply make only the following changes: change wireing.c, (energia_dir)\hardware\lm4f\cores\lm4f\wiring.c // //SysTick is used for delay() and delayMicroseconds() // //ROM_SysTickPeriodSet(0x00FFFFFF); ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / 100); ROM_SysTickEnable(); I hope to someone would be of help Automate 1 Quote Link to post Share on other sites
rolfsatake 0 Posted February 25, 2014 Share Posted February 25, 2014 I really dont know what happening now! This example is not working on energy-0101E0011. Quote Link to post Share on other sites
mic 0 Posted May 27, 2014 Share Posted May 27, 2014 Hello Rei Vilo, finally I was able to run my DHT22 on Stellaris Launchpad. But as usual I have some problems. When I'm uploading ported version of Your code DHT22_430_main, I receive: *** DHT22 test starts PUSH2 to end debug bits received 40 debug 2, 19, 1, 10, 2C =? 2C debug checksum ok debug RH% 537 debug oC 272 RH% 53.7 % oC 27.2 *C debug bits received 40 debug 2, 29, 1, F, 3B =? 3B debug checksum ok debug RH% 553 debug oC 271 RH% 55.3 % oC 27.1 *C debug bits received 40 debug 2, 29, 1, F, 3B =? 3B debug checksum ok debug RH% 553 debug oC 271 RH% 55.3 % oC 27.1 *C but when I'm trying to include and run with DHT22 code - LCD_5110.h / LCD_5110.cpp etc. also made by You, on serial port I receive strange characters. For example: ? a Y [ ] ] ] LCD_5110 is working fine - I got everything on the screen what I want. For DHT22 I use same as for DHT11 4,8kOhm resistor between pin 1 and pin 2. Serial is set up: Serial.begin(9600) Energia:0101E0012 Do You know maybe how to fix problem with joining both libraries ? Thanks Quote Link to post Share on other sites
Rei Vilo 695 Posted May 28, 2014 Author Share Posted May 28, 2014 I haven't played with the DHT22 sensor for a while now. The library was aimed at the MSP430G2 MCU, so I suspect a timing-related issue, as the TM4C runs at 80 MHz instead of 16 MHz for the MSP430G2. Quote Link to post Share on other sites
mic 0 Posted May 28, 2014 Share Posted May 28, 2014 Ok, Thanks. I will try to find something related to clock in LCD_5110 library (maybe SPI.setClockDivider(...) or similar ). Yesterday I focused on that the DHT22 library when is compiled alone is working properly and with LCD is not. I tested the Serial.print, Serial.println and Serial.write, when only LCD_5110 library was included. Each time there were improper chars send (on any baud rate). So I believe that should be something with the 5110 lib. /// This was a problem with code for LCD_5110 (not library but code in .ino file) when I'll rewrite and got this fully operational I'll upload it on the forum. 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.