移远通讯BC260Y CN STM32G0串口下载教程

下载前,需要先断电并将BOOT0处红⾊开关拨 ⾄“NO”,并再次接上数据线,打开STM32CubeProgrammer,选择UART模式,点击右上⻆的“Connect”按钮,显示绿⾊“Connected”图标时即为连接成功

移远通讯BC260Y CN STM32G0串口下载教程_第1张图片

点击左侧的下载图标,进⼊Erasing & Programming界⾯,并点击“Browse”选择需要的烧录的 程序

移远通讯BC260Y CN STM32G0串口下载教程_第2张图片

点击右上⻆的“Disconnect”按钮断开连接,并断电,将底板上的红⾊开关码拨到“1”,拔掉数据线重启后再连接。

移远通讯BC260Y CN STM32G0串口下载教程_第3张图片

 下载好后显示的灯 

一个红色1个蓝色常量 

移远通讯BC260Y CN STM32G0串口下载教程_第4张图片

注意下载的时候波特率是115200,使用串口软件是9600 ,程序路径不要有中文

移远通讯BC260Y CN STM32G0串口下载教程_第5张图片

AT

OK
AT

OK
AT

OK
AT

OK
AT+CFUN=1

OK
AT+QMTDISC=0

OK

+QMTDISC: 0,0
AT+CIMI

460083501703547

OK
AT+CGATT=1

OK
AT+CGATT?

+CGATT: 1

OK
AT+CESQ

+CESQ: 99,99,255,255,34,70

OK
AT+QMTCFG="aliauth",0,"a1ZMkwhevG9","mzh001","cc96840980ac49570acc47e2c0195b5c"

OK
AT+QMTOPEN=0,"139.196.135.135",1883

OK

+QMTOPEN: 0,0
AT+QMTCONN=0,"clientExample_1987"

OK

+QMTCONN: 0,0,0
AT+QMTPUB=0,0,0,0,/sys/a1ZMkwhevG9/mzh001/thing/event/property/post

>
{"id":"26","version":"1.0","sys":{"ack":0},"params":{"CurrentTemperature":{"value":22},"CurrentHumidity":{"value":30}},"method":"thing.event.property.post"}
OK

+QMTPUB: 0,0,0
AT+QMTPUB=0,0,0,0,/sys/a1ZMkwhevG9/mzh001/thing/event/property/post

>
{"id":"26","version":"1.0","sys":{"ack":0},"params":{"CurrentTemperature":{"value":22},"CurrentHumidity":{"value":30}},"method":"thing.event.property.post"}
OK

+QMTPUB: 0,0,0

+AT+QMTPUB=0,0,0,0,/sys/a1ZMkwhevG9/mzh001/thing/event/property/post

>
{"id":"26","version":"1.0","sys":{"ack":0},"params":{"CurrentTemperature":{"value":22},"CurrentHumidity":{"value":30}},"method":"thing.event.property.post"}
OK

+QMTPUB: 0,0,0

+
AT+QMTPUB=0,0,0,0,/sys/a1ZMkwhevG9/mzh001/thing/event/property/post

>
{"id":"26","version":"1.0","sys":{"ack":0},"params":{"CurrentTemperature":{"value":22},"CurrentHumidity":{"value":30}},"method":"thing.event.property.post"}
OK

+QMTPUB: 0,0,0

+}"
AT+QMTPUB=0,0,0,0,/sys/a1ZMkwhevG9/mzh001/thing/event/property/post

>
{"id":"26","version":"1.0","sys":{"ack":0},"params":{"CurrentTemperature":{"value":22},"CurrentHumidity":{"value":30}},"method":"thing.event.property.post"}
OK

+QMTPUB: 0,0,0

+t"}"
AT+QMTPUB=0,0,0,0,/sys/a1ZMkwhevG9/mzh001/thing/event/property/post

>
{"id":"26","version":"1.0","sys":{"ack":0},"params":{"CurrentTemperature":{"value":22},"CurrentHumidity":{"value":30}},"method":"thing.event.property.post"}
OK

+QMTPUB: 0,0,0

+y.post"}"
AT

OK
AT

OK
AT

OC程序源码,采集温湿度

移远通讯BC260Y CN STM32G0串口下载教程_第6张图片

/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * @file           : main.c
  * @brief          : Main program body
  ******************************************************************************
  * @attention
  *
  * 

© Copyright (c) 2021 STMicroelectronics. * All rights reserved.

