微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > 射频无线通信设计 > CC2530串口打印出错的问题

CC2530串口打印出错的问题

时间:10-02 整理:3721RD 点击:
从串口中得到数据,先存入环形数组,再从环形数组中读取数字,分析之后通过原串口发送,利用串口助手显示在电脑上。可是存在有的数据能够正常打印,有的数据却不行的问题。

利用串口助手发送数据为:AT+SEND=18,1,0,123,8,00 12 4B 00 07 22 AC 92

环形数组存储和读取都没有问题

//读取尾指针指向的的地址中存储的需要调用的命令长度

CMD_Len = *(UART_StoreBuf + UART_StoreBuf_tail_pointer);

UART_StoreBuf_tail_pointer++;

UART_StoreBuf_tail_pointer %= UART_StoreBuf_Len_MAX;

sprintf(temp,"CMD_Len:%d\r\n",CMD_Len);

HalUARTWrite(0, temp, strlen(temp));


//将环形数组中的命令读取拼接出来,存入命令分析缓存区

if((UART_StoreBuf_tail_pointer + CMD_Len) <= UART_StoreBuf_Len_MAX)

{

memcpy(UartData_Behavior_Buf,UART_StoreBuf + UART_StoreBuf_tail_pointer,CMD_Len);

}else

{

temp1 = UART_StoreBuf_Len_MAX - UART_StoreBuf_tail_pointer;

memcpy(UartData_Behavior_Buf,UART_StoreBuf + UART_StoreBuf_tail_pointer, temp1);

temp2 = CMD_Len - temp1;

memcpy(UartData_Behavior_Buf + temp1,UART_StoreBuf,temp2);

}

//对命令分析缓存区中的数据经行分析

p1 = strchr((const char*)UartData_Behavior_Buf,',');

memcpy(num_str,UartData_Behavior_Buf,1);

CMD = atoi(num_str);

sprintf(temp,"CMD:%d\r\n",CMD);

HalUARTWrite(0, temp, strlen(temp));


if(CMD == 1)

{

p2 = strchr((const char*)(p1+1),',');

memcpy(num_str,p1+1,p2-p1-1);

operate = atoi(num_str);

sprintf(temp,"operate:%d\r\n",operate);

HalUARTWrite(0, temp, strlen(temp));

p3 = strchr((const char*)(p2+1),',');

memcpy(num_str,p2+1,p3-p2-1);

SettingIndex = atoi(num_str);

sprintf(temp,"SettingIndex:%d\r\n",SettingIndex);

HalUARTWrite(0, temp, strlen(temp));


p4 = strchr((const char*)(p3+1),',');

memcpy(num_str,p3+1,p4-p3-1);

data_len = atoi(num_str);

sprintf(temp,"data_len:%d\r\n",data_len);

HalUARTWrite(0, temp, strlen(temp));



memcpy(Data,p4+1,8);

sprintf(temp,"Data:%X\r\n",Data[7]);

HalUARTWrite(0, temp, strlen(temp));



//HalUARTWrite(0, "WhiteList\r\n", 11);

//调用数据处理函数

rev = Data_Process(operate,data_len,WhiteList_Data);

sprintf(temp,"rev:%d\r\n",rev);

HalUARTWrite(0, temp, strlen(temp));

if(rev)

{

HalUARTWrite(0, "Update tail pointer\r\n", 21);

HalLcdWriteString( "Update", HAL_LCD_LINE_1 );

//发送完成,更新尾指针

UART_StoreBuf_tail_pointer += CMD_Len;

UART_StoreBuf_tail_pointer %= UART_StoreBuf_Len_MAX;

}else

{

UART_StoreBuf_tail_pointer--;

HalLcdWriteString( "fail", HAL_LCD_LINE_1 );

sprintf(temp,"tail_pointer:%d\r\n",UART_StoreBuf_tail_pointer);

HalUARTWrite(0, temp, strlen(temp));

}

HalUARTWrite(0, "fail!\r\n", 7);

}

求指导!!谢谢!data_len和Data没有打印,后面的尾指针也没有打印!

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top