4314 views|2 replies

32

Posts

0

Resources
The OP
 

Mobile phone Bluetooth controls the lights on the BlueRNG development board (source code + .hex file) [Copy link]

 This post was last edited by elike on 2018-1-24 19:18 Basic function description. After the program is written, you can connect to the BLE server in the lightblue client on your phone. After the connection is successful, LED1 will light up. Then, when you send 'x' to BlueNRG with your phone, the blue light of LED3 will light up. When you send 'x' again, the blue light of LED3 will go out. When you send 'y', LED2 will light up. When you send it again, LED2 will go out. In this way, you can use your phone to send different letters via Bluetooth to control the on and off of LED2 and LED3. (Attachment server.hex can be burned directly) [attach]342418 [/attach] [attach]342419 [/attach] [attach]342420 [/attach] 1. Set up the working environment TrueSTUDIO + secureCRT, and use the BlueRNG-1Flasher_GUI that comes with the burning tool. Since this program is modified from the Blue_chat in the example program, let's first analyze the source code structure. [attach]342421 [/attach] [attach]342423 [/attach] The code we need to write is marked in the blue box. The other files are project files for different platforms, including EWARM, MDK-ARM and TrueSTUDIO. The following is only for TrueSTUDIO, so we can just copy the files in the following three directories: ./inc/*, ./src/*, ./TrueSTUDIO/BlueNRG-1/*. However, the source code also has many dependent libraries, which are all placed in the BlueNRG-1_2 DK 2.6.0/Library folder. We just need to copy and configure them to the corresponding project files. For the convenience of modification, I created a new Projec folder, with Library and Project in the same directory. The project file structure is as follows. The files in the yellow box are generated after compilation, so don't worry about them. Finally, the file configuration part can be modified in the project configuration, as shown in the figure. After the build passes, it's time to modify the code2. Add the code to control the light Define the clock global variable in the BLE_char_main.c file
  1. volatile uint32_t lSystickCounter=0;
复制代码
  1. /* Identify BlueNRG1 platform */ SdkEvalIdentification();
复制代码
Add port initialization after this
  1. /* Enable the GPIO Clock */ SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_GPIO, ENABLE); /* Configure the LEDs */ GPIO_InitType GPIO_InitStructure; GPIO_InitStructure.GPIO_Pin = Get_LedGpioPin(LED1) | Get_LedGpioPin(LED2) | Get_LedGpioPin(LED3); GPIO_InitStructure.GPIO_Mode = GPIO_Output; GPIO_InitStructure.GPIO_Pull = ENABLE; GPIO_InitStructure.GPIO_HighPwr = ENABLE; GPIO_Init(&GPIO_InitStructure); /* Put the LEDs off */ GPIO_WriteBit(Get_LedGpioPin(LED1) | Get_LedGpioPin(LED2) | Get_LedGpioPin(LED3), LED_OFF);
复制代码
Clock initialization
  1. /* Configure SysTick to generate interrupt */ SysTick_Config(SYST_CLOCK/1000 - 1);
复制代码
In the chart.c file, change the following function to
  1. void hci_le_connection_complete_event(uint8_t Status, uint16_t Connection_Handle, uint8_t Role, uint8_t Peer_Address_Type, uint8_t Peer_Address[6], uint16_t Conn_Interval, uint16_t Conn_Latency, uint16_t Supervision_Timeout, uint8_t Master_Clock_Accuracy) { connection_handle = Connection_Handle; APP_FLAG_SET(CONNECTED); GPIO_ToggleBits(Get_LedGpioPin(LED1)); printf("connection complete\r\n"); #if REQUEST_CONN_PARAM_UPDATE APP_FLAG_CLEAR(L2CAP_PARAM_UPD_SENT); Timer_Set(&l2cap_req_timer, CLOCK_SECOND*2); #endif }/* end hci_le_connection_complete_event() */
复制代码
The above means that LED1 and
  1. void are turned on after being connected. hci_disconnection_complete_event(uint8_t Status, uint16_t Connection_Handle,uint8_t Reason)
  2. {
  3.    APP_FLAG_CLEAR(CONNECTED);
  4.   /* Make the device connectable again. */
  5.   APP_FLAG_SET(SET_CONNECTABLE);
  6.   APP_FLAG_CLEAR(NOTIFICATIONS_ENABLED);
  7.   APP_FLAG_CLEAR(TX_BUFFER_FULL);
  8.   APP_FLAG_CLEAR(START_READ_TX_CHAR_HANDLE);
  9.   APP_FLAG_CLEAR(END_READ_TX_CHAR_HANDLE);
  10.   APP_FLAG_CLEAR(START_READ_RX_CHAR_HANDLE);
  11.   APP_FLAG_CLEAR(END_READ_RX_CHAR_HANDLE);
  12.   GPIO_ToggleBits(Get_LedGpioPin(LED1));
  13.   printf("disconnection complete\r\n");
  14. #if ST_OTA_FIRMWARE_UPGRADE_SUPPORT
  15.   OTA_terminate_connection();
  16. #endif
  17.   
  18. }/* end hci_disconnection_complete_event() */
复制代码
以上表示,断开就熄灭LED1.
还有gatt_db.c文件中
void Attribute_Modified_CB函数改为
  1. void Attribute_Modified_CB(uint16_t handle, uint16_t data_length, uint8_t *att_data)
  2. {
  3.   if(handle == RXCharHandle + 1)
  4.   {
  5.     for(int i = 0; i < data_length; i++){
  6.       if(att_data == 'x')
  7.             GPIO_ToggleBits(Get_LedGpioPin(LED3));
  8. if(att_data == 'y')
  9.             GPIO_ToggleBits(Get_LedGpioPin(LED2));
  10.       printf("%c", att_data);
  11.     }
  12.   }
  13.   else if(handle == TXCharHandle + 2)
  14.   {        
  15.     if(att_data[0] == 0x01)
  16.       APP_FLAG_SET(NOTIFICATIONS_ENABLED);
  17.   }
  18.   //printf("attribute_modefied\r\n");
  19. }
复制代码
接着build成功就行了,把生成的.hex问价烧录到单片机中就可以实现。

3.烧录
至于烧录过程如图配置即可。


所有代码详见
链接已隐藏,如需查看请登录或者注册





图片1.jpg (66.45 KB, downloads: 0)

图片1.jpg

图片2.jpg (38.58 KB, downloads: 0)

图片2.jpg

图片3.jpg (36.64 KB, downloads: 0)

图片3.jpg

file_list1.jpg (109.45 KB, downloads: 0)

file_list1.jpg

file_list2.jpg (120.7 KB, downloads: 0)

file_list2.jpg

Server.hex

229.77 KB, downloads: 3

This post is from ST - Low Power RF

Latest reply

I don't understand, it's so profound  Details Published on 2018-2-19 10:16
 
 

293

Posts

1

Resources
2
 
Great, I learned a lot
This post is from ST - Low Power RF
 
 
 

11

Posts

3

Resources
3
 
I don't understand, it's so profound
This post is from ST - Low Power RF
 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list