CC2540做传感器应用蓝牙总是断开
在使用TICC2540开发温湿度检测时,采用SHT11作为温湿度传感器采集数据,使用TI的BLE-CC254x-1.4.0进行二次开发,对SimpleBLECentral以及SimpleBLEPeripheral进行修改,已经实现两个BLE模块之间的透传功能,在此基础上添加传感器数据采集,但在采集过程中,发现蓝牙会断开。程序相关代码如下:
static void NpiSerialCallback(uint8 port, uint8 events)
{
(void) port;
uint8 numBytes = 0 ;
uint8 buf[128];
uint8 buftest[15] = {14,1,2,3,4,5,6,7,9,10,11,12,13,14};
if( events & HAL_UART_RX_TIMEOUT)
{
numBytes = NPI_RxBufLen();
if(numBytes)
{
if( numBytes >= SIMPLEPROFILE_CHAR7_LEN ) buf[0] = SIMPLEPROFILE_CHAR6_LEN-1;
else buf[0] = numBytes;
NPI_ReadTransport(&buf[1],buf[0]); //read data from serial port
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR7,SIMPLEPROFILE_CHAR7_LEN,buf);
}
}
}
这部分代码主要实现透传功能。
数据周期性采集在如下代码中实现:
static void performPeriodicTask( void )
{
uint8 valueToCopy;
uint8 stat;
unsigned char T_H[15];
// Call to retrieve the value of the third characteristic in the profile
stat = SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR3, &valueToCopy);
if( stat == SUCCESS )
{
/*
* Call to set that value of the fourth characteristic in the profile. Note
* that if notifications of the fourth characteristic have been enabled by
* a GATT client device, then a notification will be sent every time this
* function is called.
*/
SimpleProfile_SetParameter( SIMPLEPROFILE_CHAR4, sizeof(uint8), &valueToCopy);
}
GetSH1X_Data();//温湿度采集
T_H[0]=0x0a;
T_H[1]=data1/1000+0x30;
T_H[2]=(data1%1000)/100+0x30;
T_H[3]=(data1%100)/10+0x30;
T_H[4]=0x2e;
T_H[5]=data1%10+0x30;
T_H[6]=data2/1000+0x30;
T_H[7]=(data2%1000)/100+0x30;
T_H[8]=(data2%100)/10+0x30;
T_H[9]=0x2e;
T_H[10]=data2%10+0x30;
SimpleProfile_SetParameter(SIMPLEPROFILE_CHAR7,SIMPLEPROFILE_CHAR7_LEN,T_H);
}
其中温湿度采集程序,模拟IIC,已经通过CC2540裸机测试。
此外尝试过将温湿度采集程序放到void SimpleBLEPeripheral_Init( uint8 task_id )中,通过串口输出数据,发现没有问题,但当在uint16 SimpleBLEPeripheral_ProcessEvent( uint8 task_id, uint16 events )进行周期采集时,蓝牙便断开连接。
stephen,
会断开通常是因为有循环没有退出,导致底层挂起了。
看一下有没有类似情况?
我用BLE-CC254x-1.4.0中SimpleBLEPeripheral例程配合usb dongle进行测试发现,若采用Power_save则蓝牙连接后不会断开,但若xPower_save则连接会断开。
请问是什么原因?