* * This software component is licensed by ST under BSD 3-Clause license, * the "License"; You may not use this file except in compliance with the * License. You may obtain a copy of the License at: * opensource.org/licenses/BSD-3-Clause * ****************************************************************************** */ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "usart.h" #include "stdlib.h" #include "string.h" #include "stdlib.h" #include "BC260Y.h" #include "AHT20.h" IWDG_HandleTypeDef hiwdg; /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ /* USER CODE END Includes */ /* Private typedef -----------------------------------------------------------*/ /* USER CODE BEGIN PTD */ /* USER CODE END PTD */ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN PD */ /* USER CODE END PD */ /* Private macro -------------------------------------------------------------*/ /* USER CODE BEGIN PM */ /* USER CODE END PM */ /* Private variables ---------------------------------------------------------*/ /* USER CODE BEGIN PV */ /* USER CODE END PV */ /* Private function prototypes -----------------------------------------------*/ void SystemClock_Config(void); static void MX_GPIO_Init(void); static void MX_IWDG_Init(void); void IWDG_Feed(void); /* USER CODE BEGIN PFP */ /* USER CODE END PFP */ /* Private user code ---------------------------------------------------------*/ /* USER CODE BEGIN 0 */ /* USER CODE END 0 */ void OPEN_BC260Y(void) { char *strx; printf("AT\r\n"); HAL_Delay(300); strx=strstr((const char*)RxBuffer,(const char*)"OK");//返回OK printf("AT\r\n"); HAL_Delay(300); strx=strstr((const char*)RxBuffer,(const char*)"OK");//返回OK if(strx==NULL) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0,GPIO_PIN_SET);//拉低PWRKEY HAL_Delay(600); HAL_Delay(600); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0,GPIO_PIN_RESET);//拉高正常开机 IWDG_Feed();//喂狗 } printf("AT\r\n"); HAL_Delay(300); IWDG_Feed();//喂狗 strx=strstr((const char*)RxBuffer,(const char*)"OK");//返回OK while(strx==NULL) { Clear_Buffer(); printf("AT\r\n"); HAL_Delay(300); HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0); strx=strstr((const char*)RxBuffer,(const char*)"OK");//返回OK } HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0,0); IWDG_Feed();//喂狗 } void Send_ATcmd(void)//发送AT指令给到模块,从串口1接收指令,串口2控制 { char i; for(i=0;iISR&0X40)==0){}//等待发送完成 USART2->TDR = Uart1_RxBuff[i]; } } /** * @brief The application entry point. * @retval int */ int main(void) { unsigned char i; uint8_t ret = 0; uint32_t CT_data[2]; uint8_t send_jason[200]; int c1,t1; /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ HAL_Init(); SystemClock_Config(); /* Initialize all configured peripherals */ MX_GPIO_Init(); MX_IWDG_Init(); MX_USART1_UART_Init(); MX_USART2_UART_Init(); HAL_Delay(500); I2C_Bus_Init(); ret = AHT20_Init(); if(ret == 0) { while(1) { Uart1_SendStr("AHT20传感器初始化错误\n"); HAL_Delay(300); } } /* USER CODE BEGIN 2 */ // OPEN_BC260Y(); /* USER CODE END 2 */ BC260Y_Init(); MQTT_Init();//初始化MQTT while (1) { /* 读取 AHT20 传感器数据*/ while(AHT20_Read_Cal_Enable() == 0) { AHT20_Init();//如果为0再使能一次 HAL_Delay(30); } AHT20_Read_CTdata(CT_data); //读取温度和湿度 c1 = CT_data[0] * 1000 / 1024 / 1024; //计算得到湿度值(放大了10倍,如果c1=523,表示现在湿度为52.3%) t1 = CT_data[1] * 200 *10 / 1024 / 1024 - 500;//计算得到温度值(放大了10倍,如果t1=245,表示现在温度为24.5℃) ONENET_SendJsondata(send_jason,t1/10,c1/10);//发布数据 HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0); HAL_Delay(300); // HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0); IWDG_Feed();//喂狗 } /* USER CODE END 3 */ } /** * @brief System Clock Configuration * @retval None */ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; RCC_ClkInitTypeDef RCC_ClkInitStruct = {0}; RCC_PeriphCLKInitTypeDef PeriphClkInit = {0}; /** Configure the main internal regulator output voltage */ HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1); /** Initializes the CPU, AHB and APB busses clocks */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.LSIState = RCC_LSI_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1; RCC_OscInitStruct.PLL.PLLN = 16; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2; if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) { Error_Handler(); } /** 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_2) != HAL_OK) { Error_Handler(); } /** Initializes the peripherals clocks */ PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_USART2; PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_PCLK1; if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK) { Error_Handler(); } } /** * @brief GPIO Initialization Function * @param None * @retval None */ static void MX_GPIO_Init(void) { GPIO_InitTypeDef GPIO_InitStruct = {0}; /* GPIO Ports Clock Enable */ __HAL_RCC_GPIOF_CLK_ENABLE(); __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOA_CLK_ENABLE(); /*Configure GPIO pin Output Level */ HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET); /*Configure GPIO pin : PB0 */ GPIO_InitStruct.Pin = GPIO_PIN_0; 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 pin Output Level */ /*Configure GPIO pin : PA0 */ GPIO_InitStruct.Pin = GPIO_PIN_0; 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); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET); } /* USER CODE BEGIN 4 */ /** * @brief IWDG Initialization Function * @param None * @retval None */ static void MX_IWDG_Init(void) { /* USER CODE BEGIN IWDG_Init 0 */ /* USER CODE END IWDG_Init 0 */ /* USER CODE BEGIN IWDG_Init 1 */ /* USER CODE END IWDG_Init 1 */ hiwdg.Instance = IWDG; hiwdg.Init.Prescaler = IWDG_PRESCALER_64; hiwdg.Init.Window = 4000; hiwdg.Init.Reload = 4000; if (HAL_IWDG_Init(&hiwdg) != HAL_OK) { Error_Handler(); } /* USER CODE BEGIN IWDG_Init 2 */ /* USER CODE END IWDG_Init 2 */ } /* USER CODE END 4 */ /** * @brief This function is executed in case of error occurrence. * @retval None */ #ifdef USE_FULL_ASSERT /** * @brief Reports the name of the source file and the source line number * where the assert_param error has occurred. * @param file: pointer to the source file name * @param line: assert_param error line source number * @retval None */ void assert_failed(uint8_t *file, uint32_t line) { /* USER CODE BEGIN 6 */ /* User can add his own implementation to report the file name and line number, tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ /* USER CODE END 6 */ } #endif /* USE_FULL_ASSERT */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

你可能感兴趣的:(stm32,单片机,嵌入式硬件)