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

串口输入,和透传问题

1、串口好像只能输入一次,是否需要清空缓存数据?如需要,请给例

首先NpiSerialCallback函数

static void NpiSerialCallback( uint8 port, uint8 events )
{
(void)port;
uint8 numBytes = 0;
uint8 buf[128];
if (events & HAL_UART_RX_TIMEOUT) //串口有数据
{
numBytes = NPI_RxBufLen(); //读出串口缓冲区有多少字节
if(numBytes)
{
if ( numBytes >= SIMPLEPROFILE_CHAR1_LEN ) buf[0] = SIMPLEPROFILE_CHAR1_LEN-1;
else buf[0] = numBytes;
NPI_ReadTransport(&buf[1],buf[0]);
//从串口缓冲区读出numBytes字节数据
webeesensorProfile_SetParameter( WEBEESENSORPROFILE_TEMP, SIMPLEPROFILE_CHAR1_LEN, buf );
NPI_ReadTransport(buf,numBytes);
}
}
}

2、我通过手机接受这个特性的通知,获得的值跟我输入的不一样。一直不懂。

SimpleBLEPeripheral_Init里

// Setup the webeesensorProfile Characteristic Values
{
uint8 charValue1[SIMPLEPROFILE_CHAR1_LEN] = { 1, 2, 3, 4, 5 };
webeesensorProfile_SetParameter( WEBEESENSORPROFILE_TEMP, SIMPLEPROFILE_CHAR1_LEN, charValue1);
}

webeesensorProfile_SetParameter中

case WEBEESENSORPROFILE_TEMP:
if ( len == SIMPLEPROFILE_CHAR1_LEN ) {
attHandleValueNoti_t Noti;
Noti.handle = webeesensorProfileAttrTbl[2].handle;
Noti.len =SIMPLEPROFILE_CHAR1_LEN;
osal_memcpy( Noti.value, value, SIMPLEPROFILE_CHAR1_LEN );
GATT_Notification( 0, &Noti, false );
}
else
{
ret = bleInvalidRange;
}
break;

一些定义

static uint8 webeesensorProfileChar1Props = GATT_PROP_READ | GATT_PROP_NOTIFY;
static uint8 webeesensorProfileChar1[SIMPLEPROFILE_CHAR1_LEN] = { 0, 0, 0, 0, 0 };
static gattCharCfg_t webeesensorProfileChar1Config[GATT_MAX_NUM_CONN];
static uint8 webeesensorProfileChar1UserDesp[17] = "Characteristic 1\0";

#define WEBEESENSORPROFILE_TEMP_UUID            0xFFA1

#define SIMPLEPROFILE_CHAR1_LEN           5

属性

// Characteristic 1 Declaration
{ { ATT_BT_UUID_SIZE, characterUUID },
GATT_PERMIT_READ, 0,
&webeesensorProfileChar1Props },

// Characteristic Value 1
{ { ATT_BT_UUID_SIZE, webeesensorProfilechar1UUID },
GATT_PERMIT_READ | GATT_PERMIT_WRITE, 0, webeesensorProfileChar1 },
// Characteristic 1 configuration
{ { ATT_BT_UUID_SIZE, clientCharCfgUUID },
GATT_PERMIT_READ | GATT_PERMIT_WRITE, 0, (uint8 *)webeesensorProfileChar1Config },
// Characteristic 1 User Description
{ { ATT_BT_UUID_SIZE, charUserDescUUID },
GATT_PERMIT_READ, 0, webeesensorProfileChar1UserDesp },

好的就这2个问题,串口输入通知手机,手机收到感觉是乱码;串口好像只能输入一次!!!

Yue TANG:

你先按下面的例子跑通,下面的例子就是TI官方的串口透传,搞通了这个再基于它稍作修改即可。

http://processors.wiki.ti.com/index.php/SerialBLEbridge_V_1.4.1

赞(0)
未经允许不得转载:TI中文支持网 » 串口输入,和透传问题
分享到: 更多 (0)