实验室 0
<div style="padding-left: 60px;">
<div class="vditor-reset"style="max-width: 800px;">第一篇内容:总体设计/系统功能介绍/机智云自助开发平台-开发利器GAgent等等
点击下载:【Io开发笔记】机智云智能浇花器实战(1)-基础Demo实现
第二篇内容:
继电器实现/功能测试/DHT11驱动代码实现/OLED屏幕显示传感器数据/中文字模制作等等
点击下载:机智云智能浇花器实战(2)-基础Demo实现
一,BH1750光照传感器原理图
二,BH1750传感器代码
- #include "bh1750.h"
- #include "delay.h"
- uint8_t BUF[8]; //接收数据缓存区
- int mcy; //进位标志
- / 开始信号 /
- void BH1750_Start()
- {
- BH1750_SDA_H; //拉高数据线
- BH1750_SCL_H; //拉高时钟线
- Delay_nus(5); //延时
- GPIO_ResetBits(BH1750_PORT, BH1750_SDA_PIN); //产生下降沿
- Delay_nus(5); //延时
- GPIO_ResetBits(BH1750_PORT, BH1750_SCL_PIN); //拉低时钟线
- }
- / 停止信号 /
- void BH1750_Stop()
- {
BH1750_SCL_H; //拉高时钟线GPIO_SetBits(BH1750_PORT, BH1750_SDA_PIN); //产生上升沿
- }
- /******************
- 发送应答信号
- 入口参数:ack (0:ACK 1:NAK)
- ******************/
- void BH1750_SendACK(int ack)
- {
GPIO_InitTypeDef GPIO_InitStruct;BH1750_SDA_H;- 一下活动板块都不显示 888 25 1218 282 9
复制代码 BH1750_SDA_L;return;mcy = 1 ;
- BH1750_SCL_L; //拉低时钟线
- Delay_nus(5); //延时
- GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
- GPIO_Init(BH1750_PORT,&GPIO_InitStruct);
return mcy;GPIO_SetBits(BH1750_PORT,BH1750_SDA_PIN);GPIO_ResetBits(BH1750_PORT,BH1750_SDA_PIN);BH1750_SCL_H; //拉高时钟线BH1750_SCL_L; //拉低时钟线<ol start="95">}
BH1750_RecvACK();
}
uint8_t BH1750_RecvByte()
{
uint8_t i;
uint8_t dat = 0;
uint8_t bit;
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPU; /这里一定要设成输入上拉,否则不能读出数据/
GPIO_InitStruct.GPIO_Pin = BH1750_SDA_PIN;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(BH1750_PORT,&GPIO_InitStruct );
GPIO_SetBits(BH1750_PORT,BH1750_SDA_PIN); //使能内部上拉,准备读取数据,
for (i=0; iyear,ptime->month,ptime->day,ptime->hour,ptime->minute,ptime->second,ptime->ntp);</p>case MODULE_INFO:#if MODULE_TYPE//Format By gprsInfo_tGIZWITS_LOG("WIF MODULE ...
");GIZWITS_LOG("moduleType : [%d]
",ptModuleInfo->moduleType);break;break;
- }
- return 0;
- }
- void userHandle(void)
- {
- /*
currentDataPoint.valueTemp = ;//Add Sensor Data CollectioncurrentDataPoint.valueLight_Intensity = ;//Add Sensor Data CollectioncurrentDataPoint.valueRelay_1 = 0;currentDataPoint.valueHumi = 0;
- }
- void gizTimerMs(void)
- {
timerMsCount++;
- }
- void mcuRestart(void)
- {
__set_FAULTMASK(1);
- }
- void TIMER_IRQ_FUN(void)
- {
- gizTimerMs();
- }
- void UART_IRQ_FUN(void)
- {
- uint8_t value = 0;
- gizPutData(&value, 1);
- }
- int32_t uartWrite(uint8_t *buf, uint32_t len)
- {
uint32_t i = 0;{}{while(USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET); //循环发送,直到发送完毕{while (USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET); //循环发送,直到发送完毕}复制代码
5,修改
- #ifndef _GIZWITS_PRODUCT_H
- #define _GIZWITS_PRODUCT_H
- #ifdef __cplusplus
- extern "C" {
- #endif
- #include
- //#include "stm32f1xx.h"
- #include"gizwits_protocol.h"
- /**
- */
- #define SOFTWARE_VERSION "03030000"
- /**
- */
- #define HARDWARE_VERSION "03010100"
- /**
- Communication module model
- */
- #define MODULE_TYPE 0 //0,WIFI ;1,GPRS
- /**@name TIM3 related macro definition
- */
- #define TIMER TIM3
- #define TIMER_IRQ TIM3_IRQn
- #define TIMER_RCC RCC_APB1Periph_TIM3
- #define TIMER_IRQ_FUN TIM3_IRQHandler
- /**@} */
- /**@name USART related macro definition
- */
- #define UART_BAUDRATE 9600
- #define UART_PORT 2
- #define UART USART2
- #define UART_IRQ USART2_IRQn
- #define UART_IRQ_FUN USART2_IRQHandler
- #if (UART_PORT == 1)
- #define UART_GPIO_Cmd RCC_APB2PeriphClockCmd
- #define UART_GPIO_CLK RCC_APB2Periph_GPIOA
- #define UART_AFIO_Cmd RCC_APB2PeriphClockCmd
- #define UART_AFIO_CLK RCC_APB2Periph_AFIO
- #define UART_CLK_Cmd RCC_APB2PeriphClockCmd
- #define UART_CLK RCC_APB2Periph_USART1
- #define UART_GPIO_PORT GPIOA
- #define UART_RxPin GPIO_Pin_10
- #define UART_TxPin GPIO_Pin_9
- #endif
- #if (UART_PORT == 2)
- #define UART_GPIO_Cmd RCC_APB2PeriphClockCmd
- #define UART_GPIO_CLK RCC_APB2Periph_GPIOA
- #define UART_AFIO_Cmd RCC_APB2PeriphClockCmd
- #define UART_AFIO_CLK RCC_APB2Periph_AFIO
- #define UART_CLK_Cmd RCC_APB1PeriphClockCmd
- #define UART_CLK RCC_APB1Periph_USART2
- #define UART_GPIO_PORT GPIOA
- #define UART_RxPin GPIO_Pin_3
- #define UART_TxPin GPIO_Pin_2
- #endif
- #if (UART_PORT == 3)
- #define UART_GPIO_Cmd RCC_APB2PeriphClockCmd
- #define UART_GPIO_CLK RCC_APB2Periph_GPIOC
- #define UART_AFIO_Cmd RCC_APB2PeriphClockCmd
- #define UART_AFIO_CLK RCC_APB2Periph_AFIO
- #define UART_CLK_Cmd RCC_APB1PeriphClockCmd
- #define UART_CLK RCC_APB1Periph_USART3
- #define UART_GPIO_PORT GPIOC
- #define UART_RxPin GPIO_Pin_11
- #define UART_TxPin GPIO_Pin_10
- #endif
- /**@} */
- /** User area the current device state structure*/
- extern dataPoint_t currentDataPoint;
- voidgizTimerMs(void);
- uint32_tgizGetTimerCount(void);
- voidtimerInit(void);
- voiduartInit(void);
- voiduserInit(void);
- voiduserHandle(void);
- voidmcuRestart(void);
- int32_tuartWrite(uint8_t *buf, uint32_t len);
- int8_tgizwitsEventProcess(eventInfo_t *info, uint8_t *data, uint32_t len);
- #ifdef __cplusplus
- }
- #endif
- #endif
复制代码
5,修改gizwits_product.h
Listitem
Listitem
Listitem
Listitem
Listitem
- /**
- @Brief Corresponding gizwits_product.c header file (including product hardware and software version definition)
Gizwits Smart Cloud for Smart Productswww.gizwits.com
- */
- int32_t gizPutData(uint8_t *buf, uint32_t len)
- {
int32_t count = 0;{return -1;count = rbWrite(&pRb, buf, len);{return -1;return count;{return -1;memset((uint8_t *)head, 0, sizeof(protocolHead_t));head->head[1] = 0xFF;
- }
- /**
- @brief Protocol ACK check processing function
- @param [in] data : data adress
- @param [in] len : data length
- @return 0, suceess; other, failure
- */
- static int8_t gizProtocolWaitAck(uint8_t *gizdata, uint32_t len)
- {
if(NULL == gizdata)GIZWITS_LOG("ERR: data is empty
");}memcpy((uint8_t *)gizwitsProtocol.waitAck.buf, gizdata, len);gizwitsProtocol.waitAck.flag = 1;return 0;{return -1;/** Greater than 1 byte to do bit conversion **/{{return -1;}{info->num++;}
- }
- /**
- @brief contrasts the current data with the last data
- @param [in] cur: current data point data
- @param [in] last: last data point data
- @return: 0, no change in data; 1, data changes
- */
- static int8_t ICACHE_FLASH_ATTR gizCheckReport(dataPoint_t *cur, dataPoint_t *last)
- {
int8_t ret = 0;uint32_t currentTime = 0;{
[code]实验室 |