Jump to content
Sign in to follow this  
OppaErich

CCSv6 DS18B20 - return value gets lost

Recommended Posts

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 ?

 

 

 

post-973-0-84566100-1401364598_thumb.png

post-973-0-69970900-1401364614_thumb.png

post-973-0-24988100-1401364631_thumb.png

post-973-0-64269000-1401364643_thumb.png

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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_*/

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

post-973-0-65976500-1401537825_thumb.png

post-973-0-41796000-1401537836_thumb.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×