TI中文支持网
TI专业的中文技术问题搜集分享网站

CC2640R2F从app向串口传输字节(数目不等于特征值时)出现乱码。怎么解决?

       板子CC2640R2F, SDK4.30, BLE5 , simple_peripheral工程 ,特征值20,app通过uuid4(修改具有写入功能)向蓝牙发送数据1-19字节,尾部会出现固定字节和随机零还有随机字节组合。比如输入16进制61,串口收到的是61+34(一个字节时固定时34)+00+20+18+。。。。(后面部份随机)。我在将其输入的字节strlen()输出到串口看其长度变化,当输入字节数目为1,3,4,6,8,12,16字节时检测的字节长度不符合。

       输入20字节时候是准确的,请问我可以输入小于20字节串口显示不乱码吗?

Kevin Qiu1:

串口乱码的数据截图传上来看看
参考e2echina.ti.com/…/85543

user6300988:

回复 Kevin Qiu1:

user6300988:

回复 Kevin Qiu1:

不好意思回复晚了,图片已发,如上分别发61,6162,616263,…….。我看了一下你的链接我放一下我的配置
static bStatus_t simpleProfile_WriteAttrCB(uint16_t connHandle,gattAttribute_t *pAttr,uint8_t *pValue, uint16_t len,uint16_t offset, uint8_t method)
{bStatus_t status = SUCCESS;uint8 notifyApp = 0xFF;
if ( pAttr->type.len == ATT_BT_UUID_SIZE ){// 16-bit UUIDuint16 uuid = BUILD_UINT16( pAttr->type.uuid[0], pAttr->type.uuid[1]);switch ( uuid ){case SIMPLEPROFILE_CHAR1_UUID:case SIMPLEPROFILE_CHAR3_UUID:case SIMPLEPROFILE_CHAR4_UUID:
//Validate the value// Make sure it's not a blob operif ( offset == 0 ){if ( len > 20 ){status = ATT_ERR_INVALID_VALUE_SIZE;}}else{status = ATT_ERR_ATTR_NOT_LONG;}
//Write the value//Write the value
if ( status == SUCCESS ){
uint8 *pCurValue = (uint8 *)pAttr->pValue;
memcpy(pCurValue,pValue,20);notifyApp = SIMPLEPROFILE_CHAR4;

}

break;
case GATT_CLIENT_CHAR_CFG_UUID:status = GATTServApp_ProcessCCCWriteReq( connHandle, pAttr, pValue, len,offset, GATT_CLIENT_CFG_NOTIFY );break;
default:// Should never get here! (characteristics 2 and 4 do not have write permissions)status = ATT_ERR_ATTR_NOT_FOUND;break;}}else{// 128-bit UUIDstatus = ATT_ERR_INVALID_HANDLE;}
// If a characteristic value changed then callback function to notify application of changeif ( (notifyApp != 0xFF ) && simpleProfile_AppCBs && simpleProfile_AppCBs->pfnSimpleProfileChange ){simpleProfile_AppCBs->pfnSimpleProfileChange( notifyApp );}
return ( status );
}

特征值部分代码// Characteristic 4 configuration{{ ATT_BT_UUID_SIZE, clientCharCfgUUID },GATT_PERMIT_READ | GATT_PERMIT_WRITE,0,(uint8 *)&simpleProfileChar4Config},
// Characteristic 4 User Description{{ ATT_BT_UUID_SIZE, charUserDescUUID },GATT_PERMIT_READ,0,simpleProfileChar4UserDesp},

Kevin Qiu1:

回复 user6300988:

返回值是什么,一般需要发送与特征值长度等长的数据

user6300988:

回复 Kevin Qiu1:

好的谢谢,与特征值等长的可以实现,我找的好多相关资料都是等长的。我就是想看看可不可以不等长,我想收到数据检测字节长度不足补0,但是一直无法准确获取字节长度。

Kevin Qiu1:

回复 user6300988:

可以不等长,发送小于特征值长度的数据

user6300988:

回复 Kevin Qiu1:

可是不等长,后面字节收到的值是跟上面图片补齐的奇特数字,我不知道这是啥。前面几个字节是我输入的,没错。请问这个怎么把后面多出来的数字全变成0?我是在原来char4基础上修改的。

Kevin Qiu1:

回复 user6300988:

后面数看起来是随机的,更改memcpy数据长度看看是否有变化
另外可以看下e2e.ti.com/…/818555

赞(0)
未经允许不得转载:TI中文支持网 » CC2640R2F从app向串口传输字节(数目不等于特征值时)出现乱码。怎么解决?
分享到: 更多 (0)