Jump to content

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 ?








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.

Link to post
Share on other sites

I did nothing but import, build and upload this.



#include <msp430.h>
#include "ishan.h"
#include "ds18x20.h"

float temperature=0;
void main()

   	WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
	//setup DCO to 1MHZ
	//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


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

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.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...