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 /******************** (C) COPYRIGHT 2010 NXPSemiconductors ************
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 * burst mode
frank26080115 0:bf7b9fba3924 5 * @version 2.0
frank26080115 0:bf7b9fba3924 6 * @date 16. July. 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 #include "lpc17xx_gpio.h"
frank26080115 0:bf7b9fba3924 25
frank26080115 0:bf7b9fba3924 26 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 27 /** @defgroup ADC_Burst Burst
frank26080115 0:bf7b9fba3924 28 * @ingroup ADC_Examples
frank26080115 0:bf7b9fba3924 29 * @{
frank26080115 0:bf7b9fba3924 30 */
frank26080115 0:bf7b9fba3924 31
frank26080115 0:bf7b9fba3924 32 /************************** PRIVATE DEFINITIONS ***********************/
frank26080115 0:bf7b9fba3924 33 #define MCB_LPC_1768
frank26080115 0:bf7b9fba3924 34 //#define IAR_LPC_1768
frank26080115 0:bf7b9fba3924 35 #define MCB_LPC17XX_ADC_INJECT_TEST
frank26080115 0:bf7b9fba3924 36
frank26080115 0:bf7b9fba3924 37 #ifdef MCB_LPC_1768
frank26080115 0:bf7b9fba3924 38 #define MCB_LPC_1768_ADC_BURST_MULTI
frank26080115 0:bf7b9fba3924 39 #endif
frank26080115 0:bf7b9fba3924 40
frank26080115 0:bf7b9fba3924 41 #ifdef MCB_LPC_1768
frank26080115 0:bf7b9fba3924 42 #define _ADC_INT ADC_ADINTEN2
frank26080115 0:bf7b9fba3924 43 #define _ADC_CHANNEL ADC_CHANNEL_2
frank26080115 0:bf7b9fba3924 44
frank26080115 0:bf7b9fba3924 45 #ifdef MCB_LPC_1768_ADC_BURST_MULTI
frank26080115 0:bf7b9fba3924 46 #define _ADC_INT_3 ADC_ADINTEN3
frank26080115 0:bf7b9fba3924 47 #define _ADC_CHANNEL_3 ADC_CHANNEL_3
frank26080115 0:bf7b9fba3924 48 #endif
frank26080115 0:bf7b9fba3924 49
frank26080115 0:bf7b9fba3924 50 #elif defined(IAR_LPC_1768)
frank26080115 0:bf7b9fba3924 51 #define _ADC_INT ADC_ADINTEN5
frank26080115 0:bf7b9fba3924 52 #define _ADC_CHANNEL ADC_CHANNEL_5
frank26080115 0:bf7b9fba3924 53 #endif
frank26080115 0:bf7b9fba3924 54
frank26080115 0:bf7b9fba3924 55 /** DMA size of transfer */
frank26080115 0:bf7b9fba3924 56 #define DMA_SIZE 8
frank26080115 0:bf7b9fba3924 57
frank26080115 0:bf7b9fba3924 58 #ifdef MCB_LPC17XX_ADC_INJECT_TEST
frank26080115 0:bf7b9fba3924 59 #define GPIO_INT (1<<10)
frank26080115 0:bf7b9fba3924 60 #define POLL_LED (1<<4) // P1.28
frank26080115 0:bf7b9fba3924 61 #endif
frank26080115 0:bf7b9fba3924 62 /************************** PRIVATE VARIABLES *************************/
frank26080115 0:bf7b9fba3924 63 uint8_t menu1[] =
frank26080115 0:bf7b9fba3924 64 "********************************************************************************\n\r"
frank26080115 0:bf7b9fba3924 65 "Hello NXP Semiconductors \n\r"
frank26080115 0:bf7b9fba3924 66 " ADC burst demo \n\r"
frank26080115 0:bf7b9fba3924 67 "\t - MCU: LPC17xx \n\r"
frank26080115 0:bf7b9fba3924 68 "\t - Core: ARM CORTEX-M3 \n\r"
frank26080115 0:bf7b9fba3924 69 "\t - Communicate via: UART0 - 115200 bps \n\r"
frank26080115 0:bf7b9fba3924 70 " Use ADC with 12-bit resolution rate of 200KHz, running burst mode (single or multiple input)\n\r"
frank26080115 0:bf7b9fba3924 71 " Display ADC value via UART0\n\r"
frank26080115 0:bf7b9fba3924 72 " Turn the potentiometer to see how ADC value changes\n\r"
frank26080115 0:bf7b9fba3924 73 "********************************************************************************\n\r";
frank26080115 0:bf7b9fba3924 74
frank26080115 0:bf7b9fba3924 75 #ifdef MCB_LPC17XX_ADC_INJECT_TEST
frank26080115 0:bf7b9fba3924 76 static BOOL_8 toggle=FALSE;
frank26080115 0:bf7b9fba3924 77 #endif
frank26080115 0:bf7b9fba3924 78 /************************** PRIVATE FUNCTION *************************/
frank26080115 0:bf7b9fba3924 79 void print_menu(void);
frank26080115 0:bf7b9fba3924 80
frank26080115 0:bf7b9fba3924 81 #ifdef MCB_LPC17XX_ADC_INJECT_TEST
frank26080115 0:bf7b9fba3924 82 void EINT3_IRQHandler(void);
frank26080115 0:bf7b9fba3924 83 #endif
frank26080115 0:bf7b9fba3924 84
frank26080115 0:bf7b9fba3924 85 /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
frank26080115 0:bf7b9fba3924 86 #ifdef MCB_LPC17XX_ADC_INJECT_TEST
frank26080115 0:bf7b9fba3924 87 void EINT3_IRQHandler(void)
frank26080115 0:bf7b9fba3924 88 {
frank26080115 0:bf7b9fba3924 89 if (GPIO_GetIntStatus(1, 10, 1))
frank26080115 0:bf7b9fba3924 90 {
frank26080115 0:bf7b9fba3924 91 GPIO_ClearInt(2,(1<<10));
frank26080115 0:bf7b9fba3924 92 toggle=~toggle;
frank26080115 0:bf7b9fba3924 93 #ifdef MCB_LPC_1768_ADC_BURST_MULTI
frank26080115 0:bf7b9fba3924 94 if(toggle)
frank26080115 0:bf7b9fba3924 95 {
frank26080115 0:bf7b9fba3924 96 ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_3,ENABLE);
frank26080115 0:bf7b9fba3924 97 FIO_ByteSetValue(1, 3, POLL_LED);
frank26080115 0:bf7b9fba3924 98 }
frank26080115 0:bf7b9fba3924 99 else
frank26080115 0:bf7b9fba3924 100 {
frank26080115 0:bf7b9fba3924 101 ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_3,DISABLE);
frank26080115 0:bf7b9fba3924 102 FIO_ByteClearValue(1, 3, POLL_LED);
frank26080115 0:bf7b9fba3924 103 }
frank26080115 0:bf7b9fba3924 104 #endif
frank26080115 0:bf7b9fba3924 105 }
frank26080115 0:bf7b9fba3924 106 }
frank26080115 0:bf7b9fba3924 107 #endif
frank26080115 0:bf7b9fba3924 108 /*-------------------------PRIVATE FUNCTIONS------------------------------*/
frank26080115 0:bf7b9fba3924 109 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 110 * @brief Print menu
frank26080115 0:bf7b9fba3924 111 * @param[in] None
frank26080115 0:bf7b9fba3924 112 * @return None
frank26080115 0:bf7b9fba3924 113 **********************************************************************/
frank26080115 0:bf7b9fba3924 114 void print_menu(void)
frank26080115 0:bf7b9fba3924 115 {
frank26080115 0:bf7b9fba3924 116 _DBG(menu1);
frank26080115 0:bf7b9fba3924 117 }
frank26080115 0:bf7b9fba3924 118
frank26080115 0:bf7b9fba3924 119
frank26080115 0:bf7b9fba3924 120 /*-------------------------MAIN FUNCTION------------------------------*/
frank26080115 0:bf7b9fba3924 121 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 122 * @brief c_entry: Main ADC program body
frank26080115 0:bf7b9fba3924 123 * @param[in] None
frank26080115 0:bf7b9fba3924 124 * @return int
frank26080115 0:bf7b9fba3924 125 **********************************************************************/
frank26080115 0:bf7b9fba3924 126 int c_entry(void)
frank26080115 0:bf7b9fba3924 127 {
frank26080115 0:bf7b9fba3924 128 PINSEL_CFG_Type PinCfg;
frank26080115 0:bf7b9fba3924 129 #ifdef MCB_LPC_1768_ADC_BURST_MULTI
frank26080115 0:bf7b9fba3924 130 PINSEL_CFG_Type PinCfg1;
frank26080115 0:bf7b9fba3924 131 #endif
frank26080115 0:bf7b9fba3924 132 uint32_t tmp;
frank26080115 0:bf7b9fba3924 133 uint32_t adc_value;
frank26080115 0:bf7b9fba3924 134 /* Initialize debug via UART0
frank26080115 0:bf7b9fba3924 135 * – 115200bps
frank26080115 0:bf7b9fba3924 136 * – 8 data bit
frank26080115 0:bf7b9fba3924 137 * – No parity
frank26080115 0:bf7b9fba3924 138 * – 1 stop bit
frank26080115 0:bf7b9fba3924 139 * – No flow control
frank26080115 0:bf7b9fba3924 140 */
frank26080115 0:bf7b9fba3924 141 debug_frmwrk_init();
frank26080115 0:bf7b9fba3924 142
frank26080115 0:bf7b9fba3924 143 // print welcome screen
frank26080115 0:bf7b9fba3924 144 print_menu();
frank26080115 0:bf7b9fba3924 145
frank26080115 0:bf7b9fba3924 146 /* Because the potentiometer on different boards (MCB & IAR) connect
frank26080115 0:bf7b9fba3924 147 * with different ADC channel, so we have to configure correct ADC channel
frank26080115 0:bf7b9fba3924 148 * on each board respectively.
frank26080115 0:bf7b9fba3924 149 * If you want to check other ADC channels, you have to wire this ADC pin directly
frank26080115 0:bf7b9fba3924 150 * to potentiometer pin (please see schematic doc for more reference)
frank26080115 0:bf7b9fba3924 151 */
frank26080115 0:bf7b9fba3924 152 #ifdef MCB_LPC_1768
frank26080115 0:bf7b9fba3924 153 /*
frank26080115 0:bf7b9fba3924 154 * Init ADC pin connect
frank26080115 0:bf7b9fba3924 155 * AD0.2 on P0.25
frank26080115 0:bf7b9fba3924 156 */
frank26080115 0:bf7b9fba3924 157 PinCfg.Funcnum = 1;
frank26080115 0:bf7b9fba3924 158 PinCfg.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 159 PinCfg.Pinmode = 0;
frank26080115 0:bf7b9fba3924 160 PinCfg.Pinnum = 25;
frank26080115 0:bf7b9fba3924 161 PinCfg.Portnum = 0;
frank26080115 0:bf7b9fba3924 162 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 163 #ifdef MCB_LPC_1768_ADC_BURST_MULTI
frank26080115 0:bf7b9fba3924 164 /*
frank26080115 0:bf7b9fba3924 165 * Init ADC pin connect
frank26080115 0:bf7b9fba3924 166 * AD0.3 on P0.26
frank26080115 0:bf7b9fba3924 167 */
frank26080115 0:bf7b9fba3924 168 PinCfg1.Funcnum = 1;
frank26080115 0:bf7b9fba3924 169 PinCfg1.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 170 PinCfg1.Pinmode = 0;
frank26080115 0:bf7b9fba3924 171 PinCfg1.Pinnum = 26;
frank26080115 0:bf7b9fba3924 172 PinCfg1.Portnum = 0;
frank26080115 0:bf7b9fba3924 173 PINSEL_ConfigPin(&PinCfg1);
frank26080115 0:bf7b9fba3924 174 #endif
frank26080115 0:bf7b9fba3924 175 #elif defined (IAR_LPC_1768)
frank26080115 0:bf7b9fba3924 176 /* select P1.31 as AD0.5 */
frank26080115 0:bf7b9fba3924 177 PinCfg.Funcnum = 3;
frank26080115 0:bf7b9fba3924 178 PinCfg.OpenDrain = 0;
frank26080115 0:bf7b9fba3924 179 PinCfg.Pinmode = 0;
frank26080115 0:bf7b9fba3924 180 PinCfg.Pinnum = 31;
frank26080115 0:bf7b9fba3924 181 PinCfg.Portnum = 1;
frank26080115 0:bf7b9fba3924 182 PINSEL_ConfigPin(&PinCfg);
frank26080115 0:bf7b9fba3924 183 #endif
frank26080115 0:bf7b9fba3924 184
frank26080115 0:bf7b9fba3924 185
frank26080115 0:bf7b9fba3924 186 /* Configuration for ADC:
frank26080115 0:bf7b9fba3924 187 * select: ADC channel 2 (if using MCB1700 board)
frank26080115 0:bf7b9fba3924 188 * ADC channel 5 (if using IAR-LPC1768 board)
frank26080115 0:bf7b9fba3924 189 * ADC conversion rate = 200KHz
frank26080115 0:bf7b9fba3924 190 */
frank26080115 0:bf7b9fba3924 191 ADC_Init(LPC_ADC, 200000);
frank26080115 0:bf7b9fba3924 192 ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL,ENABLE);
frank26080115 0:bf7b9fba3924 193 #ifdef MCB_LPC_1768_ADC_BURST_MULTI
frank26080115 0:bf7b9fba3924 194 ADC_ChannelCmd(LPC_ADC,_ADC_CHANNEL_3,ENABLE);
frank26080115 0:bf7b9fba3924 195 #endif
frank26080115 0:bf7b9fba3924 196
frank26080115 0:bf7b9fba3924 197 #ifdef MCB_LPC17XX_ADC_INJECT_TEST
frank26080115 0:bf7b9fba3924 198 FIO_ByteSetDir(1, 3, POLL_LED, 1);
frank26080115 0:bf7b9fba3924 199 FIO_ByteClearValue(1, 3, POLL_LED);
frank26080115 0:bf7b9fba3924 200 // Enable GPIO interrupt P2.10
frank26080115 0:bf7b9fba3924 201 GPIO_IntCmd(2,(1<<10),1);
frank26080115 0:bf7b9fba3924 202 NVIC_EnableIRQ(EINT3_IRQn);
frank26080115 0:bf7b9fba3924 203 #endif
frank26080115 0:bf7b9fba3924 204
frank26080115 0:bf7b9fba3924 205 //Start burst conversion
frank26080115 0:bf7b9fba3924 206 ADC_BurstCmd(LPC_ADC,ENABLE);
frank26080115 0:bf7b9fba3924 207 while(1)
frank26080115 0:bf7b9fba3924 208 {
frank26080115 0:bf7b9fba3924 209 #ifdef MCB_LPC_1768
frank26080115 0:bf7b9fba3924 210 adc_value = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_2);
frank26080115 0:bf7b9fba3924 211 _DBG("ADC value on channel 2: ");
frank26080115 0:bf7b9fba3924 212 #elif defined (IAR_LPC_1768)
frank26080115 0:bf7b9fba3924 213 adc_value = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_5);
frank26080115 0:bf7b9fba3924 214 _DBG("ADC value on channel 5: ");
frank26080115 0:bf7b9fba3924 215 #endif
frank26080115 0:bf7b9fba3924 216 _DBD32(adc_value);
frank26080115 0:bf7b9fba3924 217 _DBG_("");
frank26080115 0:bf7b9fba3924 218 #ifdef MCB_LPC_1768_ADC_BURST_MULTI
frank26080115 0:bf7b9fba3924 219 adc_value = ADC_ChannelGetData(LPC_ADC,ADC_CHANNEL_3);
frank26080115 0:bf7b9fba3924 220 _DBG("ADC value on channel 3: ");
frank26080115 0:bf7b9fba3924 221 _DBD32(adc_value);
frank26080115 0:bf7b9fba3924 222 _DBG_("");
frank26080115 0:bf7b9fba3924 223 #endif
frank26080115 0:bf7b9fba3924 224 // Wait for a while
frank26080115 0:bf7b9fba3924 225 for(tmp = 0; tmp < 1500000; tmp++);
frank26080115 0:bf7b9fba3924 226 }
frank26080115 0:bf7b9fba3924 227 ADC_DeInit(LPC_ADC);
frank26080115 0:bf7b9fba3924 228 return (0);
frank26080115 0:bf7b9fba3924 229 }
frank26080115 0:bf7b9fba3924 230
frank26080115 0:bf7b9fba3924 231 /* Support required entry point for other toolchain */
frank26080115 0:bf7b9fba3924 232 int main (void)
frank26080115 0:bf7b9fba3924 233 {
frank26080115 0:bf7b9fba3924 234 return c_entry();
frank26080115 0:bf7b9fba3924 235 }
frank26080115 0:bf7b9fba3924 236 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 237 /*******************************************************************************
frank26080115 0:bf7b9fba3924 238 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 239 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 240 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 241 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 242 * @return None
frank26080115 0:bf7b9fba3924 243 *******************************************************************************/
frank26080115 0:bf7b9fba3924 244 void check_failed(uint8_t *file, uint32_t line)
frank26080115 0:bf7b9fba3924 245 {
frank26080115 0:bf7b9fba3924 246 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 247 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 248
frank26080115 0:bf7b9fba3924 249 /* Infinite loop */
frank26080115 0:bf7b9fba3924 250 while(1);
frank26080115 0:bf7b9fba3924 251 }
frank26080115 0:bf7b9fba3924 252 #endif
frank26080115 0:bf7b9fba3924 253
frank26080115 0:bf7b9fba3924 254 /*
frank26080115 0:bf7b9fba3924 255 * @}
frank26080115 0:bf7b9fba3924 256 */