These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frank26080115 0:bf7b9fba3924 1 /***********************************************************************//**
frank26080115 0:bf7b9fba3924 2 * @file adc_interrupt_test.c
frank26080115 0:bf7b9fba3924 3 * @purpose This example describes how to use ADC conversion in
frank26080115 0:bf7b9fba3924 4 * interrupt mode
frank26080115 0:bf7b9fba3924 5 * @version 2.0
frank26080115 0:bf7b9fba3924 6 * @date 21. May. 2010
frank26080115 0:bf7b9fba3924 7 * @author NXP MCU SW Application Team
frank26080115 0:bf7b9fba3924 8 *---------------------------------------------------------------------
frank26080115 0:bf7b9fba3924 9 * Software that is described herein is for illustrative purposes only
frank26080115 0:bf7b9fba3924 10 * which provides customers with programming information regarding the
frank26080115 0:bf7b9fba3924 11 * products. This software is supplied "AS IS" without any warranties.
frank26080115 0:bf7b9fba3924 12 * NXP Semiconductors assumes no responsibility or liability for the
frank26080115 0:bf7b9fba3924 13 * use of the software, conveys no license or title under any patent,
frank26080115 0:bf7b9fba3924 14 * copyright, or mask work right to the product. NXP Semiconductors
frank26080115 0:bf7b9fba3924 15 * reserves the right to make changes in the software without
frank26080115 0:bf7b9fba3924 16 * notification. NXP Semiconductors also make no representation or
frank26080115 0:bf7b9fba3924 17 * warranty that such application will be suitable for the specified
frank26080115 0:bf7b9fba3924 18 * use without further testing or modification.
frank26080115 0:bf7b9fba3924 19 **********************************************************************/
frank26080115 0:bf7b9fba3924 20 #include "lpc17xx_adc.h"
frank26080115 0:bf7b9fba3924 21 #include "lpc17xx_libcfg.h"
frank26080115 0:bf7b9fba3924 22 #include "lpc17xx_pinsel.h"
frank26080115 0:bf7b9fba3924 23 #include "debug_frmwrk.h"
frank26080115 0:bf7b9fba3924 24
frank26080115 0:bf7b9fba3924 25 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 26 /** @defgroup ADC_INTERRUPT INTERRUPT
frank26080115 0:bf7b9fba3924 27 * @ingroup ADC_Examples
frank26080115 0:bf7b9fba3924 28 * @{
frank26080115 0:bf7b9fba3924 29 */
frank26080115 0:bf7b9fba3924 30
frank26080115 0:bf7b9fba3924 31 /************************** PRIVATE DEFINITIONS ***********************/
frank26080115 0:bf7b9fba3924 32 #define MCB_LPC_1768
frank26080115 0:bf7b9fba3924 33 //#define IAR_LPC_1768
frank26080115 0:bf7b9fba3924 34
frank26080115 0:bf7b9fba3924 35 #ifdef MCB_LPC_1768
frank26080115 0:bf7b9fba3924 36 #define _ADC_INT ADC_ADINTEN2
frank26080115 0:bf7b9fba3924 37 #define _ADC_CHANNEL ADC_CHANNEL_2
frank26080115 0:bf7b9fba3924 38 #elif defined(IAR_LPC_1768)
frank26080115 0:bf7b9fba3924 39 #define _ADC_INT ADC_ADINTEN5
frank26080115 0:bf7b9fba3924 40 #define _ADC_CHANNEL ADC_CHANNEL_5
frank26080115 0:bf7b9fba3924 41 #endif
frank26080115 0:bf7b9fba3924 42
frank26080115 0:bf7b9fba3924 43 /************************** PRIVATE VARIABLES *************************/
frank26080115 0:bf7b9fba3924 44 uint8_t menu1[] =
frank26080115 0:bf7b9fba3924 45 "********************************************************************************\n\r"
frank26080115 0:bf7b9fba3924 46 "Hello NXP Semiconductors \n\r"
frank26080115 0:bf7b9fba3924 47 " ADC demo \n\r"
frank26080115 0:bf7b9fba3924 48 "\t - MCU: LPC17xx \n\r"
frank26080115 0:bf7b9fba3924 49 "\t - Core: ARM CORTEX-M3 \n\r"
frank26080115 0:bf7b9fba3924 50 "\t - Communicate via: UART0 - 115200 bps \n\r"
frank26080115 0:bf7b9fba3924 51 " Use ADC with 12-bit resolution rate of 200KHz, read in interrupt mode\n\r"
frank26080115 0:bf7b9fba3924 52 " To get ADC channel value and display via UART0\n\r"
frank26080115 0:bf7b9fba3924 53 " Turn the potentiometer to see how ADC value changes\n\r"
frank26080115 0:bf7b9fba3924 54 "********************************************************************************\n\r";
frank26080115 0:bf7b9fba3924 55
frank26080115 0:bf7b9fba3924 56 uint32_t adc_value;
frank26080115 0:bf7b9fba3924 57
frank26080115 0:bf7b9fba3924 58 /************************** PRIVATE FUNCTION *************************/
frank26080115 0:bf7b9fba3924 59 void ADC_IRQHandler(void);
frank26080115 0:bf7b9fba3924 60
frank26080115 0:bf7b9fba3924 61 void print_menu(void);
frank26080115 0:bf7b9fba3924 62
frank26080115 0:bf7b9fba3924 63 /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
frank26080115 0:bf7b9fba3924 64 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 65 * @brief ADC interrupt handler sub-routine
frank26080115 0:bf7b9fba3924 66 * @param[in] None
frank26080115 0:bf7b9fba3924 67 * @return None
frank26080115 0:bf7b9fba3924 68 **********************************************************************/
frank26080115 0:bf7b9fba3924 69 void ADC_IRQHandler(void)
frank26080115 0:bf7b9fba3924 70 {
frank26080115 0:bf7b9fba3924 71 adc_value = 0;
frank26080115 0:bf7b9fba3924 72 #ifdef MCB_LPC_1768
frank26080115 0:bf7b9fba3924 73 if (ADC_ChannelGetStatus(LPC_ADC,ADC_CHANNEL_2,ADC_DATA_DONE))
frank26080115 0:bf7b9fba3924 74 {
frank26080115 0:bf7b9fba3924 75 adc_value = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_2);
frank26080115 0:bf7b9fba3924 76 NVIC_DisableIRQ(ADC_IRQn);
frank26080115 0:bf7b9fba3924 77 }
frank26080115 0:bf7b9fba3924 78 #elif defined(IAR_LPC_1768)
frank26080115 0:bf7b9fba3924 79 if (ADC_ChannelGetStatus(LPC_ADC,ADC_CHANNEL_5,ADC_DATA_DONE))
frank26080115 0:bf7b9fba3924 80 {
frank26080115 0:bf7b9fba3924 81 adc_value = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_5);
frank26080115 0:bf7b9fba3924 82 NVIC_DisableIRQ(ADC_IRQn);
frank26080115 0:bf7b9fba3924 83 }
frank26080115 0:bf7b9fba3924 84 #endif
frank26080115 0:bf7b9fba3924 85 }
frank26080115 0:bf7b9fba3924 86
frank26080115 0:bf7b9fba3924 87 /*-------------------------PRIVATE FUNCTIONS------------------------------*/
frank26080115 0:bf7b9fba3924 88 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 89 * @brief Print menu
frank26080115 0:bf7b9fba3924 90 * @param[in] None
frank26080115 0:bf7b9fba3924 91 * @return None
frank26080115 0:bf7b9fba3924 92 **********************************************************************/
frank26080115 0:bf7b9fba3924 93 void print_menu(void)
frank26080115 0:bf7b9fba3924 94 {
frank26080115 0:bf7b9fba3924 95 _DBG(menu1);
frank26080115 0:bf7b9fba3924 96 }
frank26080115 0:bf7b9fba3924 97
frank26080115 0:bf7b9fba3924 98
frank26080115 0:bf7b9fba3924 99 /*-------------------------MAIN FUNCTION------------------------------*/
frank26080115 0:bf7b9fba3924 100 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 101 * @brief c_entry: Main ADC program body
frank26080115 0:bf7b9fba3924 102 * @param[in] None
frank26080115 0:bf7b9fba3924 103 * @return int
frank26080115 0:bf7b9fba3924 104 **********************************************************************/
frank26080115 0:bf7b9fba3924 105 int c_entry(void)
frank26080115 0:bf7b9fba3924 106 {
frank26080115 0:bf7b9fba3924 107 PINSEL_CFG_Type PinCfg;
frank26080115 0:bf7b9fba3924 108 uint32_t tmp;
frank26080115 0:bf7b9fba3924 109
frank26080115 0:bf7b9fba3924 110 /* Initialize debug via UART0
frank26080115 0:bf7b9fba3924 111 * – 115200bps
frank26080115 0:bf7b9fba3924 112 * – 8 data bit
frank26080115 0:bf7b9fba3924 113 * – No parity
frank26080115 0:bf7b9fba3924 114 * – 1 stop bit
frank26080115 0:bf7b9fba3924 115 * – No flow control
frank26080115 0:bf7b9fba3924 116 */
frank26080115 0:bf7b9fba3924 117 debug_frmwrk_init();
frank26080115 0:bf7b9fba3924 118
frank26080115 0:bf7b9fba3924 119 // print welcome screen
frank26080115 0:bf7b9fba3924 120 print_menu();
frank26080115 0:bf7b9fba3924 121
frank26080115 0:bf7b9fba3924 122 /* Because the potentiometer on different boards (MCB & IAR) connect
frank26080115 0:bf7b9fba3924 123 * with different ADC channel, so we have to configure correct ADC channel
frank26080115 0:bf7b9fba3924 124 * on each board respectively.
frank26080115 0:bf7b9fba3924 125 * If you want to check other ADC channels, you have to wire this ADC pin directly
frank26080115 0:bf7b9fba3924 126 * to potentiometer pin (please see schematic doc for more reference)
frank26080115 0:bf7b9fba3924 127 */
frank26080115 0:bf7b9fba3924 128 #ifdef MCB_LPC_1768
frank26080115 0:bf7b9fba3924 129 /*
frank26080115 0:bf7b9fba3924 130 * Init ADC pin connect
frank26080115 0:bf7b9fba3924 131 * AD0.2 on P0.25
frank26080115 0:bf7b9fba3924 132 */
frank26080115 0:bf7b9fba3924 133 PinCfg.Funcnum = 1;
frank26080115 0:bf7b9fba3924 134 PinCfg.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 135 PinCfg.Pinmode = 0;
frank26080115 0:bf7b9fba3924 136 PinCfg.Pinnum = 25;
frank26080115 0:bf7b9fba3924 137 PinCfg.Portnum = 0;
frank26080115 0:bf7b9fba3924 138 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 139 #elif defined (IAR_LPC_1768)
frank26080115 0:bf7b9fba3924 140 /* select P1.31 as AD0.5 */
frank26080115 0:bf7b9fba3924 141 PinCfg.Funcnum = 3;
frank26080115 0:bf7b9fba3924 142 PinCfg.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 143 PinCfg.Pinmode = 0;
frank26080115 0:bf7b9fba3924 144 PinCfg.Pinnum = 31;
frank26080115 0:bf7b9fba3924 145 PinCfg.Portnum = 1;
frank26080115 0:bf7b9fba3924 146 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 147 #endif
frank26080115 0:bf7b9fba3924 148
frank26080115 0:bf7b9fba3924 149
frank26080115 0:bf7b9fba3924 150 /* Configuration for ADC:
frank26080115 0:bf7b9fba3924 151 * select: ADC channel 2 (if using MCB1700 board)
frank26080115 0:bf7b9fba3924 152 * ADC channel 5 (if using IAR-LPC1768 board)
frank26080115 0:bf7b9fba3924 153 * ADC conversion rate = 200KHz
frank26080115 0:bf7b9fba3924 154 */
frank26080115 0:bf7b9fba3924 155 ADC_Init(LPC_ADC, 200000);
frank26080115 0:bf7b9fba3924 156 ADC_IntConfig(LPC_ADC,_ADC_INT,ENABLE);
frank26080115 0:bf7b9fba3924 157 ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL,ENABLE);
frank26080115 0:bf7b9fba3924 158
frank26080115 0:bf7b9fba3924 159 /* preemption = 1, sub-priority = 1 */
frank26080115 0:bf7b9fba3924 160 NVIC_SetPriority(ADC_IRQn, ((0x01<<3)|0x01));
frank26080115 0:bf7b9fba3924 161
frank26080115 0:bf7b9fba3924 162 while(1)
frank26080115 0:bf7b9fba3924 163 {
frank26080115 0:bf7b9fba3924 164 // Start conversion
frank26080115 0:bf7b9fba3924 165 ADC_StartCmd(LPC_ADC,ADC_START_NOW);
frank26080115 0:bf7b9fba3924 166
frank26080115 0:bf7b9fba3924 167 /* Enable ADC in NVIC */
frank26080115 0:bf7b9fba3924 168 NVIC_EnableIRQ(ADC_IRQn);
frank26080115 0:bf7b9fba3924 169
frank26080115 0:bf7b9fba3924 170 //Display the result of conversion on the UART0
frank26080115 0:bf7b9fba3924 171 #ifdef MCB_LPC_1768
frank26080115 0:bf7b9fba3924 172 _DBG("ADC value on channel 2: ");
frank26080115 0:bf7b9fba3924 173 #elif defined (IAR_LPC_1768)
frank26080115 0:bf7b9fba3924 174 _DBG("ADC value on channel 5: ");
frank26080115 0:bf7b9fba3924 175 #endif
frank26080115 0:bf7b9fba3924 176 _DBD32(adc_value);
frank26080115 0:bf7b9fba3924 177 _DBG_("");
frank26080115 0:bf7b9fba3924 178 for(tmp = 0; tmp < 1000000; tmp++);
frank26080115 0:bf7b9fba3924 179 }
frank26080115 0:bf7b9fba3924 180 ADC_DeInit(LPC_ADC);
frank26080115 0:bf7b9fba3924 181 return (0);
frank26080115 0:bf7b9fba3924 182 }
frank26080115 0:bf7b9fba3924 183
frank26080115 0:bf7b9fba3924 184 /* Support required entry point for other toolchain */
frank26080115 0:bf7b9fba3924 185 int main (void)
frank26080115 0:bf7b9fba3924 186 {
frank26080115 0:bf7b9fba3924 187 return c_entry();
frank26080115 0:bf7b9fba3924 188 }
frank26080115 0:bf7b9fba3924 189 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 190 /*******************************************************************************
frank26080115 0:bf7b9fba3924 191 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 192 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 193 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 194 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 195 * @return None
frank26080115 0:bf7b9fba3924 196 *******************************************************************************/
frank26080115 0:bf7b9fba3924 197 void check_failed(uint8_t *file, uint32_t line)
frank26080115 0:bf7b9fba3924 198 {
frank26080115 0:bf7b9fba3924 199 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 200 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 201
frank26080115 0:bf7b9fba3924 202 /* Infinite loop */
frank26080115 0:bf7b9fba3924 203 while(1);
frank26080115 0:bf7b9fba3924 204 }
frank26080115 0:bf7b9fba3924 205 #endif
frank26080115 0:bf7b9fba3924 206
frank26080115 0:bf7b9fba3924 207 /*
frank26080115 0:bf7b9fba3924 208 * @}
frank26080115 0:bf7b9fba3924 209 */