蓝桥杯嵌入式类比赛经验分享

本文是作者参加第八届蓝桥杯嵌入式大赛的经验分享,详细介绍了竞赛板的使用和部分外设配置,强调了STM32的时钟、GPIO、中断、ADC和PWM的配置,提醒参赛者需要熟练掌握相关知识,如外设驱动编写。作者还反思了自身在比赛中因自负导致的失误,提醒大家避免犯同样的错误。此外,文中还涉及了STM32的基础知识和部分客观题,供读者学习参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

第八届蓝桥杯大赛(嵌入式组)

    蓝桥杯的嵌入式组是Stm32rbt6单片机的编程比赛,我想对于学习电子信息工程专业的同学这不是一个陌生的名词,如果你是电信专业的大四同学却没有听说过msp430或者stm32,或许你应该审视一下自己是否懈怠了4年时光,不过一般大四的同学是看不见我这篇文章的。

    看到这篇文章的人大多是要参加这个比赛的同学,我在上次比赛中只获得了国二,差一丢丢国一这是非常令人遗憾的事情,我会在接下来的文章中介绍我的经验,和产生遗憾的原因。
  • 竞赛板介绍

  • 竞赛板使用经验

  • 部分外设的配置

  • 要求熟练掌握的知识

  • 错失国一的自我反省

  • 客观题部分


竞赛板介绍

  • 图片展示
    这里写图片描述
    这里写图片描述
  • 介绍
    第一块板子是主板,第二块是扩展板,他们的资料可以通过加蓝桥杯嵌入式相关的QQ群中去下载,有空的话我也可以分享出来。

竞赛板使用经验

①下载程序并不是使用Stlink或者Jlink,而是CooCox
②使用蜂鸣器的时候是需要将PB4短接帽接上,而一般正常使用时是不可短接PB4的,否则无法下载程序。理由我就不细说了,PB4的主要功能是J-RST其复用功能才是普通IO口,我会在后面附上蜂鸣器的相关配置。

部分外设的配置

  • 在此之前我还是希望对读者的基础知识有一点小小的要求
    1.C语言功底至少在结构体之后链表之前即可。
    2.熟悉Uart,SPI,I2C三种基础通信协议(我这里的熟悉是指SPI和I2C能够盲打)

时钟配置

用到哪些外设就开启对应时钟,注意APB1和APB2所对应的外设

void RCC_Configuration(void)
{
/* TIM clock enable */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
/* GPIO clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO , ENABLE);
}

GPIO配置

用多少添加多少

void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
 /* GPIOC Configuration:Pin6, 7, 8 and 9 as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_8  ;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2  ;    //BUTTON
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

//  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_2  ;      //UASRT2T
//  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
//  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
//  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_3  ;    //UASRT2R
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);


  GPIO_InitStructure.GPIO_Pin =  0XFF00  ;    //LED
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOC, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_2  ;    //LED
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_0  ;    //adc
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  GPIO_PinRemapConfig(GPIO_Remap_SWJ_NoJTRST, ENABLE);
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4  ;    //BEER
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2  ;  //CAP
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_6 | GPIO_Pin_7  ; //PWM_OUT
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
}

中断配置

哪些外设需要使用中断就在此处开启,用多少开多少

void NVIC_Configuration(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;

  /* Enable the TIM2 global Interrupt */
  NVIC_PriorityGroupConfig( NVIC_PriorityGroup_1 );

  NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;             //BUTTON
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority =5;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;           //USART2
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值