本帖最后由 夜声 于 2022-5-16 14:56 编辑
一,开发板开箱以及接线
本次测评的开发板来自于大掌柜的厚爱,让我有这次测评的机会,在这里谢谢大掌柜。本次的主控芯片为APM32E103ZET6,可以理解为APM32F103ZET6的加强版, 在主频上有所提升。工作频率为120MHZ,Flash为512KB,SRAM为128KB,板载的是TYPE-B接口和标准JTAG/SWD调试接口。刚接触这个芯片,还不了解,所以首先第一步是要把资料找齐。这里是官网链接https://www.geehy.com/
下载这个板子的资料到自己的电脑,这里官网没有进行打包,所以自己整理一下就可以。
打开板子原理图,查看SWD下载接口,本次采用ST-LINK和USB转TTL进行开发板的调试。由于我没有TYPE-B的USB线,所以供电使用ST-LINK上带的电源供电即可。
二、程序修改 打开SDK中的USART程序代码,我对GPIO, USART进行了封装,并在USART中增加了printf函数,方便调试。
对串口函数进行封装- #include "usart.h"
- #include "stdio.h"
- #define USART_REC_LEN 200
- unsigned short USART_RX_BUF[USART_REC_LEN]; //接收数组
- unsigned short USART_RX_STA=0; //接收状态标志位
- #if 1
- #pragma import(__use_no_semihosting)
- //标准库需要的支持函数
- struct __FILE
- {
- int handle;
- };
- FILE __stdout;
- //定义_sys_exit()以避免使用半主机模式
- _sys_exit(int x)
- {
- x = x;
- }
- //重定义fputc函数
- int fputc(int ch, FILE *f)
- {
- //sts 状态寄存器
- //DATA 数据寄存器
- while((USART1->STS&0X40)==0);//循环发送,直到发送完毕
- USART1->DATA = (u8) ch;
- return ch;
- }
- #endif
- void usart_init(unsigned int bound)
- {
- GPIO_Config_T gpio_config;
- USART_Config_T usart_config;
-
- RCM_EnableAPB2PeriphClock( RCM_APB2_PERIPH_GPIOA);
- RCM_EnableAPB2PeriphClock( RCM_APB2_PERIPH_USART1);
-
- //TX
- gpio_config.mode = GPIO_MODE_AF_PP;
- gpio_config.pin = GPIO_PIN_9;
- gpio_config.speed = GPIO_SPEED_50MHz;
- GPIO_Config(GPIOA, &gpio_config);
- //RX
- gpio_config.mode = GPIO_MODE_IN_FLOATING;
- gpio_config.pin = GPIO_PIN_10;
- GPIO_Config(GPIOA, &gpio_config);
-
-
-
- usart_config.baudRate = bound;
- usart_config.wordLength = USART_WORD_LEN_8B;
- usart_config.stopBits = USART_STOP_BIT_1;
- usart_config.parity = USART_PARITY_NONE ;
- usart_config.mode = USART_MODE_TX_RX;
- usart_config.hardwareFlow = USART_HARDWARE_FLOW_NONE;
- USART_Config(USART1, &usart_config);
- NVIC_EnableIRQRequest(USART1_IRQn, 2,3);
- USART_Enable(USART1);
- USART_EnableInterrupt(USART1, USART_INT_RXBNE);
- }
- void USART1_IRQHandler (void)
- {
- u8 Res;
- if(USART_ReadIntFlag(USART1, USART_INT_RXBNE) != RESET) //接收中断(接收到的数据必须是0x0d 0x0a结尾)
- {
- Res =USART_RxData(USART1); //读取接收到的数据
-
- if((USART_RX_STA&0x8000)==0)//接收未完成
- {
- if(USART_RX_STA&0x4000)//接收到了0x0d
- {
- if(Res!=0x0a)USART_RX_STA=0;//接收错误,重新开始
- else USART_RX_STA|=0x8000; //接收完成了
- }
- else //还没收到0X0D
- {
- if(Res==0x0d)USART_RX_STA|=0x4000;
- else
- {
- USART_RX_BUF[USART_RX_STA&0X3FFF]=Res ;
- USART_RX_STA++;
- if(USART_RX_STA>(USART_REC_LEN-1))USART_RX_STA=0;//接收数据错误,重新开始接收
- }
- }
- }
- }
- }
- //usart.h文件
- #ifndef _usart_h
- #define _usart_h
- #include "apm32e10x_usart.h"
- #include "apm32e10x_gpio.h"
- #include "apm32e10x_rcm.h"
- #include "apm32e10x_misc.h"
- void usart_init(unsigned int bound);
- #endif
主函数:
- /***********************************************************************/
- //主函数
- #include "apm32e10x.h"
- #include "led.h"
- #include "adc.h"
- #include "usart.h"
- #include "delay.h"
- #include "sys.h"
- #include "usart.h"
- #include "stdio.h"
- int main(void)
- {
- rcc_config();
- nvic_config();
- led_init();
- adc_init();
- usart_init(115200);
- while (1)
- {
- led_on;
- delay_ms(200);
- led_off;
- delay_ms(200);
-
- printf("hello world \r\n");
- }
- }
结果:
 printf打印函数使用成功。
|