一、简介
本文在工程SimpleBLEPeripheral的基础上,实现手机APP控制开发板上的LED.
二、开发平台 编译环境:IAR820.02 协议栈:BLE-CC254x-1.4.0 程序编辑器:Source Insight 3.5 手机APP:SmartRF 硬件平台:SmartRF开发板 三、编写声明
作者:爱已oО欠费
相关CC2541群:606444519
淘宝小店:https://item.taobao.com/item.htm?spm=a1z10.3-c-s.w4023-16306486995.5.hdKUUO&id=548576956486 四、实验前提 1、先实现以下历程 【cc2541历程】流水灯:http://blog.csdn.net/wangjiawu7/article/details/70261807 五、相关电路 六、实验过程 1)在SimpleBLEPeripheral_ProcessEvent函数(simpleBLEPeripheral.c)将相应的流水灯程序屏蔽掉 否则会和APP控制端有冲突 2)将simpleProfileChangeCB函数(simpleBLEPeripheral.c)修改为: static void simpleProfileChangeCB( uint8 paramID ) { uint8 newValue[20]; //APP端以数组的形式发送 switch( paramID ) { //LED控制端为特征值1 case SIMPLEPROFILE_CHAR1: SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR1, &newValue); #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteStringValue( "Char 1 : 0x", (uint16)(newValue[0]), 16, HAL_LCD_LINE_5 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) //如果接收到0x11则点亮led0 if(newValue[0] == 0x11) { HalLedSet( (HAL_LED_1), HAL_LED_MODE_ON ); } //否则接收到0x00,则关闭LED0 else if(newValue[0] == 0x10) { HalLedSet( (HAL_LED_1), HAL_LED_MODE_OFF ); } //如果接收到ox21,则点亮led1 if(newValue[0] == 0x21) { HalLedSet( (HAL_LED_2), HAL_LED_MODE_ON ); }//否则接收到0x20,则关闭LED1 else if(newValue[0] == 0x20) { HalLedSet( (HAL_LED_2), HAL_LED_MODE_OFF ); } //如果接收到ox41,则点亮LED2 if(newValue[0] == 0x41) { HalLedSet( (HAL_LED_3), HAL_LED_MODE_ON ); }//否则接收到0x40,则点亮LED2 else if(newValue[0] == 0x40) { HalLedSet( (HAL_LED_3), HAL_LED_MODE_OFF ); } break; case SIMPLEPROFILE_CHAR3: SimpleProfile_GetParameter( SIMPLEPROFILE_CHAR3, &newValue ); #if (defined HAL_LCD) && (HAL_LCD == TRUE) HalLcdWriteStringValue( "Char 3:", (uint16)(newValue), 10, HAL_LCD_LINE_3 ); #endif // (defined HAL_LCD) && (HAL_LCD == TRUE) break; default: // should not reach here! break; } } 3)将原先宏定义改为8,时间越短,接收的数值越多.(simpleBLEPeripheral.c) // Minimum connection interval (units of 1.25ms, 80=100ms) if automatic parameter update request is enabled #define DEFAULT_DESIRED_MIN_CONN_INTERVAL 8//80间隔时间 // Maximum connection interval (units of 1.25ms, 800=1000ms) if automatic parameter update request is enabled #define DEFAULT_DESIRED_MAX_CONN_INTERVAL 8//800间隔时间 4)编译成功,下载,APP成功控制LED。