boming 发表于 2019-6-19 05:44

【GE32E231_DIY】FreeRTOS+DAP_RTT+多功能按键+USART_DMA再加入FREEMODBUS

<p>FreeRTOS+DAP_RTT+多功能按键+USART_DMA再加入FREEMODBUS</p>

<p>到这里,项目一步一步实现了,一步一步调试真不容易。感谢家人的支持,成有时间码代码。</p>

<p></p>

<p>freemodbus主要思想是用状态机实现,发送&mdash;中断。接收&mdash;中断,硬时间确认,加一轮询</p>

<p>int main(void)<br />
{<br />
&nbsp;&nbsp; &nbsp;systick_config();<br />
//&nbsp;&nbsp; &nbsp;button_enable();&nbsp;<br />
//&nbsp;&nbsp; &nbsp;CreateSoftwareTime();<br />
&nbsp;&nbsp; &nbsp;LED_Init();<br />
&nbsp;&nbsp; &nbsp;eMBInit(MB_RTU, 0x01, 1, 115200, &nbsp;MB_PAR_NONE);//初始化Freemodbus数据,定时器,串口(包括中断),工作装态<br />
&nbsp;&nbsp; &nbsp;eMBEnable(); //启动接收中断,等待串口数据到来<br />
&nbsp;&nbsp; &nbsp;/* Create tasks. */<br />
&nbsp;&nbsp; &nbsp;prvCreateTasks();<br />
&nbsp;&nbsp; &nbsp;NVIC_SetPriority_Init();<br />
&nbsp;&nbsp; &nbsp;NVIC_EnableIRQ_Init();<br />
//&nbsp;&nbsp; &nbsp;TIMER2_Config();<br />
&nbsp;&nbsp; &nbsp;/* Start scheduler. */<br />
&nbsp;&nbsp; &nbsp;vTaskStartScheduler();<br />
&nbsp;&nbsp; &nbsp;/* Will not get here if the scheduler starts successfully. &nbsp;If you do end up<br />
&nbsp;&nbsp; &nbsp;here then there wasn&#39;t enough heap memory available to start either the idle<br />
&nbsp;&nbsp; &nbsp;task or the timer/daemon task. &nbsp;https://www.freertos.org/a00111.html */<br />
&nbsp;&nbsp; &nbsp;for( ; ; )<br />
&nbsp;&nbsp; &nbsp;{<br />
&nbsp;&nbsp; &nbsp;}</p>

<p>}</p>

<p>&nbsp;</p>

<p>创建一个轮询任务。ModbusSlavePoll<br />
static void prvCreateTasks( void )<br />
{<br />
&nbsp;&nbsp; &nbsp;xTaskCreate(vLED1Task, &nbsp; &nbsp;&nbsp; &nbsp;//* 任务函数 &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;vLED1Task&quot;, &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;//* 任务名 &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;configMINIMAL_STACK_SIZE, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;//* 任务栈大小,单位word,也就是4字节&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NULL, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//* 任务参数 &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;configMAX_PRIORITIES - 3, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//* 任务优先级<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;xHandleLED1Task); &nbsp;//* 任务句柄 &nbsp;<br />
&nbsp;&nbsp; &nbsp;xTaskCreate(vLED2Task, &nbsp; &nbsp;&nbsp; &nbsp;//* 任务函数 &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;vLED2Task&quot;, &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;//* 任务名 &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;configMINIMAL_STACK_SIZE, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;// 任务栈大小,单位word,也就是4字节&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NULL, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//* 任务参数 &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;configMAX_PRIORITIES - 3, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// 任务优先级<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;xHandleLED2Task); &nbsp;//* 任务句柄 &nbsp;<br />
&nbsp;&nbsp; &nbsp;xTaskCreate(vLED3Task, &nbsp; &nbsp;&nbsp; &nbsp;//* 任务函数 &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;vLED3Task&quot;, &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;//* 任务名 &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;configMINIMAL_STACK_SIZE, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;// 任务栈大小,单位word,也就是4字节&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NULL, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//* 任务参数 &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;configMAX_PRIORITIES - 3, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// 任务优先级<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;xHandleLED3Task); &nbsp;//* 任务句柄 &nbsp;<br />
&nbsp;&nbsp; &nbsp;xTaskCreate(vLED4Task, &nbsp; &nbsp;&nbsp; &nbsp;//* 任务函数 &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;vLED4Task&quot;, &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;//* 任务名 &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;configMINIMAL_STACK_SIZE, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;// 任务栈大小,单位word,也就是4字节&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NULL, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//* 任务参数 &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;configMAX_PRIORITIES - 3, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// 任务优先级<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;xHandleLED4Task); &nbsp;//* 任务句柄&nbsp;<br />
/*&nbsp;&nbsp; &nbsp;xTaskCreate(RTT_PrintfTask,//std_PrintfTask &nbsp; &nbsp;&nbsp; &nbsp;// 任务函数 &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;vprintfTask&quot;, &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;// 任务名 &nbsp; &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;configMINIMAL_STACK_SIZE+50, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;// 任务栈大小,单位word,也就是4字节&nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NULL, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// 任务参数 &nbsp;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;configMAX_PRIORITIES - 3, &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;// 任务优先级<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;xHandleprintfTask); &nbsp;// 任务句柄 &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;<br />
*/ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br />
&nbsp;&nbsp; &nbsp;xTaskCreate(ModbusSlavePoll,&nbsp;&nbsp; &nbsp;//* 任务函数 &nbsp;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&quot;ModbusSlavePoll&quot;,&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//* 任务名&nbsp;&nbsp; &nbsp; &nbsp;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;configMINIMAL_STACK_SIZE+300, //* 任务栈大小,单位word,也就是4字节&nbsp;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;NULL,&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//* 任务参数 &nbsp;<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;configMAX_PRIORITIES - 3,&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;//* 任务优先级<br />
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&amp;xHandleModbusSlavePoll); &nbsp;//* 任务句柄&nbsp;<br />
}</p>

<p>&nbsp;</p>

<p></p>

<p>&nbsp;</p>

<p>欢迎大家跟帖交流</p>

人去搂空 发表于 2019-6-19 09:59

<p>谢谢分享!</p>

y1z2f4 发表于 2021-3-5 21:42

<p>下载学习,谢谢分享!</p>

ap0405209 发表于 2024-8-18 16:08

<p>非常感谢楼主的提供,E231应该和E230没什么区别吧?放到230应该可以直接运行~~我猜</p>
页: [1]
查看完整版本: 【GE32E231_DIY】FreeRTOS+DAP_RTT+多功能按键+USART_DMA再加入FREEMODBUS