Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion module/cores/arduino/port_sam/core_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,17 @@ uint32_t analogRead(uint32_t ulPin)
{
uint32_t ulValue = 0;

#if 0 // TODO: implement
uint32_t ulChannel;

#if defined(PIN_A0)
if (ulPin < A0)
ulPin += A0;
#endif

ulChannel = g_aPinMap[ulPin].ulADCChannelNumber ;

#if 0 // TODO: implement

#if defined __SAM3U4E__
switch ( g_aPinMap[ulPin].ulAnalogChannel )
{
Expand Down Expand Up @@ -185,6 +188,27 @@ uint32_t analogRead(uint32_t ulPin)
#endif

#endif // 0


#if defined(_SAMG55J19_)
//ADC setup is done in variant_init.cpp
//enable channel
ADC->ADC_CHER=(0x1<<ulChannel);
//enable channel's End Of Conversion interrupt
ADC->ADC_IER=(0x1<<ulChannel);
//start ADC conversion
ADC->ADC_CR=ADC_CR_START;
//wait till conversion is over
while(!(ADC->ADC_ISR & (0x1<<ulChannel)));
//get ADC conversion value
ulValue=ADC->ADC_CDR[ulChannel];
//disable channel
ADC->ADC_CHDR=(0x1<<ulChannel);
//disable channel's End Of Conversion interrupt
ADC->ADC_IDR=(0x1<<ulChannel);
//map value to readResolution
ulValue = mapResolution(ulValue, ADC_RESOLUTION, _readResolution);
#endif

return ulValue;
}
Expand Down
14 changes: 4 additions & 10 deletions module/variants/atmel_samg55_xplained_pro/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,22 +90,16 @@ extern "C"
/*
* Analog pins
*/
#if 0 // TODO Analog pins
#define PIN_A0 (14ul)
#define PIN_A1 (15ul)
#define PIN_A2 (16ul)
#define PIN_A3 (17ul)
#define PIN_A4 (18ul)
#define PIN_A5 (19ul)
#define PIN_A0 (22ul)
#define PIN_A1 (23ul)
#define PIN_A2 (24ul)
#define PIN_A3 (25ul)

static const uint8_t A0 = PIN_A0 ;
static const uint8_t A1 = PIN_A1 ;
static const uint8_t A2 = PIN_A2 ;
static const uint8_t A3 = PIN_A3 ;
static const uint8_t A4 = PIN_A4 ;
static const uint8_t A5 = PIN_A5 ;
#define ADC_RESOLUTION 12
#endif // TODO Analog pins

/*
* Serial interfaces
Expand Down
7 changes: 7 additions & 0 deletions module/variants/atmel_samg55_xplained_pro/variant_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@ void initVariant( void )
// Initialize Serial port Flexcom6 pins
pinPeripheral(PIN_SERIAL2_RX, GPIO_PERIPH_B);
pinPeripheral(PIN_SERIAL2_TX, GPIO_PERIPH_B);

//ADC setup
PMC->PMC_PCR = PMC_PCR_PID(ID_ADC)|PMC_PCR_CMD|PMC_PCR_DIV(1)|PMC_PCR_EN; //Set ADC peripheral clock to MCK/1 = 120MHz
PMC->PMC_PCER0 = (1<<ID_ADC); //enable ADC peripheral clock

//ADCCLK=PERIPHCLK/(2*(PRESCAL+1)) <=> PRESCAL=(PERIPHCLK/(2*ADCCLK))-1
ADC->ADC_MR =ADC_MR_PRESCAL(5); //fastest ADC conversion clock (10MHz with 120MHz peripheral clock)
}