@@ -206,7 +206,7 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) {
206
206
EAnalogChannel channel = g_APinDescription [ulPin ].ulADCChannelNumber ;
207
207
if (channel == DA0 || channel == DA1 ) {
208
208
uint32_t chDACC = ((channel == DA0 ) ? 0 : 1 );
209
- if (( dacc_get_channel_status (DACC_INTERFACE ) & ( 1 << chDACC ) ) == 0 ) {
209
+ if (dacc_get_channel_status (DACC_INTERFACE ) == 0 ) {
210
210
/* Enable clock for DACC_INTERFACE */
211
211
pmc_enable_periph_clk (DACC_INTERFACE_ID );
212
212
@@ -228,20 +228,22 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) {
228
228
*/
229
229
dacc_set_timing (DACC_INTERFACE , 0x08 , 0 , 0x10 );
230
230
231
- /* Disable TAG and select output channel chDACC */
232
- dacc_set_channel_selection (DACC_INTERFACE , chDACC );
233
-
234
- /* Enable output channel chDACC */
235
- dacc_enable_channel (DACC_INTERFACE , chDACC );
236
-
237
231
/* Set up analog current */
238
232
dacc_set_analog_control (DACC_INTERFACE , DACC_ACR_IBCTLCH0 (0x02 ) |
239
233
DACC_ACR_IBCTLCH1 (0x02 ) |
240
234
DACC_ACR_IBCTLDACCORE (0x01 ));
241
235
}
242
236
237
+ /* Disable TAG and select output channel chDACC */
238
+ dacc_set_channel_selection (DACC_INTERFACE , chDACC );
239
+
240
+ if ((dacc_get_channel_status (DACC_INTERFACE ) & (1 << chDACC )) == 0 ) {
241
+ dacc_enable_channel (DACC_INTERFACE , chDACC );
242
+ }
243
+
243
244
// Write user value
244
245
ulValue = mapResolution (ulValue , _writeResolution , DACC_RESOLUTION );
246
+ while ((dacc_get_interrupt_status (DACC_INTERFACE ) & DACC_ISR_TXRDY ) == 0 );
245
247
dacc_write_conversion_data (DACC_INTERFACE , ulValue );
246
248
return ;
247
249
}
0 commit comments