1701 views|0 replies

274

Posts

8

Resources
The OP
 

[Contactless facial recognition access control system] + Creation of 5-EFR32BG22 Bluetooth host [Copy link]

 

EFR32BG22 is a Bluetooth chip from Silicon Labs that can implement BLE host and slave functions. It contains a cortex-M33 core.

To use EFR32BG22, you need to use its supporting IDE, "simplicity studio". This IDE is also very convenient to use. When the development board is connected to the computer, it will automatically identify the chip model.

Click the "start" button to enter the interface of the corresponding chip. By selecting the corresponding example, you can quickly start the development of a project, which is quite convenient. Here, a BLE client example is selected.

In this example, it is found that the BLE protocol stack is also event-driven. It seems that similar protocol stacks are all constructed in an event-driven manner. The source code is mainly concentrated in 'app.c' and 'main.c' .

1. main.c

int main(void)
{
  // Initialize Silicon Labs device, system, service(s) and protocol stack(s).
  // Note that if the kernel is present, processing task(s) will be created by this call.
  sl_system_init();
  // Initialize the application. For example, create periodic timer(s) or task(s) if the kernel is present.
  app_init();
  while (1) {
    // Do not remove this call: Silicon Labs components process action routine must be called from the super loop.
    sl_system_process_action();
    // Application process.
    app_process_action();
    // Let the CPU go to sleep if the system allows it.
    sl_power_manager_sleep();

  }
}

If users want to add their own code, they can choose to add it in app_init()and app_process_action().

2. app.c

The main focus of this file is the event handling function. The entire Bluetooth event handling function is in 'app.c', and the function name is void sl_bt_on_event(sl_bt_msg_t* evt).

If you are a BLE client, you need to scan devices, connect to devices, discover services and characteristics, handle the notify events of the BLE server, and read and write the characteristics of the server.

Therefore, the main events used are as follows:

  1. Event sl_bt_evt_scanner_scan_report_id, this event indicates that a device has been scanned. In this event, it is necessary to determine whether the scanned device is the one that needs to be connected. The device can be determined by address or name. If the device is the one that needs to be connected, then the stop scanning function must be executed and a connection must be established.
  2. Event sl_bt_evt_connection_opened_id, indicating that a connection has been established, and the function of discovering the service needs to be called in this event
  3. Event sl_bt_evt_gatt_service_idindicating that a service was discovered
  4. Event sl_bt_evt_gatt_characteristic_id, indicating that a feature is discovered. In this event, we need to determine whether the feature is the one we want to operate. We need to determine it based on the UUID
  5. Event sl_bt_evt_gatt_procedure_completed_id: This event is more complex and is an event when a certain behavior is completed. This behavior may be the completion of a service scan or the completion of a feature scan. When the service scan is completed, you need to start scanning the corresponding features.
  6. Event sl_bt_evt_gatt_characteristic_value_id, indicating that a notification of a feature of the server has been received

There are also read and write functions for the features:

// 读函数
sl_status_t sl_bt_gatt_read_characteristic_value(uint8_t connection,
                                                 uint16_t characteristic);
// 写函数
sl_status_t sl_bt_gatt_write_characteristic_value(uint8_t connection,
                                                  uint16_t characteristic,
                                                  size_t value_len,
                                                  const uint8_t* value);

There are many read and write functions, only the used functions are listed here.

Conclusion

At this point, the BLE client code is basically completed, connecting to the server, finding the required characteristics for reading and writing, and being able to receive the notify actively sent by the server. Next, you need to operate the peripherals on the EFR32BG22.

This post is from DigiKey Technology Zone
 
 

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