STM32初学demo——GPIO/USART/NVIC/DMA

写了点儿简单的demo,用于STM32F10X的初学者进行参考,包含:

1、LED操作:单纯LED输出、按键控制LED输出(通过主函数while查询按键输入状态、配置按键中断输入状态)

2、USART操作:USART中断输入输出、USART的DMA输出

 main.c贴在下面了,代码包见附件

#include "board.h"
#include <rtthread.h>
#include "led.h"
#include "uart.h"
#include "dma.h"

int main(void){
	/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 点亮一个LED灯的代码,初学者看这部分↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
	/*
	LED_Periph_Config();
	while(1){
				
		//Notes:study level 0: Light up an LED
		//LED(ON);
		//rt_thread_delay(5);
		//LED(OFF);
		
		//Notes:study level 1:The led is controlled by key input
		//get_key_status();
		//do_led_output();		
		
		//Notes:study level 2: Key input is configured in interrupt mode to control led
		//Notes:study level 2:In this code implementation, only need to wait for interrupts, and don't need to write code in the loop
		//Notes:study level 2:Need to write the key interrupt service function in stm32f10x_it.c
	}
	*/
	/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ 点亮一个LED灯的代码,初学者看这部分 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
	
	/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 实现UART串口收发的代码,进阶1 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
	/*
	//Notes:study level 3: Control the sending and receiving of UART1 through interrupt
	//Notes:study level 3:Need to write the uart interrupt service function in stm32f10x_it.c
	UART1_Periph_Config();
	uint16_t i;
	while(1){
		UART1_Receive();
		if(USART1_RX_LEN){
			UART1_Send("["__DATE__" - "__TIME__"] receive times %d",++i);
		}		
	}
	//Notes else:if you do not kown about how to send data,read more in usart.c
	*/		
	/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ 实现UART串口收发的代码,进阶1 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
	
	/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ DMA实现UART串口发送的代码,进阶2 ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
	
	//Notes:study level 4:Control the sending and receiving of UART1 through DMA(TX) && interrupt(RX)
	//i need test:DMA RX
	/*
	uint16_t i;
	LED_Periph_Config();
	UART1_Periph_Config();
	UART1_TX_DMA_Config();
	for(i = 0; i < USART1_TX_MAX; i++){
		USART1_TX_BUF[i] = 0xaa;
	}
	USART_DMACmd(USART1,USART_DMAReq_Tx,ENABLE);  // USART1 向 DMA发出TX请求 
	LED(ON);
	while(1);
	*/
	/*↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ DMA实现UART串口发送的代码,进阶2 ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*/
		
}
  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值