mcpField
A
adc-dac-baremetal

adc-dac-baremetal

github.com/mohitmishra786Development269300 installsUpdated 18w ago
Repository

About adc-dac-baremetal

A bare-metal skill for configuring ADC and DAC peripherals, with examples centered on STM32. It covers single conversions, calibration, DMA-based continuous sampling, and static or dynamic DAC output.

Key features

  1. 01STM32 ADC single conversions
  2. 02ADC calibration sequences
  3. 03Circular DMA sampling and buffering
  4. 04DAC static output configuration
  5. 05Common analog-read and DMA troubleshooting

Use cases

  1. 01Reading analog temperature or voltage sensors
  2. 02Sampling continuously with DMA
  3. 03Producing audio or control voltage through DAC
  4. 04Calibrating ADC after an STM32 reset

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/mohitmishra786/low-level-dev-skills --skill adc-dac-baremetal

After installing, type/adc-dac-baremetalin Claude Code to confirm it loaded.

Details

From the project README

ADC and DAC (Bare-Metal)

Purpose

Configure ADC and DAC peripherals: channel selection, sampling times, calibration sequences, DMA circular buffers, and DAC static/dynamic output.

When to Use

  • Reading analog sensors (temperature, voltage)
  • Audio or control voltage output via DAC
  • Continuous sampling with DMA
  • Post-reset ADC calibration on STM32

Workflow

1. STM32 ADC single conversion
/* Enable ADC1 and GPIOA clock; PA0 analog mode */
ADC1->CR2 |= ADC_CR2_ADON;
for (volatile int i = 0; i < 10000; i++);  /* stabilization — RM value */

ADC1->SMPR2 |= ADC_SMPR2_SMP0_2;  /* 84 cycles sample time ch0 */
ADC1->SQR3   = 0;                 /* channel 0, 1 conversion */
ADC1->CR2   |= ADC_CR2_SWSTART;

while (!(ADC1->SR & ADC_SR_EOC))
    ;
uint16_t sample = ADC1->DR;

Run ADC_Calibration() / ADC_CR2_RSTCAL/CAL per RM on F1/F4 families.

2. DMA circular ADC
/* ADC1 → DMA2 Stream0, circular mode into buffer[64] */
/* Configure DMA: periph-to-mem, halfword, increment mem, circular */
ADC1->CR2 |= ADC_CR2_DMA | ADC_CR2_CONT;
DMA2_Stream0->CR |= DMA_SxCR_EN;

Half-transfer / transfer-complete IRQs for double buffering.

3. DAC output (STM32)
RCC->APB1ENR |= RCC_APB1ENR_DACEN;
DAC->CR |= DAC_CR_EN1;
DAC->DHR12R1 = 2048;  /* mid-scale 3.3V reference */
4. Agent usage
/adc-dac-baremetal Set up ADC1 channel 0 with DMA circular buffer

Common Problems

SymptomCauseFix
Noisy readingsShort sample timeIncrease SMP bits
Stuck EOCClock not enabledRCC ADC enable
Wrong voltageVref not 3.3VMeasure VDDA; calibrate
DMA corruptBuffer alignmentUse uint16_t aligned buffer

Related Skills

  • skills/baremetal/dma-baremetal — ADC DMA streams
  • skills/baremetal/timers-pwm-baremetal — ADC external trigger
  • skills/baremetal/gpio-baremetal — analog pin mode

Comments

Markdown supported