2382 views|2 replies

280

Posts

7

Resources
The OP
 

In programming mode, output sensor data from the USB virtual serial port [Copy link]

 

After studying the official ST routine STM32CubeFunctionPack_STBOX1_V1.1.0\Projects\STM32L4R9ZI-SensorTile.box\Applications\BLESensors, the Bluetooth is unstable. After connecting, the data of various environmental sensors can be displayed, but within a minute, the Bluetooth connection fails. It may be that the Bluetooth compatibility with the mobile phone is not good, so I simply modified the code myself and viewed the data through the reserved USB virtual debugging serial port.

The main modification is to block the Bluetooth related initialization functions. The following is the code, and the modified parts are marked in Chinese.

Notes on debugging: When starting debugging, be sure to open the serial port after the USB virtual serial port is successfully mapped. When ending debugging, first close the serial port of the debugging assistant and then stop the program. If you forget to close the serial port of the debugging assistant and stop the program, the assistant software will report errors and you will need to force the program to terminate.

int main(void)
{

#ifdef STBOX1_RESTART_DFU
  /* Check if we need to go to DFU */
  if(DFU_Var == DFU_MAGIC_NUM) {
    typedef void (*pFunction)(void);
    pFunction JumpToDFU;

    /* Reset the Magic Number */
    DFU_Var = 0x00000000;
    HAL_RCC_DeInit();
    SysTick->CTRL = 0;
    SysTick->LOAD = 0;
    SysTick->VAL = 0;
    __disable_irq();
    __HAL_SYSCFG_REMAPMEMORY_SYSTEMFLASH();
    JumpToDFU = (void (*)(void)) (*((uint32_t *)(0x1FFF0000 + 4)));
    /* Initialize user application's Stack Pointer */
    __set_MSP(*(__IO uint32_t*) 0x1FFF0000);
    JumpToDFU();
  }
#endif /* STBOX1_RESTART_DFU */

  /* HAL_Init */
  HAL_Init();

  /* Configure the System clock */
  SystemClock_Config();

  InitTargetPlatform();

#ifdef STBOX1_ENABLE_PRINTF
  DisplayFirmwareInfo();
#endif /* STBOX1_ENABLE_PRINTF */

//  /* Initialize the BlueNRG */屏蔽掉
//  Init_BlueNRG_Stack();
//
//  /* Initialize the BlueNRG Custom services */
//  Init_BlueNRG_Custom_Services();

  /* Reset the volatile for avoid to power off the board */
  PowerButtonPressed  =0;
  
  
  uint32_t uhCapture = __HAL_TIM_GET_COUNTER(&TimCCHandle);
  /* Start the TIM Base generation in interrupt mode 1Hz中断,用于输出电池电量*/
  if(HAL_TIM_OC_Start_IT(&TimCCHandle, TIM_CHANNEL_1) != HAL_OK){
    /* Starting Error */
    Error_Handler();
  }
  /* Set the Capture Compare Register value */
  __HAL_TIM_SET_COMPARE(&TimCCHandle, TIM_CHANNEL_1, (uhCapture + STBOX1_UPDATE_LED_BATTERY));
  
        /* Start the TIM Base generation in interrupt mode 2Hz中断,用于输出环境传感器数据,后来把加速度传感器也改过来了*/
      if(HAL_TIM_OC_Start_IT(&TimCCHandle, TIM_CHANNEL_3) != HAL_OK){
        /* Starting Error */
        Error_Handler();
      }
      /* Set the Capture Compare Register value */
      __HAL_TIM_SET_COMPARE(&TimCCHandle, TIM_CHANNEL_3, (uhCapture + STBOX1_UPDATE_ENV));
      
//      /* Start the TIM Base generation in interrupt mode */这个20Hz更新太快,看的眼花,我把触发信号改到通道3上了
//      if(HAL_TIM_OC_Start_IT(&TimCCHandle, TIM_CHANNEL_4) != HAL_OK){
//        /* Starting Error */
//        Error_Handler();
//      }
//      /* Set the Capture Compare Register value */
//      __HAL_TIM_SET_COMPARE(&TimCCHandle, TIM_CHANNEL_4, (uhCapture + STBOX1_UPDATE_INV));


  while (1){
//    if(set_connectable){蓝牙的全部注释掉
//      uint32_t uhCapture = __HAL_TIM_GET_COUNTER(&TimCCHandle);
//      set_connectable =0;
//      setConnectable();
//
//      /* Start the TIM Base generation in interrupt mode */
//      if(HAL_TIM_OC_Start_IT(&TimCCHandle, TIM_CHANNEL_1) != HAL_OK){
//        /* Starting Error */
//        Error_Handler();
//      }
//
//      /* Set the Capture Compare Register value */
//      __HAL_TIM_SET_COMPARE(&TimCCHandle, TIM_CHANNEL_1, (uhCapture + STBOX1_UPDATE_LED_BATTERY));
//    }

    /* Handle BLE event */
    if(hci_event) {
      hci_event =0;
      hci_user_evt_proc();
    }

    /* Handle user button */
    if(ButtonPressed) {
      ButtonCallback();
      ButtonPressed=0;
    }

    /* Power Off the SensorTile.box */
    if(PowerButtonPressed){
      BSP_BC_CmdSend(SHIPPING_MODE_ON);
      PowerButtonPressed =0;
    }

    /* Reboot the Board */
    if(RebootBoard) {
      RebootBoard=0;
      HAL_NVIC_SystemReset();
    }

    /* Battery Info Data */
    if(SendBatteryInfo) {
      SendBatteryInfo=0;
      SendBatteryInfoData();
    }

    /* Environmental Data */
    if(SendEnv) {
      int32_t PressToSend;
      uint16_t HumToSend;
      int16_t TempToSend;

      SendEnv=0;

      /* Read all the Environmental Sensors */
      ReadEnvironmentalData(&PressToSend,&HumToSend, &TempToSend);
      STBOX1_PRINTF("Press:%d,Hum:%d,Temp:%d\r\n",PressToSend,HumToSend,TempToSend);
      /* Send the Data with BLE */
//      Environmental_Update(PressToSend,HumToSend,TempToSend);蓝牙发送注释掉,前面加上虚拟串口发送
    }

    /* Motion Data */
    if(SendAccGyroMag) {
      BSP_MOTION_SENSOR_Axes_t ACC_Value;
      BSP_MOTION_SENSOR_Axes_t GYR_Value;
      BSP_MOTION_SENSOR_Axes_t MAG_Value;

      SendAccGyroMag=0;

      /* Read the Inertial Sensors */
      ReadInertialData(&ACC_Value,&GYR_Value,&MAG_Value);
      STBOX1_PRINTF("ACC.x:%d,y:%d,z:%d\r\n",ACC_Value.x,ACC_Value.y,ACC_Value.z);

      /* Send the Data with BLE */
//      AccGyroMag_Update(&ACC_Value,&GYR_Value,&MAG_Value);蓝牙发送注释掉,前面加上虚拟串口发送
    }

    /* Blinking the Led */
    if(BlinkLed) {
      BlinkLed = 0;
      LedToggleTargetPlatform();
    }

    /* Wait next event */
    __WFI();
  }
}

The following figure shows the final serial port output result:

The following plan is to modify the STM32CubeFunctionPack_STBOX1_V1.1.0\Projects\STM32L4R9ZI-SensorTile.box\Applications\BLEMLC routine to realize personnel activity information recognition and virtual serial port output.

This example also disconnects after a while on the app, which is a bad Bluetooth experience.

Latest reply

Great post! The code is very beautifully written. Did the author write the code himself? You are very skilled. Without a few years of experience, you can't write such code.   Details Published on 2020-5-8 13:44
 
 

18

Posts

10

Resources
2
 

Great post! The code is very beautifully written. Did the author write the code himself? You are very skilled. Without a few years of experience, you can't write such code.

Comments

It's an official routine  Details Published on 2020-5-8 14:12
 
 
 

280

Posts

7

Resources
3
 
aytwartoofyoroo posted on 2020-5-8 13:44 Great post! The code is very beautiful. Did you write the code yourself? You are very skilled. Without a few years of experience, you can't write such code

It's the official routine

 
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

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