41 lines
No EOL
850 B
Text
41 lines
No EOL
850 B
Text
//read the temperature of the integrated sensor on the Arduino DUE
|
|
|
|
float trans = 3.3/4096;
|
|
float offset = 0.8;
|
|
float factor = 0.00256;
|
|
int fixtemp = 27;
|
|
|
|
void setup() {
|
|
Serial.begin(9600);
|
|
}
|
|
|
|
void loop() {
|
|
float treal = fixtemp + (( trans * temperatur() ) - offset ) / factor;
|
|
Serial.println(treal);
|
|
delay(10);
|
|
}
|
|
|
|
uint32_t temperatur() {
|
|
uint32_t ulValue = 0;
|
|
uint32_t ulChannel;
|
|
|
|
// Enable the corresponding channel
|
|
adc_enable_channel(ADC, ADC_TEMPERATURE_SENSOR);
|
|
|
|
// Enable the temperature sensor
|
|
adc_enable_ts(ADC);
|
|
|
|
// Start the ADC
|
|
adc_start(ADC);
|
|
|
|
// Wait for end of conversion
|
|
while ((adc_get_status(ADC) & ADC_ISR_DRDY) != ADC_ISR_DRDY);
|
|
|
|
// Read the value
|
|
ulValue = adc_get_latest_value(ADC);
|
|
|
|
// Disable the corresponding channel
|
|
adc_disable_channel(ADC, ADC_TEMPERATURE_SENSOR);
|
|
|
|
return ulValue;
|
|
} |