OppaErich 25 Posted May 29, 2014 Share Posted May 29, 2014 I found a DS18B20 example project in MSP430Ware. I've imported that into CCS and tried the GNU compiler. That threw a ton of errors and did not compile. I've opted for the TI compiler and it did compile. When I debug this I can see that the conversion and data transfer seem to work. Somehow the return value to main gets messed. What is going here ? Quote Link to post Share on other sites
tripwire 139 Posted May 29, 2014 Share Posted May 29, 2014 Have you made a declaration (aka prototype) of the GetData function in any of the header files included before your main function? If not, and you're compiling as C rather than C++ you'll run into this: "If the expression that precedes the parenthesized argument list in a function call consists solely of an identifier, and if no declaration is visible for this identifier, the identifier is implicitly declared exactly as if, in the innermost block containing the function call, the declaration extern int identifier(); appeared." (ANSI C standard) In that case, as far as main is concerned the GetData function returns an int rather than a float. Quote Link to post Share on other sites
OppaErich 25 Posted May 29, 2014 Author Share Posted May 29, 2014 I did nothing but import, build and upload this. main.c #include <msp430.h> #include "ishan.h" #include "ds18x20.h" float temperature=0; void main() { WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer //setup DCO to 1MHZ BCSCTL1 = CALBC1_16MHZ; DCOCTL = CALDCO_16MHZ; //General GPIO Defines LED_DIR |= (LED_0 + LED_1); // Set P1.0 and P1.6 to output direction LED_OUT &= ~(LED_0 + LED_1); // Set the LEDs off InitDS18B20(); for(; { temperature=GetData(); delay_ms(100); } } ds18x20.h #ifndef DS18X20_H_ #define DS18X20_H_ #define DS1820_OUT P2OUT #define DS1820_DIR P2DIR #define DS1820_SEL P2SEL #define DS1820_IN P2IN #define DS1820_DATA_IN_PIN BIT4 #define DS1820_VCC BIT3 #define DS1820_GND BIT1 #define DS1820_SKIP_ROM 0xCC #define DS1820_READ_SCRATCHPAD 0xBE #define DS1820_CONVERT_T 0x44 void InitDS18B20(void); unsigned int ResetDS1820 ( void ); void DS1820_HI(void); void DS1820_LO(void); void WriteZero(void); void WriteOne(void); unsigned int ReadBit(void); void WriteDS1820 (unsigned char,int ); unsigned int ReadDS1820 ( void ); float GetData(void); // <- there it is #endif /*DS18X20_H_*/ Quote Link to post Share on other sites
tripwire 139 Posted May 29, 2014 Share Posted May 29, 2014 float GetData(void); // <- there it is Oh well, it was worth a shot It's probably a good idea to get the disassembly of the main and GetData functions. Hopefully that will reveal where things are going awry. Quote Link to post Share on other sites
OppaErich 25 Posted May 29, 2014 Author Share Posted May 29, 2014 Yeah, thank you. There's two things I noticed: temperature - Address 0x0000 is that right ? I added a watch temp*0.0625 that was shown as double I've tried casting this to float but nope. Trying to use double instead of float made the compiler complain about a missing hardware multiplier. Quote Link to post Share on other sites
enl 227 Posted May 29, 2014 Share Posted May 29, 2014 Make temperature a volitile. It may be getting optimized out as it is never used tripwire 1 Quote Link to post Share on other sites
OppaErich 25 Posted May 31, 2014 Author Share Posted May 31, 2014 temperature - Address 0x0000 is that right ? That was the problem. temperature was declared AND initialized before main(). I've set it to 0.0 inside of main() and now it resides at 0x0200 and shows sane values. tripwire 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.