0% found this document useful (0 votes)
571 views13 pages

Getting Started STM32 - ADC&FFT&UART - Updated by Phill

The document discusses using an STM32 microcontroller to take an analog input signal of a 1 kHz sine wave sampled at 10 kHz, perform an FFT on the sampled data using the CMSIS DSP library, and transmit the FFT results over UART to MATLAB for analysis and verification. It provides steps for setting up the hardware and software components in STM32CubeMX and STM32CubeIDE, integrating the CMSIS DSP library, sampling and transmitting the data to MATLAB, and analyzing the results to confirm the measured signal frequency matches the 1 kHz input frequency.

Uploaded by

Xiaofang Jiang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
571 views13 pages

Getting Started STM32 - ADC&FFT&UART - Updated by Phill

The document discusses using an STM32 microcontroller to take an analog input signal of a 1 kHz sine wave sampled at 10 kHz, perform an FFT on the sampled data using the CMSIS DSP library, and transmit the FFT results over UART to MATLAB for analysis and verification. It provides steps for setting up the hardware and software components in STM32CubeMX and STM32CubeIDE, integrating the CMSIS DSP library, sampling and transmitting the data to MATLAB, and analyzing the results to confirm the measured signal frequency matches the 1 kHz input frequency.

Uploaded by

Xiaofang Jiang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

ADC 

/ FFT / UART
with STM32
Input Signal: Sine wave with f0 = 1 kHz 
fs = 10 kHz

Jeong Phill Kim
Chung‐Ang University, Seoul, Korea

Required Hardware / Software Step 1: Work with STM32CubeMX
1. STM32F4XXX Board
2. Analog Discovery 2 (or Studio)
1. Run STM32CubeMX.exe
3. STM32CubeMX
4. STM32CubeIDE
5. CMSIS DPS Library
6. Matlab
2. Click New Project (Ctrl+N)

1. New Project

Chung‐Ang University 2
3. Select STM32F407VG 4. MCU Configuration Setting

4.1. System Core  SYS  Debug 


 Serial Wire

1. STM32F407VG 

2. Double Click

Chung‐Ang University 3

4.2. System Core  RCC  HSE  4.3. Clock Configuration Setting


 Crystal/Ceramic Resonator

2. HSE

4. HLK = 168
3. PLLCLK

1. Inpu freq = 8

Chung‐Ang University 4
4.4. ADC1  IN1  DMA Enabled

4.2
4.4 DMA Settings

4.1
4.3
4.5 ADC1 Select

4.6 Add

4.7 Circular mode

Chung‐Ang University 5

5. Timer and Clock Setting 6. Communication (Connectivity  USART3)

2. Asynchoronous
2. Internal Clock

84M/84/100 = 10K
 Sample freq setting

3. Prescaler
1. Click TIM2 1. USART3
4. Counter Period

5. Trigger Update Event

Chung‐Ang University 6
7. Interrupt Setting 8. Code Generation Setting
System Core  NVIC  Global Interrupt for
1. ADC1, ADC2, ADC3 2. Project name 4. Generate Code
2. usart3 
3. TIM2

1. Project Manager

3. Toolchaind/IDE  STM32CubeIDE

Check

Chung‐Ang University 7

9. Check Pin Setup Step 2: Work with STM32CubeIDE

1. Run STM32CubeIDE

Check pin setting


1. ADC input = PA1
2. UART = PB10, 11

Chung‐Ang University 8
File 
 New 
 STM32 Project from an Existing STM32CubeMx Configuration file

Project folder

Location of
STM32CubeMx Configuration file

ioc file click

Chung‐Ang University 9

Chung‐Ang University 10
Step 3: Work with CMSIS DSP Library
For FFT, CMSIS DSP library is downloaded !!!
https://www.st.com/en/embedded‐software/x‐cube‐dspdemo.html#overview

Chung‐Ang University 11

Chung‐Ang University 12
Copy and paste 

Chung‐Ang University 13

Back to CMSIS Folder and go to Lib arm_cortexM4lf_mat.lib copy and paste

Chung‐Ang University 14
Copy and paste

Chung‐Ang University 15

File  Properties

1 3

Chung‐Ang University 16
Check 4 Symbol

Click

Add symbol
__FPU_PRESENT         1
__FPU_USED             1
__TARGET_FPU_VFP
ARM_MATH_CM4

Chung‐Ang University 17

Chung‐Ang University 18
Chung‐Ang University 19

Project  Properties

Chung‐Ang University 20
1 3 Click & Build

4. check

5. click

Chung‐Ang University 21

Sine Wave Generator

UART

Click

Chung‐Ang University 22
Chung‐Ang University 23

Step 4: Data Transfer to MATLAB

uart_setup.m

이전에 연결한 uart가


없으면 써주지 않아도
됨.

Chung‐Ang University 24
Click Run

Chung‐Ang University 25

Data_achieve.m

Data type 변환해야 돼서
가끔 에러 날 때 있음. 그럴
경우는 data 가 어떻게
들어왔는지 workspace에서
확인

N = 1000
Ts = 0.1 ms (fs = 10 kHz)
Tmon = N Ts = 100 ms
df = 1/(N Ts) = 10 Hz

Measured Signal Frequency
Idx = 100
fm = Idx x df = 1 kHz

Signal Frequency (1 kHz)와 일치

Chung‐Ang University 26

You might also like