6729 views|12 replies

85

Posts

0

Resources
The OP
 

【AT32F421 Review】+ ADC Sampling and SPI_OLED Display [Copy link]

 
 

This article will evaluate the hardware SPI and 12-bit ADC of AT32F421. First, the hardware SPI will be presented in the form of SPI_OLED, and the ADC will be tested by testing the actual voltage.

The OLED I chose is the common 0.96-inch OLED on the market. It supports I2C and SPI interfaces. I will use the AT32 hardware SPI to drive it and use it as a display for the voltage value measured by the ADC.

First of all, because there are many people using 0.96-inch OLEDs on the market, some developers or merchants have written universal drivers for them. In order to improve development efficiency and avoid reinventing the wheel, I chose a driver from a certain park, which provides a lot of routines, and I modified them based on it.

First, create three C files such as SPI.c, SPI_OLED.c, ADC.c and their corresponding h header files in the HARDWARE folder. Then add at32f4xx_spi.c, at32f4xx_adc.c and at32f4xx_dma.c in FWLIB as shown in the figure below

The second step is to copy the analog SPI driver of a certain park to SPI_OLED.c, and

OLED_WR_Byte , which is the function of writing a byte, is modified as shown in the figure below, and the software simulated transmission process is replaced by the hardware SPI sending function SPI_I2S_TxData.

Because there are DC and RST pins on SPI_OLED, I use PA6 and PA4 to replace them respectively, as shown in the figure below.

Other driver functions do not need to be modified.

The third step is to configure the hardware SPI of AT32F421. First, add the following function in SPI.c so that it can be called in the main function (refer to the Simplex_Interrupt example in AT_START_F421 in the official BSP). It should be noted here that, first, we need to use SPI, configure GPIO, configure the SPI corresponding clock and GPIO corresponding clock, and configure the SPI parameters; second, according to the timing diagram of the SPI interface of the SSD1306 driver chip used by the 0.96-inch OLED, the initial clock level can be high or low, and then transmit data on the rising edge, so I configure the initial level to low through SPI_InitStructure.SPI_CPOL = SPI_CPOL_LOW; and then through SPI_InitStructure.SPI_CPHA = SPI_CPHA_1EDGE; configure it as the first edge change transmission , that is, the rising edge. (Here I would like to add that it may be my misunderstanding of the timing diagram. When CPOL and CPHA are not configured as the above configuration, it seems to be drivable after the experiment, but my suggestion is that it is best to configure it as the above configuration). The specific configuration is shown in the figure below.

The fourth step is to configure ADC. Please refer to the ADC1_DMA example in AT_START_F421 in the official BSP. I will only talk about the key points here. Please see the attachment for the specific configuration. The measured ADC data here is transferred to a variable array through DMA, through DMA_InitStructure.DMA_MemoryBaseAddr=(uint32_t)ADC_RegularConvertedValueTab;

DMA_InitStructure.DMA_BufferSize = 1;

Move the measured voltage to the ADC_RegularConvertedValueTab array,

I will then test the ADC measuring the external voltage and the internal reference voltage in turn.

The following is to measure the external voltage value of channel 1 of ADC1, which is the external value of PA1

ADC_RegularChannelConfig(ADC1,ADC_Channel_1,1,ADC_SampleTime_239_5);

//Test channel 1 PA1

The following can measure the internal reference voltage

ADC_RegularChannelConfig(ADC1,ADC_Channel_Vrefint,1,ADC_SampleTime_239_5); //Test internal reference voltage

Remember to add the following sentence , which is the function that enables ADC to measure the internal temperature sensor and reference voltage

/* Enables Temperature Sensor and Vrefint Channel */

ADC_TempSensorVrefintCtrl(ENABLE);

Finally , write the following function in the main program. The microcontroller updates the actual voltage value collected at a refresh rate of 1 second. A conversion is required here: ADC_RegularConvertedValueTab[0]*3282/4096.0; the 3282 in this statement means that the working voltage of the microcontroller measured by the multimeter is 3282mv. The voltage value may be different in different situations, so this needs to be modified.

Finally, let's show the actual measurement results . First, measure the reference voltage inside the microcontroller. According to the data sheet, this reference voltage should be around 1.20V.

The actual measurement is 1.206V, which meets the standard

Next, we tested different voltage values and compared them with a calibrated 4.5-digit multimeter. The ADC of AT32F421 is still very reliable and has high accuracy.

This time the ADC and SPI test of AT32F421 is completed

AT32_ADC_and_SPI_OLED.zip

12.86 MB, 阅读权限: 10, downloads: 21

This post is from Domestic Chip Exchange

Latest reply

Can't download  Details Published on 2023-6-29 23:12
 
 

6547

Posts

0

Resources
2
 

The accuracy can be compared with a calibrated 4.5-digit multimeter, and the test is successful.

This post is from Domestic Chip Exchange
 
 
 

7422

Posts

2

Resources
3
 

It seems that the ADC analog part of this chip is well done. What about the response speed?

This post is from Domestic Chip Exchange

Comments

This hasn't been tested yet.  Details Published on 2021-5-9 17:55
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 
 

71

Posts

2

Resources
4
 

Very detailed write-up, thanks for sharing.

This post is from Domestic Chip Exchange
 
 
 

85

Posts

0

Resources
5
 
freebsder posted on 2021-5-6 16:23 It seems that the ADC analog part of this chip is well made. What about the response speed?

This hasn't been tested yet.

This post is from Domestic Chip Exchange
 
 
 

1

Posts

0

Resources
6
 

Why can't I download it?

This post is from Domestic Chip Exchange
 
 
 

5

Posts

0

Resources
7
 

Why can't I download it?

This post is from Domestic Chip Exchange

Comments

nmg
Are you talking about the attachment in the post? I just downloaded it and it worked fine. Can you try again?  Details Published on 2021-6-11 08:07
 
 
 

5213

Posts

239

Resources
8
 

Are you talking about the attachment in the post? I just downloaded it and it worked fine. Can you try again?

This post is from Domestic Chip Exchange
Add and join groups EEWorld service account EEWorld subscription account Automotive development circle
 
 
 

85

Posts

0

Resources
9
 

Has read permission 10

This post is from Domestic Chip Exchange
 
 
 

2

Posts

0

Resources
10
 

Very well written

This post is from Domestic Chip Exchange
 
 
 

2

Posts

0

Resources
11
 

Why can't I download it?

This post is from Domestic Chip Exchange
 
 
 

1

Posts

0

Resources
12
 

Unable to download attachment

This post is from Domestic Chip Exchange
 
 
 

1

Posts

0

Resources
13
 
Can't download
This post is from Domestic Chip Exchange
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list