Matt-Lemcke / Register-Level-Project

Firmware developed in C for the STM32F429 microcontroller with custom hardware abstraction for minimal memory usage
0 stars 0 forks source link

ADC configuration #7

Closed Matt-Lemcke closed 2 years ago

Matt-Lemcke commented 2 years ago

Configure ADC to capture input

Matt-Lemcke commented 2 years ago

Enable ADC1 clk, enable GPIOx clk. Set GPIO pin in analog mode Set ADC prescalar (from APB2 source). Set continuous conversion, EOC after each conversion, data alignment LEFT. Set sampling time to 3 cycles. Set one conversion in regular sequence, assign channel as 1st conversion. Set sampling frequency. Set TSVREFE bit to wait sensor. Enable DMA in CR2 register. Enable continuous request.

Enable ADC (ADON=1). Wait at least 10us.

Enable DMA clock. Set peripheral to memory stream CIRC = 1. MINC = 1. Set PSIZE and MSIZE for size of data (16 bit) Select channel for stream (find in datasheet)

Set size of DMA stream transfer size. Set source address as peripheral address. Set destination address as memory location of buffer variable. Enable dma stream.

ADC clear SR register. Start conversion (SWSTART = 1)

Read values through buffer variable when needed

Matt-Lemcke commented 2 years ago

ADC1 uses DMA2, stream 0, channel 0