Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 #include "mbed.h" 00002 #include "cube_hal.h " 00003 00004 #include "osal.h" 00005 #include "sensor_service.h " 00006 #include "debug.h" 00007 #include "stm32_bluenrg_ble.h " 00008 00009 00010 Serial pc(USBTX, USBRX); // tx, rx 00011 /* Private macro -------------------------------------------------------------*/ 00012 #define BDADDR_SIZE 6 00013 00014 /* Private variables ---------------------------------------------------------*/ 00015 extern volatile uint8_t set_connectable; 00016 extern volatile int connected; 00017 extern AxesRaw_t axes_data; 00018 00019 /* Private function prototypes -----------------------------------------------*/ 00020 void User_Process(AxesRaw_t* p_axes); 00021 00022 00023 float tri; 00024 int main() { 00025 const char *name = "BlueNRG"; 00026 uint8_t SERVER_BDADDR[] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x02}; 00027 //uint8_t bdaddr[BDADDR_SIZE]; 00028 uint8_t bdaddr[BDADDR_SIZE] = {0x12, 0x34, 0x00, 0xE1, 0x80, 0x02} ; 00029 uint16_t service_handle, dev_name_char_handle, appearance_char_handle; 00030 int ret; 00031 00032 HAL_Init(); 00033 /* Configure the User Button in GPIO Mode */ 00034 BSP_PB_Init(BUTTON_KEY, BUTTON_MODE_GPIO); 00035 /* Configure the system clock */ 00036 // SystemClock_Config(); 00037 /* Initialize the BlueNRG SPI driver */ 00038 BNRG_SPI_Init(); 00039 /* Initialize the BlueNRG HCI */ 00040 HCI_Init(); 00041 /* Reset BlueNRG hardware */ 00042 BlueNRG_RST(); 00043 /* The Nucleo board must be configured as SERVER */ 00044 //Osal_MemCpy(bdaddr, SERVER_BDADDR, sizeof(SERVER_BDADDR)); 00045 00046 ret = aci_hal_write_config_data(CONFIG_DATA_PUBADDR_OFFSET, 00047 CONFIG_DATA_PUBADDR_LEN, 00048 bdaddr); 00049 00050 pc.printf("Hello World!\n"); 00051 00052 if(ret){ 00053 PRINTF("Setting BD_ADDR failed.\n"); 00054 } 00055 00056 ret = aci_gatt_init(); 00057 if(ret){ 00058 PRINTF("GATT_Init failed.\n"); 00059 } 00060 00061 ret = aci_gap_init(GAP_PERIPHERAL_ROLE, &service_handle, 00062 &dev_name_char_handle, &appearance_char_handle); 00063 if(ret != BLE_STATUS_SUCCESS){ 00064 PRINTF("GAP_Init failed.\n"); 00065 } 00066 00067 ret = aci_gatt_update_char_value(service_handle, dev_name_char_handle, 0, 00068 strlen(name), (uint8_t *)name); 00069 00070 if(ret){ 00071 PRINTF("aci_gatt_update_char_value failed.\n"); 00072 while(1); 00073 } 00074 00075 ret = aci_gap_set_auth_requirement(MITM_PROTECTION_REQUIRED, 00076 OOB_AUTH_DATA_ABSENT, 00077 NULL, 00078 7, 00079 16, 00080 USE_FIXED_PIN_FOR_PAIRING, 00081 123456, 00082 BONDING); 00083 if (ret == BLE_STATUS_SUCCESS) { 00084 PRINTF("BLE Stack Initialized.\n"); 00085 } 00086 00087 PRINTF("SERVER: BLE Stack Initialized\n"); 00088 00089 ret = Add_Acc_Service(); 00090 00091 if(ret == BLE_STATUS_SUCCESS) 00092 PRINTF("Acc service added successfully.\n"); 00093 else 00094 PRINTF("Error while adding Acc service.\n"); 00095 00096 ret = Add_Environmental_Sensor_Service(); 00097 00098 if(ret == BLE_STATUS_SUCCESS) 00099 PRINTF("Environmental Sensor service added successfully.\n"); 00100 else 00101 PRINTF("Error while adding Environmental Sensor service.\n"); 00102 00103 /* Set output power level */ 00104 ret = aci_hal_set_tx_power_level(1,4); 00105 00106 while(1) 00107 { 00108 HCI_Process(); 00109 User_Process(&axes_data); 00110 } 00111 } 00112 00113 void User_Process(AxesRaw_t* p_axes) 00114 { 00115 if(set_connectable){ 00116 setConnectable(); 00117 set_connectable = FALSE; 00118 } 00119 00120 /* Check if the user has pushed the button */ 00121 if(BSP_PB_GetState(BUTTON_KEY) == RESET) 00122 { 00123 while (BSP_PB_GetState(BUTTON_KEY) == RESET); 00124 00125 //BSP_LED_Toggle(LED2); //used for debugging 00126 00127 if(connected){ 00128 /* Update acceleration data */ 00129 p_axes->AXIS_X += 100; 00130 p_axes->AXIS_Y += 100; 00131 p_axes->AXIS_Z += 100; 00132 //PRINTF("ACC: X=%6d Y=%6d Z=%6d\r\n", p_axes->AXIS_X, p_axes->AXIS_Y, p_axes->AXIS_Z); 00133 Acc_Update(p_axes); 00134 } 00135 } 00136 }
Generated on Tue Jul 12 2022 17:28:29 by
1.7.2