Skip to content

Commit 253e40e

Browse files
GabrielNotmancmaglie
authored andcommitted
Removes the requirement that the DAC is on A0 (which requires that A0 uses PA02)
1 parent 9ac80d9 commit 253e40e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Diff for: cores/arduino/wiring_analog.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ uint32_t analogRead(uint32_t pin)
135135

136136
pinPeripheral(pin, PIO_ANALOG);
137137

138-
if (pin == A0) { // Disable DAC, if analogWrite(A0,dval) used previously the DAC is enabled
138+
// Disable DAC, if analogWrite() was used previously to enable the DAC
139+
if ((g_APinDescription[pin].ulADCChannelNumber == ADC_Channel0) || (g_APinDescription[pin].ulADCChannelNumber == DAC_Channel0)) {
139140
syncDAC();
140141
DAC->CTRLA.bit.ENABLE = 0x00; // Disable DAC
141142
//DAC->CTRLB.bit.EOEN = 0x00; // The DAC output is turned off.
@@ -196,7 +197,7 @@ void analogWrite(uint32_t pin, uint32_t value)
196197
{
197198
// DAC handling code
198199

199-
if (pin != PIN_A0) { // Only 1 DAC on A0 (PA02)
200+
if ((pinDesc.ulADCChannelNumber != ADC_Channel0) && (pinDesc.ulADCChannelNumber != DAC_Channel0)) { // Only 1 DAC on AIN0 / PA02
200201
return;
201202
}
202203

0 commit comments

Comments
 (0)