[MM32软件] 【MM32 eMiniBoard测评报告】开箱加点灯(寄存器+库函数)

[复制链接]
 楼主| nvjwiciw659 发表于 2020-5-4 23:24 | 显示全部楼层 |阅读模式
本帖最后由 nvjwiciw659 于 2020-5-4 23:33 编辑

很幸运能有这次机会把玩一下MM32的板子,之前智能互联大赛很遗憾与MM32擦肩而过,现在我已脱离学生身份,成了一名头发渐稀的硬件开发者。这次多谢二姨家和MM32的支持,让我能进一步了解MM32这款国产片子。废话不多说,直接开箱欣赏它的美。
3.jpg 2.jpg 1.jpg
然后我们开始正式测试
第一:肯定是先到官网唰唰唰的下载资料咯
图片18.png 图片19.png 图片20.png

不管三七二十一我就是一顿下载
安装MM32-Link驱动,然后我们就可以用板载Link下载程序了
安装芯片包
图片22.png
第二:打开led程序
图片1.png 图片2.png

这时候翻出我们的电路图
图片4.png 图片3.png
打开程序
图片5.png 图片12.png 图片11.png
可以发现电路图中的LED和程序中的1234顺序是反着的,不影响,我们继续
编译下载一气呵成,就能看到四个灯在向我眨眼睛。
以上是寄存器的版本,下面我们看看库函数的版本
图片10.png 图片13.png 图片14.png

还是库函数比较适合傻傻的我,先库函数配置,然后debug看寄存器,注释库函数,改成寄存器,不知道有没有和我一样的老哥呢?
(十天前就已经编辑好了,只差插入图片了,由于新手的原因,插图频频出错,12点之后没能上传,一下子拖了十天,趁五一赶紧搞咯!)
顺便祝大家青年节快乐!

 楼主| nvjwiciw659 发表于 2020-5-5 22:52 | 显示全部楼层
本帖最后由 nvjwiciw659 于 2020-5-5 22:54 编辑

二姨家RTT活动也在进行中,看到我的大师兄在移植RTT_nano,而我个菜**只能直接用RTTsdk包里的开始,不过驱动比较少,进去看了看只有串口
4.jpg
不过差不多也够用,进去测试一下子,来个经典的点灯
  1. static rt_thread_t led0_thread = RT_NULL;
  2. static rt_thread_t led1_thread = RT_NULL;
  3. /********************************************************************************************************
  4. * led_init(void)
  5. ********************************************************************************************************/
  6. void led_init(void)
  7. {
  8.     GPIO_InitTypeDef  GPIO_InitStructure;
  9.     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  10.                 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
  11.     GPIO_InitStructure.GPIO_Pin  =  GPIO_Pin_15;
  12.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  13.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  14.     GPIO_Init(GPIOA, &GPIO_InitStructure);
  15.                 GPIO_InitStructure.GPIO_Pin  =  GPIO_Pin_3;
  16.                 GPIO_Init(GPIOB, &GPIO_InitStructure);
  17. }
  18. /********************************************************************************************************
  19. * led0_thread_entry(void)LED0任务初始化
  20. ********************************************************************************************************/
  21. static void led0_thread_entry(void* parameter)
  22. {        
  23.     while (1)
  24.     {
  25.         GPIO_SetBits(GPIOA, GPIO_Pin_15);
  26.         rt_thread_delay(500);   /* 延时500个tick */
  27.         rt_kprintf("led0_thread running,LED1_ON\r\n");
  28.         
  29.         GPIO_ResetBits(GPIOA, GPIO_Pin_15);   
  30.         rt_thread_delay(500);   /* 延时500个tick */                                 
  31.         rt_kprintf("led0_thread running,LED1_OFF\r\n");
  32.     }
  33. }
  34. /********************************************************************************************************
  35. * led1_thread_entry(void)LED1任务初始化
  36. ********************************************************************************************************/
  37. static void led1_thread_entry(void* parameter)
  38. {        
  39.     while (1)
  40.     {
  41.         GPIO_SetBits(GPIOB, GPIO_Pin_3);
  42.         rt_thread_delay(1000);   /* 延时1000个tick */
  43.         rt_kprintf("led1_thread running,LED1_ON\r\n");
  44.         
  45.         GPIO_ResetBits(GPIOB, GPIO_Pin_3);   
  46.         rt_thread_delay(1000);   /* 延时1000个tick */                                 
  47.         rt_kprintf("led1_thread running,LED1_OFF\r\n");
  48.     }
  49. }
  50. /********************************************************************************************************
  51. * led0_task(void)LED0任务
  52. ********************************************************************************************************/
  53. void led0_task(void)
  54. {
  55.         led0_thread =                          /* 线程控制块指针 */
  56.     rt_thread_create( "led0",              /* 线程名字 */
  57.                       led0_thread_entry,   /* 线程入口函数 */
  58.                       RT_NULL,             /* 线程入口函数参数 */
  59.                       512,                 /* 线程栈大小 */
  60.                       2,                   /* 线程的优先级 */
  61.                       20);                 /* 线程时间片 */
  62.                   
  63.     /* 启动线程,开启调度 */
  64.    if (led0_thread != RT_NULL)
  65.         rt_thread_startup(led0_thread);
  66. }
  67. /********************************************************************************************************
  68. * led1_task(void)LED1任务
  69. ********************************************************************************************************/
  70. void led1_task(void)
  71. {
  72.         led1_thread =                          /* 线程控制块指针 */
  73.     rt_thread_create( "led1",              /* 线程名字 */
  74.                       led1_thread_entry,   /* 线程入口函数 */
  75.                       RT_NULL,             /* 线程入口函数参数 */
  76.                       512,                 /* 线程栈大小 */
  77.                       3,                   /* 线程的优先级 */
  78.                       20);                 /* 线程时间片 */
  79.                   
  80.     /* 启动线程,开启调度 */
  81.    if (led1_thread != RT_NULL)
  82.         rt_thread_startup(led1_thread);
  83. }

  84. int main(void)
  85. {
  86.     led_init();
  87.                 led0_task();
  88.                 led1_task();
  89.     while (1)
  90.     {

  91.     }
  92. }


 楼主| nvjwiciw659 发表于 2020-5-5 23:16 | 显示全部楼层
