当前位置:网站首页>Stm3 (cubeide) lighting experiment
Stm3 (cubeide) lighting experiment
2022-07-25 21:12:00 【Glazed amber eye】
Create a project :
open cubeIDE-->File->new->STM32 Project-> Enter the chip model in the search box in the upper left corner -> Select the chip in the lower right corner
->next-> stay Project Name Fill in the project name ->Finsh->yes-> Find the pin in the pop-up graphic configuration interface search box
-> Select the corresponding pin setting input with the left mouse button ( Output ) Pattern -> Right mouse button Pin Reservation Set the corresponding initialization code
->ProjectManager->Code Generator->Gnernerate peripheral.......'h/c'( It means to generate a pair .h and .c)
->Ctrl+s preservation
How to view the relevant register address of the small light bulb :
1. Check the name of the small light bulb on the development board, such as LED1, without , Skip to step two
2. Look at the schematic , stay wps Wait for the document viewing tool to open the principle ,Ctrl+f And search in the search box in the upper right corner LED1,
contrast LED1 Corresponding pin , such as LED1 Corresponding PZ5, Go to the next step ;
3. Check out the chip manual , stay wps Wait for the document viewing tool to open the principle ,Ctrl+f And search in the search box in the upper right corner GPIOZ,
Check the corresponding Talbel such as Register boundary addresses (continued) This table corresponds to GPIOZ The base address
Here's the picture : You can see GPIOZ The base site of 0x5400400

Click on GPIO registers You can jump to GPIOZ Operation instructions of relevant registers of
Here's the picture :
1) Set the port mode : Set to general output mode 
Address offset:0x00, It means that the address of this register is GPIOA Offset based on the base address of 0x00
Reset value :0xFFFFFFFF Corresponding to the reset value
(volatile The function of is to make the modified variable directly from memery Each time the operation is modified from memory , Instead of operating registers .
Use scenarios :
1: Operate the variables stored in the device address
2. Use other variables in interrupts
3. Variables shared in multitasking
)
#define GPIOZ_PORT_MODE_REGISTER (volatile usigned int*)(0x0x5400400+0x00)// Set register address
*GPIOZ_PORT_MODE_REGISTER=0XFFFFFFFF;// Yes GPIOZ_PORT_MODE_REGISTER Reset
*GPIOZ_PORT_MODE_REGISTER=01<<10;// Yes PZ5 Conduct mode Set up , Set to general output
The mode is set above P5 The mode of is general output ;
Next, set the type of output , Refer to port output register .
2) Set the port output register : Set to open drain output 
#define GPIOZ_PORT_OUTPUT_TYPE_REGISTER (volatile usigned int*)(0x0x5400400+0x04)// Set register address
*GPIOZ_PORT_OUTPUT_TYPE_REGISTER=0X00000000;// Yes GPIOZ_PORT_OUTPUT_TYPE_REGISTER Reset
*GPIOZ_PORT_OUTPUT_TYPE_REGISTER=1<<5;// Yes PZ5 Set it up , Set the output mode to open drain output
The output mode is set above : Open drain output
Next, set the port output speed register : Also called port speed register
3) Port output speed register : Set the speed of the port to High speed
#define GPIOZ_PORT_OUTPUT_SPEED_REGISTER (volatile usigned int*)(0x0x5400400+0x08)// Set register address
*GPIOZ_PORT_OUTPUT_SPEED_REGISTE=0X00000000;// Reset GPIOZ_PORT_OUTPUT_SPEED_REGISTE register
*GPIOZ_PORT_OUTPUT_SPEED_REGISTE=10<<10;// Set up PZ The speed of is Hight speed
Next, set the high and low level of the port , Because it's output , Therefore, the port output data register is selected instead of the port input data register
4) Port output data register 
#define GPIOZ_PORT_OUTPUT_DATA_REGISTER (volatile usigned int*)(0x0x5400400+0x14)// Set register address
*GPIO_PORT_OUTPUT_DATA_REGISTER=0x00000000;// Reset GPIO_PORT_OUTPUT_DATA_REGISTER register
*GPIO_PORT_OUTPUT_DATA_REGISTER=1<<5;// Set up PZ5 High level
summary
#define GPIOZ_PORT_MODE_REGISTER (volatile usigned int*)(0x0x5400400+0x00)// Set register address
#define GPIOZ_PORT_OUTPUT_TYPE_REGISTER (volatile usigned int*)(0x0x5400400+0x04)// Set register address
#define GPIOZ_PORT_OUTPUT_SPEED_REGISTER (volatile usigned int*)(0x0x5400400+0x08)// Set register address
#define GPIOZ_PORT_OUTPUT_DATA_REGISTER (volatile usigned int*)(0x0x5400400+0x14)// Set register address
void init_GPIO_OUT(void)
{
*GPIOZ_PORT_MODE_REGISTER=0XFFFFFFFF;// Yes GPIOZ_PORT_MODE_REGISTER Reset
*GPIOZ_PORT_OUTPUT_TYPE_REGISTER=0X00000000;// Yes GPIOZ_PORT_OUTPUT_TYPE_REGISTER Reset
*GPIOZ_PORT_OUTPUT_SPEED_REGISTE=0X00000000;// Reset GPIOZ_PORT_OUTPUT_SPEED_REGISTE register
*GPIO_PORT_OUTPUT_DATA_REGISTER=0x00000000;// Reset GPIO_PORT_OUTPUT_DATA_REGISTER register
}
void SET_LED(unsigned int x)
{
*GPIOZ_PORT_MODE_REGISTER|=1<<(x<<1);// Yes PZ5 Conduct mode Set up , Set to general output
*GPIOZ_PORT_OUTPUT_TYPE_REGISTER|=1<<5;// Yes PZ5 Set it up , Set the output mode to open drain output
*GPIOZ_PORT_OUTPUT_SPEED_REGISTE|=10<<(x<<1);// Set up PZ The speed of is Hight speed
}
int main(){
init_GPIO_OUT();
SET_LED(5);
while(1){
*GPIO_PORT_OUTPUT_DATA_REGISTER|=1<<5;// Set up PZ5 High level
HAL_Delay(100);
*GPIO_PORT_OUTPUT_DATA_REGISTER&=~(1<<5);// Set up PZ5 Low level
}
}
The above is completed in STM32 Develop the operation of the flow lamp on the board
边栏推荐
- Reading the pointpillar code of openpcdet -- Part 3: Calculation of loss function
- SSH private key realizes login to remote target server
- Canvas fill gradient
- leetcode-114:二叉树展开为链表
- "Shallow in and shallow out" MySQL and InnoDB [it is recommended to collect and share]
- cuda_error_out_of_memory(out of memory怎么办)
- Opencv learning Fourier transform experience and line direction Fourier transform code
- Miscellaneous notes -- a hodgepodge
- Database SQL statement exercise "suggestions collection"
- As a test, how to understand thread synchronization and asynchrony
猜你喜欢

