完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
我在STM32中完成一个消费发送和接收的两个进程。但消息老是发不成功,麻烦帮看看:
//#include #include “segled.h” unsigned char TABLE[16] = {0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E}; static struct rt_messagequeue segled_mq; static char segled_msg_pool[2048]; void rt_hw_segled_init(void) { //GPIO配置 GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB , ENABLE); //GPIOB LED 数码驱动IO GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15 ; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_Write(GPIOB,0x0000); } void LED_DISP(unsigned char BN,unsigned char number,unsigned char dot) { unsigned int tmp = 0; tmp = GPIO_ReadOutputData(GPIOB); switch(BN) { case 0x1: { tmp = tmp & 0x0018; if(dot) { tmp = tmp | ((TABLE[number] & 0x7F) 《《 8 ) | 0x0001; } else { tmp = tmp | (TABLE[number] 《《 8) | 0x0001; } GPIO_Write(GPIOB,tmp); break; } case 0x02: { tmp = tmp & 0x0018; if(dot) { tmp = tmp | ((TABLE[number] & 0x7F) 《《 8) | 0x0002; } else { tmp = tmp | (TABLE[number] 《《 8) | 0x0002; } GPIO_Write(GPIOB,tmp); break; } case 0x03: { tmp = tmp & 0x0018; if(dot) { tmp = tmp | ((TABLE[number] & 0x7F) 《《 8) | 0x0004; } else { tmp = tmp | (TABLE[number] 《《 8) | 0x0004; } GPIO_Write(GPIOB,tmp); break; } case 0x04: { tmp = tmp & 0x0018; if(dot) { tmp = tmp | ((TABLE[number] & 0x7F) 《《 8) | 0x0020; } else { tmp = tmp | (TABLE[number] 《《 8) | 0x0020; } GPIO_Write(GPIOB,tmp); break; } case 0x05: { tmp = tmp & 0x0018; if(dot) { tmp = tmp | ((TABLE[number] & 0x7F) 《《 8) | 0x0040; } else { tmp = tmp | (TABLE[number] 《《 8) | 0x0040; } GPIO_Write(GPIOB,tmp); break; } case 0x06: { tmp = tmp & 0x0018; if(dot) { tmp = tmp | ((TABLE[number] & 0x7F) 《《 8) | 0x0080; } else { tmp = tmp | (TABLE[number] 《《 8) | 0x0080; } GPIO_Write(GPIOB,tmp); break; } default: { } } } //char thread_segled_rev_stack[1024]; //struct rt_thread segled_thread_rev; static void segled_rev_thread(void* parameter) { char buf[6] = {0x88,0x88,0x88,0x88,0x88,0x88}; char buf1[6] = {0,0,0,0,0,0}; unsigned char counter = 0; rt_hw_segled_init(); while(1) { //counter ++; if(rt_mq_recv(&segled_mq,&buf[0],sizeof(buf),3) == RT_EOK)//RT_WAITING_NO { //LED_DISP(counter,buf[counter] & 0x0F,buf[counter] & 0x80 ); memcpy(buf1,buf,6); } LED_DISP(counter,buf[counter ++] & 0x0F,buf[counter] & 0x80 ); if(counter 》= 6) { counter = 0; } //rt_thread_delay(3); } } //char thread_segled_test_stack[1024]; //struct rt_thread segled_thread_test; static void segled_test_thread(void* parameter) { char tempstr[6] = {0,0,0,0,0,0}; while(1) { if(rt_mq_send(&segled_mq,&tempstr[0],sizeof(tempstr)) == -RT_EFULL)//RT_WAITING_NO { ; } rt_thread_delay(1000); if(tempstr[0]++ == 9) { tempstr[0] = 0; } } } rt_thread_t td1 = RT_NULL; rt_thread_t td2 = RT_NULL; void start_segled_thread(void) { rt_mq_init(&segled_mq, “segled_mq”, &segled_msg_pool[0], 6-sizeof(void *), sizeof(segled_msg_pool), RT_IPC_FLAG_FIFO); //segled rev thread /* rt_thread_init(&segled_thread_rev, “segled”, segled_rev_thread, RT_NULL, &thread_segled_rev_stack[0], sizeof(thread_segled_rev_stack),11,10); rt_thread_startup(&segled_thread_rev); */ td1 = rt_thread_create(“segled_rev”,segled_rev_thread, RT_NULL,512,11, 10); rt_thread_startup(td1); td2 = rt_thread_create(“segled_test”,segled_test_thread, RT_NULL,512,12, 10); rt_thread_startup(td2); //segled test send thread //return(thread); } 问题出在那儿?? |
|
相关推荐
1个回答
|
|
解决了:问题出在消息的初始化上。
rt_mq_init(&segled_mq, "segled_mq", &segled_msg_pool[0], 6,//6-sizeof(void *), sizeof(segled_msg_pool), RT_IPC_FLAG_FIFO); 按照RT-thread中编程指南中:这个初始化函数的第四个参数是6-sizeof(void *),这样一个结构。我直接写成6就OK了。 |
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
683 浏览 0 评论
AI模型部署边缘设备的奇妙之旅:如何在边缘端部署OpenCV
2521 浏览 0 评论
tms320280021 adc采样波形,为什么adc采样频率上来波形就不好了?
1314 浏览 0 评论
1915 浏览 0 评论
1494 浏览 0 评论
74900 浏览 21 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-24 07:28 , Processed in 0.663208 second(s), Total 72, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号