本帖最后由 nvjwiciw659 于 2020-5-5 23:20 编辑

接下来试试ADC采集
  1. static rt_thread_t adc_thread = RT_NULL;
  2. static rt_thread_t printf_thread = RT_NULL;

  3. #define DISABLE_ALL_CHANNEL     9

  4. __IO uint16_t ADCVAL;
  5. int fValue;

  6. void GPIO_Configuration(void)
  7. {
  8.     GPIO_InitTypeDef GPIO_InitStructure;
  9.     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);   
  10.    
  11.     GPIO_InitStructure.GPIO_Pin  =  GPIO_Pin_1|GPIO_Pin_2;
  12.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  13.     /*将PA1配置为模拟输入*/
  14.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
  15.     GPIO_Init(GPIOA, &GPIO_InitStructure);
  16. }

  17. /********************************************************************************************************
  18. **函数信息 :void ADC1_SingleChannel(uint8_t ADC_Channel_x)      
  19. **功能描述 :配置ADC1单次转换模式
  20. **输入参数 :ADC_Channel_x , x为0~8
  21. **输出参数 :无
  22. **    备注 :
  23. ********************************************************************************************************/
  24. void ADC1_SingleChannel(uint8_t ADC_Channel_x)
  25. {
  26.     ADC_InitTypeDef  ADC_InitStructure;
  27.    
  28.     GPIO_Configuration();
  29.     RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1, ENABLE);
  30.    
  31.     /* Initialize the ADC_PRESCARE values */
  32.     ADC_InitStructure.ADC_PRESCARE = ADC_PCLK2_PRESCARE_16;
  33.     /* Initialize the ADC_Mode member */
  34.     ADC_InitStructure.ADC_Mode = ADC_Mode_Single;
  35.     /* Initialize the ADC_ContinuousConvMode member */
  36.     ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
  37.     /* Initialize the ADC_DataAlign member */
  38.     ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
  39.     /* Initialize the ADC_ExternalTrigConv member */
  40.     ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
  41.     ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
  42.     ADC_Init(ADC1, &ADC_InitStructure);
  43.    
  44.     /*屏蔽所有通道*/
  45.     ADC_RegularChannelConfig(ADC1, DISABLE_ALL_CHANNEL , 0, 0);
  46.     /*使能选中通道,后面参数保留*/
  47.     ADC_RegularChannelConfig(ADC1, ADC_Channel_x, 0, ADC_SampleTime_28_5Cycles);
  48.    
  49.     ADC_Cmd(ADC1, ENABLE);
  50. }

  51. /********************************************************************************************************
  52. **函数信息 :ADC1_SingleChannel_Get()      
  53. **功能描述 :获取ADC1转换数据
  54. **输入参数 :ADC_Channel_x , x为0~8
  55. *puiADData ,ADC1实际转换数据
  56. **输出参数 :ucStatus ,0 表示数据获取失败,1 表示成功
  57. ********************************************************************************************************/
  58. u16 ADC1_SingleChannel_Get(uint8_t ADC_Channel_x)
  59. {
  60.     u16 puiADData;
  61.     /*ADCR寄存器的ADST位使能,软件启动转换*/
  62.     ADC_SoftwareStartConvCmd(ADC1, ENABLE);
  63.     while(ADC_GetFlagStatus(ADC1,ADC_FLAG_EOC)==0);
  64.     ADC_ClearFlag(ADC1, ADC_FLAG_EOC);
  65.     puiADData=ADC_GetConversionValue(ADC1);
  66.     return puiADData;
  67. }

  68. /********************************************************************************************************
  69. **函数信息 :Get_Adc_Average(uint8_t ADC_Channel_x,uint8_t times)     
  70. **功能描述 :获取几次ADC1采样值的平均值
  71. **输入参数 :ADC_Channel_x , x为0~8
  72. **输出参数 :puiADData为ADC读到的值
  73. ********************************************************************************************************/
  74. u16 Get_Adc_Average(uint8_t ADC_Channel_x,uint8_t times)
  75. {
  76.     u32 temp_val=0;
  77.     u8 t;
  78.     u8 delay;
  79.     for(t=0;t<times;t++)
  80.     {
  81.         temp_val+=ADC1_SingleChannel_Get(ADC_Channel_x);
  82.         for(delay=0;delay<100;delay++);
  83.     }
  84.     return temp_val/times;
  85. }         

  86. /********************************************************************************************************
  87. * led_init(void)
  88. ********************************************************************************************************/
  89. void led_init(void)
  90. {
  91.     GPIO_InitTypeDef  GPIO_InitStructure;
  92.     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
  93.                 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
  94.     GPIO_InitStructure.GPIO_Pin  =  GPIO_Pin_15;
  95.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  96.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  97.     GPIO_Init(GPIOA, &GPIO_InitStructure);
  98. }

  99. void ADC_thread_entry(void* parameter)
  100. {
  101.         while(1)
  102.         {
  103.                 ADCVAL=Get_Adc_Average(ADC_Channel_1,5);
  104.     fValue = (int) (ADCVAL * 825) >> 10;
  105.                 rt_thread_delay(500);   /* 延时500个tick */
  106.         }
  107. }

  108. void PRINTF_thread_entry(void* parameter)
  109. {
  110.         while(1)
  111.         {
  112.                 rt_kprintf("\r\nADC1_CH_1=0x%04X\r\n",ADCVAL);
  113.                 rt_kprintf("ADC1_CH_1=%dmV\r\n",fValue);
  114.                 rt_thread_delay(500);   /* 延时500个tick */                                                
  115.         }
  116. }

  117. /********************************************************************************************************
  118. * adc_task(void)adc任务
  119. ********************************************************************************************************/
  120. void adc_task(void)
  121. {
  122.         adc_thread =                          /* 线程控制块指针 */
  123.     rt_thread_create( "adc",              /* 线程名字 */
  124.                       ADC_thread_entry,   /* 线程入口函数 */
  125.                       RT_NULL,             /* 线程入口函数参数 */
  126.                       512,                 /* 线程栈大小 */
  127.                       2,                   /* 线程的优先级 */
  128.                       20);                 /* 线程时间片 */
  129.                   
  130.     /* 启动线程,开启调度 */
  131.    if (adc_thread != RT_NULL)
  132.         rt_thread_startup(adc_thread);
  133. }
  134. /********************************************************************************************************
  135. * adc_task(void)adc任务
  136. ********************************************************************************************************/
  137. void printf_task(void)
  138. {
  139.         printf_thread =                          /* 线程控制块指针 */
  140.     rt_thread_create( "printf",              /* 线程名字 */
  141.                       PRINTF_thread_entry,   /* 线程入口函数 */
  142.                       RT_NULL,             /* 线程入口函数参数 */
  143.                       512,                 /* 线程栈大小 */
  144.                       3,                   /* 线程的优先级 */
  145.                       20);                 /* 线程时间片 */
  146.                   
  147.     /* 启动线程,开启调度 */
  148.    if (printf_thread != RT_NULL)
  149.         rt_thread_startup(printf_thread);
  150. }

  151. void mmrtt_init(void)
  152. {
  153.         ADC1_SingleChannel( ADC_Channel_1);
  154.         adc_task();
  155.         printf_task();
  156. }

  157. int main(void)
  158. {
  159.     led_init();
  160.                 mmrtt_init();
  161.     while (1)
  162.     {

  163.     }
  164. }

5.jpg
nawu 发表于 2020-6-1 16:35 | 显示全部楼层
非常感谢楼主分享
qcliu 发表于 2020-6-1 16:36 | 显示全部楼层
板子很漂亮啊
tfqi 发表于 2020-6-1 16:36 | 显示全部楼层
代码是自己写的吗 很漂亮
wiba 发表于 2020-6-1 16:36 | 显示全部楼层
楼主好厉害
zljiu 发表于 2020-6-1 16:37 | 显示全部楼层
真是好羡慕楼主呀
您需要登录后才可以回帖 登录 | 注册

本版积分规则

13

主题

79

帖子

0

粉丝
快速回复 返回顶部 返回列表