1、先晒下拿到板子图片
2、搭建工程,
硬件:主要是使用板的CH340串口与芯片的PA2和PA3相连
2.1、开发环境使用Keil 5.31版本,下载器使用ULINK2
2.2、工程文件说明,如图
搭建工程详细步骤就不说了,不懂百度以下,一大堆,嘿嘿,工程如下图
3、串口驱动源文件与头文件
- /*******************************************************************
- ** Header:bsp_uart.c
- ** File describtion:
- ** Author:pandy
- ** Date:2024-10-20
- *******************************************************************/
- #include "Bsp_uart.h"
- //中断服务函数
- void UART1_IRQHandler(void)
- {
- if ( UART1 -> LSR_b.RDR )
- {
- if( ( UART1 -> LSR_b.THRE ) )
- UART1 -> THR = UART1 -> RBR;
- }
- }
- //串口初始化
- void UART1_Init(void)
- {
- //init UART pin
- PA2_INIT( PA2_UART1_TX );
- PA3_INIT( PA3_UART1_RX );
- //initial UART1
- UART_Open( UART1, UART_BAUD_RATE,UART_NO_PARITY, UART_TRIGGER_LEVEL_1_BYTE, UART_ONE_STOP_BIT );
- UART_EnableInt( UART1, UART_RX_INT );//使能接受中断
- NVIC_EnableIRQ( UART1_IRQn );
- retarget_uart = UART1;
- }
- #ifndef __BSP_UART__H_
- #define __BSP_UART__H_
- #include "me32f103_uart.h"
- #include "me32f103_gpio.h"
- #include "me32f103_ioconfig.h"
- #define UART_BAUD_RATE 115200
- extern UART0_Type * retarget_uart;
- extern void UART1_Init(void);
- #endif
4、定时器的源文件与头文件
- #ifndef __BSP_TIME__H_
- #define __BSP_TIME__H_
- #include "me32f103_timer.h"
- #define TIME_IS_1MS 1000
- typedef struct{
- uint32_t time_10ms_cnt;
- uint32_t time_1s_cnt;
- }timeContrl;
- extern timeContrl TimeIs;
- extern void TIME0_Init(void);
- extern void delay_ms( uint32_t cnt);
- #endif
- #ifndef __BSP_TIME__H_
- #define __BSP_TIME__H_
- #include "me32f103_timer.h"
- #define TIME_IS_1MS 1000
- typedef struct{
- uint32_t time_10ms_cnt;
- uint32_t time_1s_cnt;
- }timeContrl;
- extern timeContrl TimeIs;
- extern void TIME0_Init(void);
- extern void delay_ms( uint32_t cnt);
- #endif
5、main文件
- /*******************************************************************
- ** Header: main.c
- ** File describtion: Experiment with ADC and UART.
- ** Author:pandy
- ** Date:2024-10-20
- **Thanks to Mesilicon and the mbb.eet community for sponsoring
- the ME32F103 Demokit for my use and support.
- *******************************************************************/
- #include "main.h"
- void system_init(void)
- {
- SYSCON->CLKBYPASSEN =0x3; //CPU work at 30MHz
- SystemCoreClockUpdate();
- delay_ms(500);
- UART1_Init();
- TIME0_Init();
- }
- void logMessages(void)
- {
- printf("pandy\n");
- printf("2024-10-20\n");
- printf("Thanks to mbb.eet!\n");
- printf("Welcome to ME32F103 Demokit!\n");
- }
- //主函数
- int main(void)
- {
- system_init();
- logMessages();
- while(1)
- {
- printf("Welcome to ME32F103 Demokit!\n");
- delay_ms(500);
- }
- }
- #ifndef __MAIN__H_
- #define __MAIN__H_
- #include "me32f103.h"
- #include "stdio.h"
- #include "me32f103_sys.h"
- #include "me32f103.h"
- #include "Bsp_time.h"
- #include "Bsp_uart.h"
- #endif
上调试完成的效果如下图:
由于时间比较匆忙,今天UART分享到这来啦!!后续还得把开发板的排针焊上去才好调其它功能!