|
本帖最后由 Seasonic 于 2018-12-26 16:35 编辑
要求:通过手机上的机智云通用APP,点亮开发板载LED0、LED1
摘要
- 硬件组成:STM32F407ZGT6+esp8266(乐鑫)
- 软件APP:机智云开发都者中心下载的通用APP Demo;Xcom串口调试助手;Keil V5;
- 调试过程详解:
- 注意事项:
- 使用机智云后的几点建议:
一、硬件组成如下图所示:
(硬件全家福:开发板(STM32F407ZGT6+ESP8266) 该开发板IO口配置: KEY1: PE4; KEY2: PA0;
LED0: PF10; LED1: PF9;
二、下载通用APP DEMO: 下载页面:https://download.gizwits.com/zh-cn/p/98/99 根据自己的手机系统,选择下载相应的APP,如下图所示:
3.安装、注册、登陆后如下图所示:
三、调试过程详解:- 创建数据点
- 生成MCU工程
- 下载MCU工程并根据开发板原理图修改工程,修改的地方如程序中红色加注释的部分
main.c 中加入红色标出的GPIO初始化代码
- static void MX_GPIO_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStruct;
- /* GPIO Ports Clock Enable */
- __HAL_RCC_GPIOE_CLK_ENABLE();
- __HAL_RCC_GPIOH_CLK_ENABLE();
- __HAL_RCC_GPIOA_CLK_ENABLE();
- <font color="#ff0000"> __HAL_RCC_GPIOF_CLK_ENABLE(); //GPIOF CLK Enable:Used to Ctrol LED</font>
- /*Configure GPIO pins : KEY2_Pin KEY1_Pin */
- GPIO_InitStruct.Pin = KEY2_Pin|KEY1_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
- GPIO_InitStruct.Pull = GPIO_PULLUP;
- HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
-
- /*Configure GPIO pin Output Level */
- <font color="#ff0000"> HAL_GPIO_WritePin(GPIOE, LED1_Pin|LED0_Pin, GPIO_PIN_SET);
- /*Configure GPIO pins : LED1_Pin LED0_Pin */
- GPIO_InitStruct.Pin = LED1_Pin|LED0_Pin;
- GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
- GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
- HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);</font>
- }
复制代码 main.h头文件中增加以下内容- /* USER CODE BEGIN Private defines */
- <font color="#ff0000">#define LED1_Pin GPIO_PIN_9
- #define LED1_GPIO_Port GPIOF
- #define LED0_Pin GPIO_PIN_10
- #define LED0_GPIO_Port GPIOF</font>
- /* USER CODE END Private defines */
复制代码
gizwits_product.c中需要用户添设备上电状态代码如下图所示- void userInit(void)
- {
- memset((uint8_t*)¤tDataPoint, 0, sizeof(dataPoint_t));
-
- /** Warning !!! DataPoint Variables Init , Must Within The Data Range **/
-
- currentDataPoint.valueValve = 0;
- currentDataPoint.valueLED0 = 1;
- currentDataPoint.valueLED1 = 1;
- currentDataPoint.valueState = 1;
- currentDataPoint.valueValue = 5;
- }
复制代码
gizwits_product.c中需要用户添加的代码如下图所示
- int8_t gizwitsEventProcess(eventInfo_t *info, uint8_t *gizdata, uint32_t len)
- {
- uint8_t i = 0;
- dataPoint_t *dataPointPtr = (dataPoint_t *)gizdata;
- moduleStatusInfo_t *wifiData = (moduleStatusInfo_t *)gizdata;
- protocolTime_t *ptime = (protocolTime_t *)gizdata;
-
- #if MODULE_TYPE
- gprsInfo_t *gprsInfoData = (gprsInfo_t *)gizdata;
- #else
- moduleInfo_t *ptModuleInfo = (moduleInfo_t *)gizdata;
- #endif
- if((NULL == info) || (NULL == gizdata))
- {
- return -1;
- }
- for(i=0; i<info->num; i++)
- {
- switch(info->event[i])
- {
- case EVENT_Valve:
- currentDataPoint.valueValve = dataPointPtr->valueValve;
- GIZWITS_LOG("Evt: EVENT_Valve %d \n", currentDataPoint.valueValve);
- if(0x01 == currentDataPoint.valueValve)
- {
- //user handle
- <font color="#ff0000">HAL_GPIO_TogglePin(LED1_GPIO_Port,LED1_Pin); //led1闪烁 ,没有阀,用灯替代
- HAL_Delay(500);
- HAL_GPIO_TogglePin(LED0_GPIO_Port,LED0_Pin); //led0闪烁 没有阀,用灯替代
- HAL_Delay(500);</font>
- }
- else
- {
- //user handle
- <font color="#ff0000"> HAL_GPIO_WritePin(LED1_GPIO_Port,LED1_Pin,GPIO_PIN_SET); //熄灭led1
- HAL_GPIO_WritePin(LED0_GPIO_Port,LED0_Pin,GPIO_PIN_SET); //熄灭led0 </font>
- }
- break;
- case EVENT_LED0:
- currentDataPoint.valueLED0 = dataPointPtr->valueLED0;
- GIZWITS_LOG("Evt: EVENT_LED0 %d \n", currentDataPoint.valueLED0);
- if(0x01 == currentDataPoint.valueLED0)
- {
- //user handle
- <font color="#ff0000">HAL_GPIO_WritePin(GPIOF,GPIO_PIN_10,GPIO_PIN_RESET); //点亮led0 </font>
- }
- else
- {
- //user handle
- <font color="#ff0000"> HAL_GPIO_WritePin(GPIOF,GPIO_PIN_10,GPIO_PIN_SET); //熄灭led0</font>
-
- }
- break;
- case EVENT_LED1:
- currentDataPoint.valueLED1 = dataPointPtr->valueLED1;
- GIZWITS_LOG("Evt: EVENT_LED1 %d \n", currentDataPoint.valueLED1);
- if(0x01 == currentDataPoint.valueLED1)
- {
- //user handle
- <font color="#ff0000"> HAL_GPIO_WritePin(GPIOF,GPIO_PIN_9,GPIO_PIN_RESET); //点亮led1 </font>
- }
- else
- {
- //user handle
- <font color="#ff0000"> HAL_GPIO_WritePin(GPIOF,GPIO_PIN_9,GPIO_PIN_SET); //灭掉led1</font>
- }
- break;
- case WIFI_SOFTAP:
- break;
- case WIFI_AIRLINK:
- break;
- case WIFI_STATION:
- break;
- case WIFI_CON_ROUTER:
-
- break;
- case WIFI_DISCON_ROUTER:
-
- break;
- case WIFI_CON_M2M:
-
- break;
- case WIFI_DISCON_M2M:
- break;
- case WIFI_RSSI:
- GIZWITS_LOG("RSSI %d\n", wifiData->rssi);
- break;
- case TRANSPARENT_DATA:
- GIZWITS_LOG("TRANSPARENT_DATA \n");
- //user handle , Fetch data from [data] , size is [len]
- break;
- case WIFI_NTP:
- GIZWITS_LOG("WIFI_NTP : [%d-%d-%d %02d:%02d:%02d][%d] \n",ptime->year,ptime->month,ptime->day,ptime->hour,ptime->minute,ptime->second,ptime->ntp);
- break;
- case MODULE_INFO:
- GIZWITS_LOG("MODULE INFO ...\n");
- #if MODULE_TYPE
- GIZWITS_LOG("GPRS MODULE ...\n");
- //Format By gprsInfo_t
- #else
- GIZWITS_LOG("WIF MODULE ...\n");
- //Format By moduleInfo_t
- GIZWITS_LOG("moduleType : [%d] \n",ptModuleInfo->moduleType);
- #endif
- break;
- default:
- break;
- }
- }
- return 0;
- }
复制代码
4.程序烧录:使用FlyMCU进行程序烧写,
5.打开APP操控体验
6.打开Xcom查看调试信息
四、注意事项:- 正确找出开发板的UART2接口:本开发板中对应关系如下:UART2_TX:PA2,UART2_RX:PA3,
- 保证与ESP8266模块的管脚接线正确:V3.3(接开发板3.3V);
GND(接开发板GND);
TX (接开发板的PA3管脚);
RX (接开发板的PA2管脚);
3.由于本次使用的ESP8266是原来机智云二代产品上的,可能正常联上机智云,故没有给ESP8266烧写固件,关于固件烧写的内容,请参阅论坛的相关文档。
|
|