Basic method of black box (function) test

Test cases and defect report templates

matlab----EEGLab查看脑电信号

Leetcode-6131: the shortest dice sequence impossible to get

Debugged PEB (beingdebugged, ntglobalflag)

Sum of two numbers and three numbers

Airtest solves the problem that a password needs to be entered in the process of "automatic packaging" (the same applies to random bullet frame processing)

Force deduction ----- calculate the money of the force deduction bank

Leetcode-6130: designing digital container systems

Leetcode-919: complete binary tree inserter
随机推荐
LeetCode刷题——猜数字大小II#375#Medium
leetcode-6131:不可能得到的最短骰子序列
MySQL inserts three tables with different values. The association condition is the primary foreign key. How about the syntax of the insertion statement?
Leetcode-6126: designing a food scoring system
mysql导入数据时已改成csv utf8文件且文件名为英文,为什么还是导入失败
Wokerman custom write log file
Brush questions with binary tree (4)
Test cases and defect report templates
Database SQL statement exercise "suggestions collection"
The inexplicability of Intel disassembly
Niuke-top101-bm37
Leetcode-6127: number of high-quality pairs
Kali modify the update source (it is not safe to update with this source)
IEC61131 address representation
Reading the pointpillar code of openpcdet -- Part 3: Calculation of loss function
Advanced technology management - how can the team be broken?
sqlx库使用
Trusted and controllable way of Tencent cloud database
Intel base instruction -- bnd
MPI学习笔记(二):矩阵相乘的两种实现方法