【NUCLEO-L452RE测评】+消息队列
<div class='showpostmsg'><p>消息对列我认为就是一个FREERTOS能够识别的数组,相当于全局变量。</p><p>以前我死烦消息队列,因为我认为全局数组完全可以代替它。今天的程序感觉挺好用。</p>
<p>首先用STM32CUBEMX新建项目,直接打开开发板,这样管脚和串口都不用定义。</p>
<p>然后建立两个任务,一个每隔一分钟向消息队列发一个1,另一个任务是收消息队列里的数。</p>
<p>还要建立一个消息队列16个数的默认消息队列:</p>
<p></p>
<p> </p>
<p>然后生成MDK5代码。之后向两个任务中加代码:</p>
<pre>
<code>/* USER CODE BEGIN Header_mySendTaskfun */
/* USER CODE END Header_mySendTaskfun */
void mySendTaskfun(void const * argument)
{
/* USER CODE BEGIN mySendTaskfun */
for(;;)
{
osMessagePut(myQueue01Handle,1,0);
osDelay(1000);
}
/* USER CODE END mySendTaskfun */
}
/* USER CODE BEGIN Header_myReceivefun */
/* USER CODE END Header_myReceivefun */
void myReceivefun(void const * argument)
{
/* USER CODE BEGIN myReceivefun */
osEvent theEvent;
for(;;)
{
theEvent = osMessageGet(myQueue01Handle,osWaitForever);
if (theEvent.status == osEventMessage)
{
printf("Receive message......%d\n",theEvent.value.v);
}
}
/* USER CODE END myReceivefun */
}</code></pre>
<p>而消息队列的声明,STM32CUBEMX早已经定义好了:</p>
<pre>
<code>osMessageQDef(myQueue01, 16, uint16_t);
myQueue01Handle = osMessageCreate(osMessageQ(myQueue01), NULL);
</code></pre>
<p> </p>
<p> </p>
<p>接着就是编译、下载、运行:</p>
<p></p>
<p> </p>
<p> </p>
<p> </p>
<p>可见,FREERTOS的消息队列也不是很复杂。下次评测想写一个串口接收并给消息队列的程序。</p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p><strong><a href="https://bbs.eeworld.com.cn/elecplay/content/148" target="_blank">ST NUCLEO-L452RE测评</a></strong></p>
<p>汇总贴:<a href="https://bbs.eeworld.com.cn/thread-1151850-1-1.html" target="_blank">https://bbs.eeworld.com.cn/thread-1151850-1-1.html </a>、</p>
页:
[1]