我在
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};
sta
tic 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);
}
问题出在那儿??
0