Christian Taedcke
/
lpc1549_temperature
This example shows how to print the temperature from the LPC1549 temperature sensor.
Revision 0:39468e6d5d62, committed 2014-06-22
- Comitter:
- chrta
- Date:
- Sun Jun 22 09:51:10 2014 +0000
- Commit message:
- Initial commit.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Jun 22 09:51:10 2014 +0000 @@ -0,0 +1,32 @@ +#include "mbed.h" + +DigitalOut myled(LED1); +Serial pc(USBTX, USBRX); // tx, rx +AnalogIn ain(A0); //is ADC0_0: must be channel 0 of ADC0 or ADC1 + +#define ADCn_INSEL_TEMPERATURE (0x3) +#define SYSCON_PDRUNCFG_TS_PD (1 << 18) +#define SYSCON_PDRUNCFG_IREF_PD (1 << 17) + +int main() { + pc.printf("Starting program...\r\n"); + + //Enable temperature sensor and internal voltage reference, see um chapter 31 + LPC_SYSCON->PDRUNCFG &= ~(SYSCON_PDRUNCFG_TS_PD | SYSCON_PDRUNCFG_IREF_PD); + + //Select source for channel 0: temperature sensor + LPC_ADC0->INSEL = ADCn_INSEL_TEMPERATURE; + + while(1) { + unsigned short raw = ain.read_u16(); + pc.printf("Raw u16 value %u\r\n", raw); + pc.printf("Raw 12 Bit value %u\r\n", (raw >> 4)); + float value = ((float)raw) / (float) 0xffff; + pc.printf("Float value %f\r\n", value); + pc.printf("Read value %f mV\r\n", value * 3300.0f); + float temperature = -(((value * 3300.0f) - 577.3f) / 2.29f); + pc.printf("Read temperature (about) %f deg C\r\n", temperature); + myled = !myled; + wait(1); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sun Jun 22 09:51:10 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721 \ No newline at end of file