Toggle navigation
首页
问答
文章
积分商城
专家
专区
更多专区...
文档中心
返回主站
搜索
提问
会员
中心
登录
注册
RT-Thread Studio
第一次用RT Thread Studio+FreeModbusRTU碰到奇怪问题......
发布于 2020-06-11 10:17:30 浏览:1938
订阅该版
菜鸟一个,以前用过UCOS,RT Thread以前也关注过,中途好几年去搞设备了没有再用单片机,现在因项目的原因又倒回来发现RT Thread居然有Studio了:victory: 果断下了试了,因项目要用到ModbusRTU,以前用AVR的时个就是自已写的。在RT Thread Studio中发现有现成的的库,太牛了。。。然后苦B的日子来了.... 程序中共两个线程:1、LED工作闪灯 2、ModbusRTU 从机 开始:下了LibModbus....然后网上的例子看了,群里的网友也帮我发了例了。。。。结果一运行就死机。。。然后苦B了4天在后果断放弃 然后:在群里网友的支持下又下了FreeModbus... 居然不死机了还能通讯上:lol 但....高兴太早,好景不长,开发板重起后又连上,数据连接超时,过了一个多小时 又能通讯了,这样反反复复...呃、想死的心的都有了 再然后:特无聊时把编译优化由-O0改为-OS 居然反复重起通讯都不会断,神马情况:Q 我把所有的代码上传,请高手帮忙分板下,谢谢! **MAIN.C: 开启两个线程** #include
#include "thread_LedWork.h" #include "thread_ModbusRTUWork.h" #define DBG_TAG "main" #define DBG_LVL DBG_LOG #include
int main(void) { thread_task_LedWork(); thread_task_ModbusRTUWork(); return RT_EOK; } **thread_LedWork.c 工作闪灯线程** #include
#include
#include
#include
#include "thread_LedWork.h" #define LED0_PIN GET_PIN(C, 3) /* 线程入口函数 */ static void thread_entry_LedWork(void *parameter) { rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT); while (1) { rt_pin_write(LED0_PIN, PIN_HIGH); rt_thread_mdelay(500); rt_pin_write(LED0_PIN, PIN_LOW); rt_thread_mdelay(500); } } /* 使用静态线程时,线程的栈需要设置字节对齐 */ ALIGN(RT_ALIGN_SIZE) static rt_uint8_t thread_stack[512]; static struct rt_thread tid_LedWork; /* 线程创建 */ int thread_task_LedWork(void) { rt_err_t LedWork_thread; /* 静态创建线程 */ /* 初始化线程 1,名称是 LedWork,入口是 thread_entry_LedWork*/ LedWork_thread = /* 线程控制块指针 */ rt_thread_init(&tid_LedWork, "LedWork", /* 线程名字 */ thread_entry_LedWork, /* 线程入口函数 */ RT_NULL, /* 线程入口函数参数 */ thread_stack, /* 线程栈起始地址 */ 512, /* 线程栈大小 */ 10, /* 线程的优先级 */ 20); /* 线程时间片 */ /* 启动线程 */ if (LedWork_thread == RT_EOK) rt_thread_startup(&tid_LedWork); return 0; } **thread_ModbusRTUWork.c MODBUS线程** #include
#include
#include
#include
#include
#include
#include
#include "thread_ModbusRTUWork.h" #include "user_mb_app.h" /* 线程入口函数 */ static void thread_entry_ModbusRTUWork(void *parameter) { // 端口选择Port1 即Uart1 eMBInit(MB_RTU, 0x01, 2, 19200, MB_PAR_EVEN); eMBEnable(); while (1) { eMBPoll(); } } /* 使用静态线程时,线程的栈需要设置字节对齐 */ ALIGN(RT_ALIGN_SIZE) static rt_uint8_t thread_stack[512]; static struct rt_thread tid_ModbusRTUWork; /* 线程创建 */ int thread_task_ModbusRTUWork(void) { rt_err_t ModbusRTUWork_thread; /* 静态创建线程 */ /* 初始化线程 1,名称是 ModbusRTUWork,入口是 thread_entry_ModbusRTUWork*/ ModbusRTUWork_thread = /* 线程控制块指针 */ rt_thread_init(&tid_ModbusRTUWork, "ModbusRTUWork", /* 线程名字 */ thread_entry_ModbusRTUWork, /* 线程入口函数 */ RT_NULL, /* 线程入口函数参数 */ thread_stack, /* 线程栈起始地址 */ 512, /* 线程栈大小 */ 2, /* 线程的优先级 */ 20); /* 线程时间片 */ /* 启动线程 */ if (ModbusRTUWork_thread == RT_EOK) rt_thread_startup(&tid_ModbusRTUWork); return 0; } 然后在board.h中开启了串口2 #define BSP_USING_UART2 #define BSP_UART2_TX_PIN "PA2" #define BSP_UART2_RX_PIN "PA3" 就这些了,请高手帮忙看下问题在哪?应该是还有没开启的地方,菜鸟一枚,请高人指点:'(
查看更多
1
个回答
默认排序
按发布时间排序
碧蓝深邃
2020-12-20
这家伙很懒,什么也没写!
我都没成功通讯过。。一直超时。。
撰写答案
登录
注册新账号
关注者
0
被浏览
1.9k
关于作者
yinliang
这家伙很懒,什么也没写!
提问
1
回答
3
被采纳
0
关注TA
发私信
相关问题
1
rt_thread studio 啥时候能用呢
2
RT_Thread使用反馈帖子
3
RTT studio 下的 AT指令问题。
4
什么时候RTT Sdudio支持Ubuntu,Deepin和UOS操作系统
5
rt thread Studio 关于J-LINK下载问题
6
RT-Thread studio 调试设置问题
7
RTT-Studio 如何设置调试配置参数?
8
rt_thread studio 软件包配置
9
RT-Studio目前只能开发STM32的项目吗?
10
rtt studio 生成hex名字修改
推荐文章
1
RT-Thread应用项目汇总
2
玩转RT-Thread系列教程
3
国产MCU移植系列教程汇总,欢迎查看!
4
机器人操作系统 (ROS2) 和 RT-Thread 通信
5
五分钟玩转RT-Thread新社区
6
【技术三千问】之《玩转ART-Pi》,看这篇就够了!干货汇总
7
关于STM32H7开发板上使用SDIO接口驱动SD卡挂载文件系统的问题总结
8
STM32的“GPU”——DMA2D实例详解
9
RT-Thread隐藏的宝藏之completion
10
【ART-PI】RT-Thread 开启RTC 与 Alarm组件
最新文章
1
RT-thred的stm32h723对应bsp包CubeMX添加其他外设报错
2
RT-Thread中的time溢出问题,时间戳溢出,解决方法
3
ART-PI使用env驱动ETH网卡,pc和板子可以ping通
4
SystemView线程名字不显示
5
只用网页也能跑RT-Smart 无门槛腾讯Cloud studio + smart-build快速构建
热门标签
RT-Thread Studio
串口
Env
LWIP
SPI
AT
Bootloader
Hardfault
CAN总线
FinSH
ART-Pi
DMA
USB
文件系统
RT-Thread
SCons
RT-Thread Nano
线程
MQTT
STM32
RTC
FAL
rt-smart
I2C_IIC
ESP8266
UART
cubemx
WIZnet_W5500
ota在线升级
PWM
BSP
flash
freemodbus
packages_软件包
潘多拉开发板_Pandora
定时器
ADC
GD32
flashDB
socket
编译报错
中断
Debug
rt_mq_消息队列_msg_queue
keil_MDK
ulog
SFUD
msh
C++_cpp
MicroPython
本月问答贡献
RTT_逍遥
8
个答案
2
次被采纳
三世执戟
7
个答案
1
次被采纳
KunYi
6
个答案
1
次被采纳
winfeng
2
个答案
1
次被采纳
chenyaxing
2
个答案
1
次被采纳
本月文章贡献
catcatbing
2
篇文章
5
次点赞
swet123
1
篇文章
3
次点赞
YZRD
1
篇文章
2
次点赞
Days
1
篇文章
2
次点赞
阳光的掌控者
1
篇文章
1
次点赞
回到
顶部
发布
问题
分享
好友
手机
浏览
扫码手机浏览
投诉
建议
回到
底部