Andriyani
Newbie level 1
I'm so sorry everyone in this forum, I've just ignored the rules. And I want to repost my question.
It's about my different project questions. I made a project about BLE serial communication with STM32F070. The BLE I use is the RN4020 type from Microchip. I hope that later this serial communication can send data to each other from a PC to a smartphone and from a smartphone to a PC. I use Tera term serial monitor to display data sent on PC and use the MLDP terminal built in from Microchip that I installed on my smartphone to send data from smartphone to PC. To be able to transmit data, the BLE RN4020 module must be in the MLDP (Microchip Low Data Profile) mode that I have set in the program. When the program is running, BLE will issue the passcode displayed on the serial monitor and we ave to enter the passcode if our smartphone wants to connect to Bluetooth. So that, if it is connected between Bluetooth and smartphone, they can send data to each other. But the problem is that the Bluetooth connection doesn't last long, maybe only a few seconds. After that, appears in the serial monitor "Connection End" so that between the two devices can not send data each other. What should I do? I don't know what is the cause of the problem. Do you have several solutions to this project problem? And as an illustration, I also sent my code to the project that I was working on. Thank you in advance!
It's about my different project questions. I made a project about BLE serial communication with STM32F070. The BLE I use is the RN4020 type from Microchip. I hope that later this serial communication can send data to each other from a PC to a smartphone and from a smartphone to a PC. I use Tera term serial monitor to display data sent on PC and use the MLDP terminal built in from Microchip that I installed on my smartphone to send data from smartphone to PC. To be able to transmit data, the BLE RN4020 module must be in the MLDP (Microchip Low Data Profile) mode that I have set in the program. When the program is running, BLE will issue the passcode displayed on the serial monitor and we ave to enter the passcode if our smartphone wants to connect to Bluetooth. So that, if it is connected between Bluetooth and smartphone, they can send data to each other. But the problem is that the Bluetooth connection doesn't last long, maybe only a few seconds. After that, appears in the serial monitor "Connection End" so that between the two devices can not send data each other. What should I do? I don't know what is the cause of the problem. Do you have several solutions to this project problem? And as an illustration, I also sent my code to the project that I was working on. Thank you in advance!
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 #include "stm32f0xx_hal.h" #include "usb_device.h" /* USER CODE BEGIN Includes */ #include "usbd_cdc_if.h" #include "stdbool.h" #include "string.h" /* USER CODE END Includes */ /* Private variables ---------------------------------------------------------*/ ADC_HandleTypeDef hadc; I2C_HandleTypeDef hi2c1; I2C_HandleTypeDef hi2c2; UART_HandleTypeDef huart1; UART_HandleTypeDef huart2; UART_HandleTypeDef huart3; UART_HandleTypeDef huart4; /* USER CODE BEGIN PV */ /* Private variables ---------------------------------------------------------*/ //char txData[2] = "Hello World!\r\n"; char rxData[3]; char reply[30]; char buffer[15]; char message[30] = "Input Command!\r\n"; char command[15]; char newLineCh = '\n'; int val; int len; int i=0; char buff[500]; bool setup = true; /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_ADC_Init(void); static void MX_I2C1_Init(void); static void MX_I2C2_Init(void); static void MX_USART1_UART_Init(void); static void MX_USART2_UART_Init(void); static void MX_USART3_UART_Init(void); static void MX_USART4_UART_Init(void); /* USER CODE BEGIN PFP */ /* Private function prototypes -----------------------------------------------*/ static void Bluetooth_Init(void); /* USER CODE END PFP */ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ /** * @brief The application entry point. * * @retval None */ int main(void) { /* USER CODE BEGIN 1 */ /* USER CODE END 1 */ /* MCU Configuration----------------------------------------------------------*/ /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); /* USER CODE BEGIN Init */ /* USER CODE END Init */ /* Configure the system clock */ SystemClock_Config(); /* USER CODE BEGIN SysInit */ /* USER CODE END SysInit */ /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_ADC_Init(); MX_I2C1_Init(); MX_I2C2_Init(); MX_USART1_UART_Init(); MX_USART2_UART_Init(); MX_USART3_UART_Init(); MX_USART4_UART_Init(); MX_USB_DEVICE_Init(); /* USER CODE BEGIN 2 */ uint8_t Text[50] = "Hello World ECG PTE\r\n"; /* USER CODE END 2 */ /* Infinite loop */ /* USER CODE BEGIN WHILE */ while (1) { /* USER CODE END WHILE */ /* USER CODE BEGIN 3 */ CDC_Transmit_FS(Text,strlen(Text)); HAL_Delay(10); if (setup == true) { HAL_Delay(10000); Bluetooth_Init(); setup = false; } len = sprintf(buffer,"HasilPembacaan\r\n"); HAL_UART_Transmit(&huart2, (uint8_t*)&buffer, len, 1000); HAL_Delay(2000); len = sprintf(buffer,"D\n"); HAL_UART_Transmit(&huart4, (uint8_t*)&buffer, len, 1000); HAL_Delay(2000); HAL_UART_Receive(&huart4, (uint8_t *)buff, 500, 5000 ); HAL_UART_Transmit(&huart2, (uint8_t*)&buff, strlen(buff), 1000); } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct; RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_PeriphCLKInitTypeDef PeriphClkInit; /**Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14 |RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.HSIState = RCC_HSI_ON; RCC_OscInitStruct.HSI14State = RCC_HSI14_ON; RCC_OscInitStruct.HSICalibrationValue = 16; RCC_OscInitStruct.HSI14CalibrationValue = 16; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL4; RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV1; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Initializes the CPU, AHB and APB busses clocks */ RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK |RCC_CLOCKTYPE_PCLK1; RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1; if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USB|RCC_PERIPHCLK_USART1 |RCC_PERIPHCLK_I2C1; PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_HSI; PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLL; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure the Systick interrupt time */ HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000); /**Configure the Systick */ HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK); /* SysTick_IRQn interrupt configuration */ HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0); } /* ADC init function */ static void MX_ADC_Init(void) { ADC_ChannelConfTypeDef sConfig; /**Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion) */ hadc.Instance = ADC1; hadc.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1; hadc.Init.Resolution = ADC_RESOLUTION_12B; hadc.Init.DataAlign = ADC_DATAALIGN_RIGHT; hadc.Init.ScanConvMode = ADC_SCAN_DIRECTION_FORWARD; hadc.Init.EOCSelection = ADC_EOC_SINGLE_CONV; hadc.Init.LowPowerAutoWait = DISABLE; hadc.Init.LowPowerAutoPowerOff = DISABLE; hadc.Init.ContinuousConvMode = DISABLE; hadc.Init.DiscontinuousConvMode = DISABLE; hadc.Init.ExternalTrigConv = ADC_SOFTWARE_START; hadc.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE; hadc.Init.DMAContinuousRequests = DISABLE; hadc.Init.Overrun = ADC_OVR_DATA_PRESERVED; if (HAL_ADC_Init(&hadc) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure for the selected ADC regular channel to be converted. */ sConfig.Channel = ADC_CHANNEL_4; sConfig.Rank = ADC_RANK_CHANNEL_NUMBER; sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5; if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure for the selected ADC regular channel to be converted. */ sConfig.Channel = ADC_CHANNEL_5; if (HAL_ADC_ConfigChannel(&hadc, &sConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } } /* I2C1 init function */ static void MX_I2C1_Init(void) { hi2c1.Instance = I2C1; hi2c1.Init.Timing = 0x2000090E; hi2c1.Init.OwnAddress1 = 0; hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; hi2c1.Init.OwnAddress2 = 0; hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK; hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; if (HAL_I2C_Init(&hi2c1) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure Analogue filter */ if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure Digital filter */ if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } } /* I2C2 init function */ static void MX_I2C2_Init(void) { hi2c2.Instance = I2C2; hi2c2.Init.Timing = 0x20303E5D; hi2c2.Init.OwnAddress1 = 0; hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT; hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE; hi2c2.Init.OwnAddress2 = 0; hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK; hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE; hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE; if (HAL_I2C_Init(&hi2c2) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure Analogue filter */ if (HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } /**Configure Digital filter */ if (HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } } /* USART1 init function */ static void MX_USART1_UART_Init(void) { huart1.Instance = USART1; huart1.Init.BaudRate = 38400; huart1.Init.WordLength = UART_WORDLENGTH_7B; huart1.Init.StopBits = UART_STOPBITS_1; huart1.Init.Parity = UART_PARITY_NONE; huart1.Init.Mode = UART_MODE_TX_RX; huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart1.Init.OverSampling = UART_OVERSAMPLING_16; huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&huart1) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } } /* USART2 init function */ static void MX_USART2_UART_Init(void) { huart2.Instance = USART2; huart2.Init.BaudRate = 115200; huart2.Init.WordLength = UART_WORDLENGTH_8B; huart2.Init.StopBits = UART_STOPBITS_1; huart2.Init.Parity = UART_PARITY_NONE; huart2.Init.Mode = UART_MODE_TX_RX; huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart2.Init.OverSampling = UART_OVERSAMPLING_16; huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_RXOVERRUNDISABLE_INIT|UART_ADVFEATURE_DMADISABLEONERROR_INIT; huart2.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE; huart2.AdvancedInit.DMADisableonRxError = UART_ADVFEATURE_DMA_DISABLEONRXERROR; if (HAL_UART_Init(&huart2) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } } /* USART3 init function */ static void MX_USART3_UART_Init(void) { huart3.Instance = USART3; huart3.Init.BaudRate = 115200; huart3.Init.WordLength = UART_WORDLENGTH_8B; huart3.Init.StopBits = UART_STOPBITS_1; huart3.Init.Parity = UART_PARITY_NONE; huart3.Init.Mode = UART_MODE_TX_RX; huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart3.Init.OverSampling = UART_OVERSAMPLING_16; huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&huart3) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } } /* USART4 init function */ static void MX_USART4_UART_Init(void) { huart4.Instance = USART4; huart4.Init.BaudRate = 115200; huart4.Init.WordLength = UART_WORDLENGTH_8B; huart4.Init.StopBits = UART_STOPBITS_1; huart4.Init.Parity = UART_PARITY_NONE; huart4.Init.Mode = UART_MODE_TX_RX; huart4.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart4.Init.OverSampling = UART_OVERSAMPLING_16; huart4.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart4.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_RXOVERRUNDISABLE_INIT|UART_ADVFEATURE_DMADISABLEONERROR_INIT; huart4.AdvancedInit.OverrunDisable = UART_ADVFEATURE_OVERRUN_DISABLE; huart4.AdvancedInit.DMADisableonRxError = UART_ADVFEATURE_DMA_DISABLEONRXERROR; if (HAL_UART_Init(&huart4) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } } /** Configure pins as * Analog * Input * Output * EVENT_OUT * EXTI */ static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOA, BAT_STATUS1_Pin|BAT_STATUS2_Pin|COM_MCU_SYNC_Pin|TEST_LED2_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOC, BAT_STATUS3_Pin|BAT_STATUS4_Pin|CHG_CURRENT_SET_Pin|POWER_ON_HOLD_Pin |BT_RTS_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOB, BLUETOOTH_STAT_Pin|USB_PUP_Pin|BT_CMD_MLDP_Pin|BT_WAKE_SW_Pin, GPIO_PIN_RESET); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(BT_WAKE_HW_GPIO_Port, BT_WAKE_HW_Pin, GPIO_PIN_RESET); /*Configure GPIO pins : BAT_STATUS1_Pin BAT_STATUS2_Pin COM_MCU_SYNC_Pin TEST_LED2_Pin */ GPIO_InitStruct.Pin = BAT_STATUS1_Pin|BAT_STATUS2_Pin|COM_MCU_SYNC_Pin|TEST_LED2_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /*Configure GPIO pins : BAT_STATUS3_Pin BAT_STATUS4_Pin CHG_CURRENT_SET_Pin POWER_ON_HOLD_Pin BT_RTS_Pin */ GPIO_InitStruct.Pin = BAT_STATUS3_Pin|BAT_STATUS4_Pin|CHG_CURRENT_SET_Pin|POWER_ON_HOLD_Pin |BT_RTS_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); /*Configure GPIO pins : BLUETOOTH_STAT_Pin USB_PUP_Pin BT_CMD_MLDP_Pin BT_WAKE_SW_Pin */ GPIO_InitStruct.Pin = BLUETOOTH_STAT_Pin|USB_PUP_Pin|BT_CMD_MLDP_Pin|BT_WAKE_SW_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /*Configure GPIO pins : POWER_PUSH_BUTTON_Pin BT_CTS_Pin */ GPIO_InitStruct.Pin = POWER_PUSH_BUTTON_Pin|BT_CTS_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /*Configure GPIO pin : CHG_IND_MCU_Pin */ GPIO_InitStruct.Pin = CHG_IND_MCU_Pin; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(CHG_IND_MCU_GPIO_Port, &GPIO_InitStruct); /*Configure GPIO pin : BT_WAKE_HW_Pin */ GPIO_InitStruct.Pin = BT_WAKE_HW_Pin; GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; HAL_GPIO_Init(BT_WAKE_HW_GPIO_Port, &GPIO_InitStruct); } /* USER CODE BEGIN 4 */ static void Bluetooth_Init(void) { HAL_GPIO_WritePin(GPIOB, BT_WAKE_SW_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(GPIOB, BT_CMD_MLDP_Pin, GPIO_PIN_SET); HAL_GPIO_TogglePin(GPIOA,TEST_LED2_Pin); len = sprintf(buffer,"+\n"); HAL_UART_Transmit(&huart4, (uint8_t*)&buffer, len, 1000); HAL_UART_Receive(&huart4, (uint8_t *)buff, 500, 5000 ); HAL_UART_Transmit(&huart2, (uint8_t*)&buff, strlen(buff), 1000); len = sprintf(buffer,"D\n"); HAL_UART_Transmit(&huart4, (uint8_t*)&buffer, len, 1000); HAL_UART_Receive(&huart4, (uint8_t *)buff, 500, 5000 ); HAL_UART_Transmit(&huart2, (uint8_t*)&buff, strlen(buff), 1000); len = sprintf(buffer,"SF,1\n"); HAL_UART_Transmit(&huart4, (uint8_t*)&buffer, len, 1000); HAL_UART_Receive(&huart4, (uint8_t *)buff, 500, 5000 ); HAL_UART_Transmit(&huart2, (uint8_t*)&buff, strlen(buff), 1000); len = sprintf(buffer,"SS,F0000000\n"); HAL_UART_Transmit(&huart4, (uint8_t*)&buffer, len, 1000); HAL_UART_Receive(&huart4, (uint8_t *)buff, 500, 5000 ); HAL_UART_Transmit(&huart2, (uint8_t*)&buff, strlen(buff), 1000); len = sprintf(buffer,"SN,ECG_PTE_2\n"); HAL_UART_Transmit(&huart4, (uint8_t*)&buffer, len, 1000); HAL_UART_Receive(&huart4, (uint8_t *)buff, 500, 5000 ); HAL_UART_Transmit(&huart2, (uint8_t*)&buff, strlen(buff), 1000); len = sprintf(buffer,"SR,0x00000800\n"); HAL_UART_Transmit(&huart4, (uint8_t*)&buffer, len, 1000); HAL_UART_Receive(&huart4, (uint8_t *)buff, 500, 5000 ); HAL_UART_Transmit(&huart2, (uint8_t*)&buff, strlen(buff), 1000); len = sprintf(buffer,"R,1\n"); HAL_UART_Transmit(&huart4, (uint8_t*)&buffer, len, 1000); HAL_UART_Receive(&huart4, (uint8_t *)buff, 500, 5000 ); HAL_UART_Transmit(&huart2, (uint8_t*)&buff, strlen(buff), 1000); HAL_Delay(1000); len = sprintf(buffer,"F\n"); HAL_UART_Transmit(&huart4, (uint8_t*)&buffer, len, 1000); HAL_UART_Receive(&huart4, (uint8_t *)buff, 500, 5000 ); HAL_UART_Transmit(&huart2, (uint8_t*)&buff, strlen(buff), 1000); HAL_Delay(5000); len = sprintf(buffer,"X\n"); HAL_UART_Transmit(&huart4, (uint8_t*)&buffer, len, 1000); HAL_UART_Receive(&huart4, (uint8_t *)buff, 500, 5000 ); HAL_UART_Transmit(&huart2, (uint8_t*)&buff, strlen(buff), 1000); len = sprintf(buffer,"A\n"); HAL_UART_Transmit(&huart4, (uint8_t*)&buffer, len, 1000); HAL_UART_Receive(&huart4, (uint8_t *)buff, 500, 5000 ); HAL_UART_Transmit(&huart2, (uint8_t*)&buff, strlen(buff), 1000); HAL_GPIO_WritePin(GPIOB, BT_CMD_MLDP_Pin, GPIO_PIN_SET); len = sprintf(buffer,"+\n"); HAL_UART_Transmit(&huart4, (uint8_t*)&buffer, len, 1000); HAL_UART_Receive(&huart4, (uint8_t *)buff, strlen(buff), 5000 ); HAL_UART_Transmit(&huart2, (uint8_t*)&buff, strlen(buff), 1000); } /* USER CODE END 4 */
Last edited by a moderator: