I'm programming my ESP32 using Arduino-IDE. I want to use DAC in continuous mode (DMA mode) with cyclical writing to create waveforms. Therefor I'm creating a buffer-array (type: byte) containing the 8-bit values the DAC should output. But there's a significant problem: The output swaps 2 values of the buffer, so buffer[1] is output first, followed by buffer[0], then buffer[3] followed by buffer[2]. Probably the reason is the 8bit-DAC is using 16bit-I2S for DMA and this leads to the swapping.
Ok, I could just simply swap the values within my buffer to get the correct signal. But I want to keep them in their correct order and instead asking how to solve this issues by ESP32's DAC-API commands? Any ideas?
Code: Select all
#include <driver/dac_continuous.h>
void setup() {
dac_continuous_config_t dac_config = {
.chan_mask = DAC_CHANNEL_MASK_CH0,
.desc_num = 4,
.buf_size = 1024,
.freq_hz = 160000,
.offset = 0,
.clk_src = DAC_DIGI_CLK_SRC_DEFAULT,
};
dac_continuous_handle_t dac_handle;
dac_continuous_new_channels(&dac_config, &dac_handle);
dac_continuous_enable(dac_handle);
byte buffer[16] = { 0, 25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 250, 250, 250, 250, 250 };
dac_continuous_write_cyclically(dac_handle, buffer, 16, NULL);
}
void loop() {
}