Hi!
I am in need of some help reading the temperature sensor of the CC2540 chip.
I'm using the development kit.
The code I'm currently trying is this (I think I found it in some forum thread or on the wiki):
#define SAMPLE_TEMP_SENSOR(v) \ do { \ ADCCON2 = 0x3E; \ ADCCON1 = 0x73; \ while(!(ADCCON1 & 0x80)); \ v = ADCL; \ v |= (((unsigned int)ADCH) << 8); \ } while(0) #define TEMP_CONST 0.61065 // (1250 / 2047) #define TEMP_OFFSET_DATASHEET 750 #define TEMP_OFFSET_MEASURED_AT_25_DEGREES_CELCIUS 29.75 #define TEMP_OFFSET (TEMP_OFFSET_DATASHEET + TEMP_OFFSET_MEASURED_AT_25_DEGREES_CELCIUS) // 779.75 #define TEMP_COEFF 4.5 float getTemp(void){ unsigned int adcValue; float outputVoltage; SAMPLE_TEMP_SENSOR(adcValue); // Note that the conversion result always resides in MSB section of ADCH:ADCL adcValue >>= 4; // Shift 4 due to 12 bits resolution outputVoltage = adcValue * TEMP_CONST; return ((outputVoltage - TEMP_OFFSET) / TEMP_COEFF); }
I get a constant reading from this, and I am at loss.
I have looked at both the data sheet and the user guide - but I cannot figure this out.
Any help, pointers or code would be very much appreciated!