-ADC and TMP36 Example
+Watchdog Example
-Copyright 2013 Nathael Pajani <nathael.pajani@ed3l.fr>
+Copyright 2015 Nathael Pajani <nathael.pajani@ed3l.fr>
/* ****************************************************************************
*
*************************************************************************** */
-This example shows the support of the internal ADC, with conversion examples for
-a TMP36 analog temperature sensor and a CdS photoresistor.
+This example shows the support of the watchdog.
-The conversion results are sent on the UART0 serial line (115200 8n1) at
-regular intervals, and the status led flashes the rest of the time.
+When starting the app displays two line son UART0 :
-The output looks like this :
- ADC(0): 684 (raw: 0x02ac)
- TMP36: 29,36 (orig: 248, raw: 00f8)
+System started
+Watchdog started
+
+Once started the demo board plays the "chenillard" on the status led at 100ms
+speed.
+If you press the ISP button, then the chenillard play quicker (10ms), but if
+you hold it for too long, then the board gets reseted by the watchdog and
+displays again the startup messages on UART0.
+
+Try to hold the ISP button just long enough to see the "Watchdog intr !"
+message !
-The first line displays the decimal and hexadecimal value of the raw
-conversion result, on which was the luminosity sensor.
-The second line displays the TMP36 temperature, which is not very acurate at
-ambient temperature, with the corresponding decimal and hexadecimal raw
-conversion values.
/* UART 0 */
{ LPC_UART0_RX_PIO_0_1, LPC_IO_DIGITAL },
{ LPC_UART0_TX_PIO_0_2, LPC_IO_DIGITAL },
- { LPC_UART1_RX_PIO_0_8, LPC_IO_DIGITAL },
- { LPC_UART1_TX_PIO_0_9, LPC_IO_DIGITAL },
- ARRAY_LAST_PIO,
-};
-
-const struct pio_config adc_pins[] = {
- { LPC_ADC_AD0_PIO_0_30, LPC_IO_ANALOG },
- { LPC_ADC_AD1_PIO_0_31, LPC_IO_ANALOG },
- { LPC_ADC_AD2_PIO_1_0, LPC_IO_ANALOG },
- { LPC_ADC_AD3_PIO_1_1, LPC_IO_ANALOG },
- { LPC_ADC_AD4_PIO_1_2, LPC_IO_ANALOG },
- { LPC_ADC_AD5_PIO_1_3, LPC_IO_ANALOG },
+ /* ISP button */
+ { LPC_GPIO_0_12, LPC_IO_DIGITAL },
ARRAY_LAST_PIO,
};
const struct pio status_led_green = LPC_GPIO_1_4;
const struct pio status_led_red = LPC_GPIO_1_5;
+const struct pio button = LPC_GPIO_0_12; /* ISP button */
static volatile int got_wdt_int = 0;
void tmp_callback(void)
.intr_mode_only = 0,
.callback = tmp_callback,
.locks = 0,
- .nb_clk = 0x4FFFFF,
+ .nb_clk = 0x4FFFFFF,
.wdt_window = 0,
.wdt_warn = 0x3FF,
};
-/***************************************************************************** */
-/* This will display the integer value read on the ADC, between 0 and 1024.
- * ADC must be initialised prior to calls to adc_display() (it means that adc_on(NULL)
- * must be called before using this function.
- * adc_num is an ADC channel number (integer between 0 and 7)
- * use LPC_ADC(x) for channel selection.
- * returns ADC convertion value or negative value on error.
- */
-int adc_display(int adc_num, int uart_num)
-{
- uint16_t val = 0;
- int ret = 0;
-
- adc_start_convertion_once(adc_num, LPC_ADC_SEQ(0), 0);
- msleep(10);
- ret = adc_get_value(&val, adc_num);
- if (ret < 0) {
- return ret;
- } else {
- uprintf(uart_num, "ADC(%d): %d (raw: 0x%04x)\r\n", adc_num, val, val);
- }
- return val;
-}
-
/***************************************************************************** */
void system_init()
{
/* Stop the watchdog */
startup_watchdog_disable(); /* Do it right now, before it gets a chance to break in */
+ system_brown_out_detection_config(0); /* No ADC used */
system_set_default_power_state();
clock_config(SELECTED_FREQ);
set_pins(common_pins);
- set_pins(adc_pins);
gpio_on();
status_led_config(&status_led_green, &status_led_red);
/* System tick timer MUST be configured and running in order to use the sleeping functions */
}
-
/***************************************************************************** */
int main(void)
{
+ uint32_t button_val = 0;
system_init();
uart_on(UART0, 115200, NULL);
- uart_on(UART1, 115200, NULL);
- adc_on(NULL);
- uprintf(UART1, "System started\n");
+ config_gpio(&button, 0, GPIO_DIR_IN, 0);
+
uprintf(UART0, "System started\n");
msleep(5);
watchdog_config(&wdconf);
uprintf(UART0, "Watchdog started\n");
- uprintf(UART1, "Watchdog started\n");
while (1) {
watchdog_feed();
- chenillard(50);
- /* ADC Test */
- adc_display(LPC_ADC(0), 0);
- adc_display(LPC_ADC(0), 1);
+
+ do {
+ chenillard(10);
+ button_val = gpio_read(button);
+ } while (button_val == 0);
+
if (got_wdt_int != 0) {
- uprintf(UART1, "Watchdog intr !\n");
+ uprintf(UART0, "Watchdog intr !\n");
watchdog_feed();
got_wdt_int = 0;
}
+ msleep(100);
}
return 0;
}