default port = GPIO_0
Dependents: multithread_ADC_timing audio_record_serial_out
fastADC.cpp
- Committer:
- yutonggu
- Date:
- 2019-12-04
- Revision:
- 0:56e4e76188d9
- Child:
- 1:d415e0b7dc3e
File content as of revision 0:56e4e76188d9:
#include "fastADC.h" #include "mbed.h" void initADC(){ GPIOA->MODER |= (0x03 << 16); /* Configure PB0 as ADC.8 input */ ADC1->CR2 &= 1 << 1; /* non continuous conversion */ ADC1->SQR5 &= ~(0x1f); /* clear ADC_IN8 */ ADC1->SQR5 |= 0x08; /* set ADC_IN8 */ ADC1->CR2 &= ~(1 << 2); /* Make sure to use bank A */ ADC1->CR2 &= ~(3 << 24); /* set resolution to 12 bits */ ADC1->CR2 |= 1 << 0; /* turn on ADC */ while(!(ADC1->SR & (1 << 6))); } uint16_t readADC(){ while(!(ADC1->SR & (1 << 6))); /* Wait for ADC to be available */ ADC1->CR2 |= 1 << 30; /* Start new conversion */ while(!(ADC1->SR & (1 << 1))); /* If conversion has finished */ return (uint16_t) ADC1->DR & 0xFFFF; /* Read AD converted value */ }