当前位置:网站首页>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
边栏推荐
- Leetcode-919: complete binary tree inserter
- Huatai Securities account opening process, is it safe to open an account on your mobile phone
- leetcode-919:完全二叉树插入器
- Niuke-top101-bm38
- Use of C log4net: add file name and line number to the output log content; Repackaged class output file name and line number
- cts测试步骤(卡西欧cts200测试)
- Hello, I'd like to ask questions about C and database operation.
- Airtest解决“自动装包”过程中需要输入密码的问题(同适用于随机弹框处理)
- Miscellaneous notes -- a hodgepodge
- Character function and string function (2)
猜你喜欢

Leetcode-6130: designing digital container systems

Leetcode-6125: equal row and column pairs

leetcode-6130:设计数字容器系统

leetcode-6131:不可能得到的最短骰子序列

Airtest解决“自动装包”过程中需要输入密码的问题(同适用于随机弹框处理)

Huawei occupies half of the folding mobile phone market, proving its irreplaceable position in the high-end market
![[online tutorial] iptables official tutorial -- learning notes 2](/img/7d/5f8328d1b4c8878f17c95d2658d2d6.jpg)
[online tutorial] iptables official tutorial -- learning notes 2

IEC61131 address representation

Interface testing tool restlet client

476-82(322、64、2、46、62、114)
随机推荐
Programmer's Guide to health quenching 5: introduction to sports Basics
两数,三数之和
[technical dry goods] how to ensure the idempotency of the interface?
Apple estimates that iPhone will give up the Chinese market, and the Chinese industrial chain needs to consider living a hard life
租房二三事
Recommend a website that converts curl commands into PHP code & a website that initiates and executes curl requests online
牛客-TOP101-BM37
Array of arm disassembly
Hello, I'd like to ask questions about C and database operation.
Cesium 多边形渐变色纹理(Canvas)
When facing complex problems, systematic thinking helps you understand the essence of the problem
图片怎么存储到数据库里「建议收藏」
Reading the pointpillar code of openpcdet -- Part 3: Calculation of loss function
Explain the principle of MySQL master-slave replication in detail
【C语言入门】ZZULIOJ 1016-1020
Pycharm跑程序时自动进入测试模式
Force deduction ----- calculate the money of the force deduction bank
wokerman 自定义写入日志文件
Leetcode-155: minimum stack
leetcode-6129:全 0 子数组的数目