ADC_ContinuousScan (void) { /* Init System, IP clock and multi-function I/O In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register if necessary */ SysInit(); /* Init UART0 for printf */ UART0_Init(); printf("\nThis sample code demonstrate ADC continuous scan conversion\n"); printf("It convert channel 0,1,2 continuously and print conversion result\n"); // Enable channel 0,1,2 ADC_Open(ADC, ADC_INPUT_MODE_SINGLE_END, ADC_OPERATION_MODE_CONTINUOUS, (ADC_CH_0_MASK | ADC_CH_1_MASK | ADC_CH_2_MASK)); // Power on ADC ADC_POWER_ON(ADC); // Enable ADC ADC_IF interrupt ADC_EnableInt(ADC, ADC_ADF_INT); NVIC_EnableIRQ(ADC_IRQn); ADC_START_CONV(ADC); while(1); }
int32_t main (void) { uint32_t u32Result; /* Init System, IP clock and multi-function I/O In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register if necessary */ SYS_Init(); /* Init UART0 for printf */ UART0_Init(); printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("\nThis sample code demonstrate ADC single mode conversion\n"); printf("It convert channel 0 and print conversion result\n"); // Enable channel 0 ADC_Open(ADC, 0, ADC_OPERATION_MODE_SINGLE, ADC_CH_0_MASK); // Set reference voltage to AVDD ADC_SET_REF_VOLTAGE(ADC, ADC_REFSEL_POWER); // Power on ADC ADC_POWER_ON(ADC); // Enable ADC ADC_IF interrupt ADC_EnableInt(ADC, ADC_ADF_INT); NVIC_EnableIRQ(ADC_IRQn); u8ADF = 0; ADC_START_CONV(ADC); while (u8ADF == 0); u32Result = ADC_GET_CONVERSION_DATA(ADC, 0); printf("Channel 0 conversion result is 0x%x\n",u32Result); ADC_DisableInt(ADC, ADC_ADF_INT); while(1); }
int32_t main (void) { uint32_t u32DataCount; uint32_t u32ErrorCount; /* Init System, IP clock and multi-function I/O In the end of SYS_Init() will issue SYS_LockReg() to lock protected register. If user want to write protected register, please issue SYS_UnlockReg() to unlock protected register if necessary */ SYS_Init(); /* Init UART0 for printf */ UART0_Init(); printf("\n\nCPU @ %dHz\n", SystemCoreClock); printf("\nThis sample code demonstrates ADC PDMA function.\n"); printf("Set ADC operation mode to single cycle scan mode, and enable channel 0,1,2,3\n"); printf("Enable ADC PDMA function, and trigger ADC conversion.\n"); printf("Compare the log of ADC conversion data register with the content of PDMA target buffer.\n"); printf("Finally, print the test result.\n\n"); // Enable channel 0,1,2,3 ADC_Open(ADC, 0, ADC_OPERATION_MODE_SINGLE_CYCLE, ADC_CH_0_MASK | ADC_CH_1_MASK | ADC_CH_2_MASK | ADC_CH_3_MASK); // Set reference voltage to AVDD ADC_SET_REF_VOLTAGE(ADC, ADC_REFSEL_POWER); // Power on ADC ADC_POWER_ON(ADC); /* Enable ADC PDMA */ ADC_ENABLE_PDMA(ADC); /* Configure PDMA channel 1 */ PDMA_INIT(); /* Enable PDMA IRQ */ NVIC_EnableIRQ(PDMA_IRQn); /* Clear destination buffer */ for(u32DataCount = 0; u32DataCount < ADC_TEST_COUNT; u32DataCount++) g_au32RxPDMADestination[u32DataCount] = 0; u32DataCount = 0; u32ErrorCount = 0; ADC_START_CONV(ADC); while(1) { uint32_t u32Ch; if(ADC_GET_INT_FLAG(ADC,ADC_ADF_INT) == 1) { ADC_CLR_INT_FLAG(ADC, ADC_ADF_INT); for (u32Ch = 0; u32Ch < 4; u32Ch++) { au32AdcData[u32DataCount++] = ADC_GET_CONVERSION_DATA(ADC, u32Ch); if(u32DataCount >= ADC_TEST_COUNT) break; } if (u32DataCount < ADC_TEST_COUNT) ADC_START_CONV(ADC); else break; } } /* Wait for PDMA transfer down */ while(g_u32PdmaTDoneInt == 0); /* Compare the log of ADC conversion data register with the content of PDMA target buffer */ for(u32DataCount = 0; u32DataCount < ADC_TEST_COUNT; u32DataCount++) { if( au32AdcData[u32DataCount] != (g_au32RxPDMADestination[u32DataCount] & 0xFFF) ) { printf("*** Count %d, conversion result: 0x%X, PDMA result: 0x%X.\n", u32DataCount, au32AdcData[u32DataCount], g_au32RxPDMADestination[u32DataCount]); u32ErrorCount++; } } if (u32ErrorCount == 0) printf("PASS!\n"); else printf("FAIL!\n"); while (1); }