//主函数初始化部分 u1_printf("Usart_Init success \r\n"); OLED_Init(); //初始化OLED u1_printf("LOED_INIT success \r\n"); OLED_Clear(0); //清屏(全黑) u1_printf("LOED_Clear success \r\n"); TEST_Chinese(); //OLED显示中文 u1_printf("LOED_show success \r\n"); while(DHT11_Init()) //DHT11初始化 { u1_printf("DHT11_INIT error \r\n"); } u1_printf("DHT11_INIT success \r\n"); //OLED初始化代码 #include "oled.h" #include "stdlib.h" #include "string.h" #include "delay.h" #include "spi.h" //OLED显存总共分为8页 //每页8行,一行128个像素点 //OLED的显存 //存放格式如下. //[0]0 1 2 3 ... 127 (0~7)行 //[1]0 1 2 3 ... 127 (8~15)行 //[2]0 1 2 3 ... 127 (16~23)行 //[3]0 1 2 3 ... 127 (24~31)行 //[4]0 1 2 3 ... 127 (32~39)行 //[5]0 1 2 3 ... 127 (40~47)行 //[6]0 1 2 3 ... 127 (48~55)行 //[7]0 1 2 3 ... 127 (56~63)行 //数组每个bit存储OLED每个像素点的颜色值(1-亮(白色),0-灭(黑色)) //每个数组元素表示1列8个像素点,一共128列 static unsigned char OLED_buffer[1024] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, }; /******************************************************************* * @name :void OLED_WR_Byte(unsigned dat,unsigned cmd) * @function :Write a byte of content to the OLED screen * @parameters :dat:Content to be written cmd:0-write command 1-write data * @retvalue :None ********************************************************************/ void OLED_WR_Byte(unsigned dat,unsigned cmd) { if(cmd) { OLED_DC_Set(); } else { OLED_DC_Clr(); } OLED_CS_Clr(); SPI_WriteByte(SPI2,dat); OLED_CS_Set(); } /******************************************************************* * @name :void OLED_Set_Pos(unsigned char x, unsigned char y) * @function :Set coordinates in the OLED screen * @parameters :x:x coordinates y:y coordinates * @retvalue :None ********************************************************************/ void OLED_Set_Pos(unsigned char x, unsigned char y) { OLED_WR_Byte(YLevel+y/PAGE_SIZE,OLED_CMD); OLED_WR_Byte((((x+2)&0xf0)>>4)|0x10,OLED_CMD); OLED_WR_Byte(((x+2)&0x0f),OLED_CMD); } /******************************************************************* * @name :void OLED_Display_On(void) * @function :Turn on OLED display * @parameters :None * @retvalue :None ********************************************************************/ void OLED_Display_On(void) { OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC命令 OLED_WR_Byte(0X14,OLED_CMD); //DCDC ON OLED_WR_Byte(0XAF,OLED_CMD); //DISPLAY ON } /******************************************************************* * @name :void OLED_Display_Off(void) * @function :Turn off OLED display * @parameters :None * @retvalue :None ********************************************************************/ void OLED_Display_Off(void) { OLED_WR_Byte(0X8D,OLED_CMD); //SET DCDC命令 OLED_WR_Byte(0X10,OLED_CMD); //DCDC OFF OLED_WR_Byte(0XAE,OLED_CMD); //DISPLAY OFF } /******************************************************************* * @name :void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color) * @function :set the value of pixel to RAM * @parameters :x:the x coordinates of pixel y:the y coordinates of pixel color:the color value of the point 1-white 0-black * @retvalue :None ********************************************************************/ void OLED_Set_Pixel(unsigned char x, unsigned char y,unsigned char color) { if(color) { OLED_buffer[(y/PAGE_SIZE)*WIDTH+x]|= (1<<(y%PAGE_SIZE))&0xff; } else { OLED_buffer[(y/PAGE_SIZE)*WIDTH+x]&= ~((1<<(y%PAGE_SIZE))&0xff); } } /******************************************************************* * @name :void OLED_Display(void) * @function isplay in OLED screen * @parameters :None * @retvalue :None ********************************************************************/ void OLED_Display(void) { u8 i,n; for(i=0;i<AGE_SIZE;i++) { OLED_WR_Byte (YLevel+i,OLED_CMD); //设置页地址(0~7) OLED_WR_Byte (XLevelL,OLED_CMD); //设置显示位置—列低地址 OLED_WR_Byte (XLevelH,OLED_CMD); //设置显示位置—列高地址 for(n=0;n<WIDTH;n++) { OLED_WR_Byte(OLED_buffer[i*WIDTH+n],OLED_DATA); } } //更新显示 } /******************************************************************* * @name :void OLED_Clear(unsigned dat) * @function :clear OLED screen * @parameters :dat:0-Display full black 1-Display full white * @retvalue :None ********************************************************************/ void OLED_Clear(unsigned dat) { if(dat) { memset(OLED_buffer,0xff,sizeof(OLED_buffer)); } else { memset(OLED_buffer,0,sizeof(OLED_buffer)); } OLED_Display(); } /******************************************************************* * @name :void OLED_Reset(void) * @function :Reset OLED screen * @parameters :dat:0-Display full black 1-Display full white * @retvalue :None ********************************************************************/ void OLED_Reset(void) { OLED_RST_Set(); delay_ms(100); OLED_RST_Clr(); delay_ms(100); OLED_RST_Set(); } /******************************************************************* * @name :void OLED_Init_GPIO(void) * @function :Reset OLED screen * @parameters :None * @retvalue :None ********************************************************************/ void OLED_Init_GPIO(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //使能B端口时钟 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12; //GPIOB10,11,12 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//速度50MHz GPIO_Init(GPIOB, &GPIO_InitStructure); //初始化GPIOB10、11、12 GPIO_SetBits(GPIOB,GPIO_Pin_10|GPIO_Pin_11|GPIO_Pin_12); } /******************************************************************* * @name :void OLED_Init(void) * @function :initialise OLED SH1106 control IC * @parameters :None * @retvalue :None ********************************************************************/ void OLED_Init(void) { SPI2_Init(); //初始化SPI2 OLED_Init_GPIO(); //初始化GPIO delay_ms(200); OLED_Reset(); //复位OLED /**************初始化SSD1306*****************/ OLED_WR_Byte(0xAE,OLED_CMD); /*display off*/ OLED_WR_Byte(0x00,OLED_CMD); /*set lower column address*/ OLED_WR_Byte(0x10,OLED_CMD); /*set higher column address*/ OLED_WR_Byte(0x40,OLED_CMD); /*set display start line*/ OLED_WR_Byte(0xB0,OLED_CMD); /*set page address*/ OLED_WR_Byte(0x81,OLED_CMD); /*contract control*/ OLED_WR_Byte(0xFF,OLED_CMD); /*128*/ OLED_WR_Byte(0xA1,OLED_CMD); /*set segment remap*/ OLED_WR_Byte(0xA6,OLED_CMD); /*normal / reverse*/ OLED_WR_Byte(0xA8,OLED_CMD); /*multiplex ratio*/ OLED_WR_Byte(0x3F,OLED_CMD); /*duty = 1/64*/ OLED_WR_Byte(0xC8,OLED_CMD); /*Com scan direction*/ OLED_WR_Byte(0xD3,OLED_CMD); /*set display offset*/ OLED_WR_Byte(0x00,OLED_CMD); OLED_WR_Byte(0xD5,OLED_CMD); /*set osc division*/ OLED_WR_Byte(0x80,OLED_CMD); OLED_WR_Byte(0xD9,OLED_CMD); /*set pre-charge period*/ OLED_WR_Byte(0XF1,OLED_CMD); OLED_WR_Byte(0xDA,OLED_CMD); /*set COM pins*/ OLED_WR_Byte(0x12,OLED_CMD); OLED_WR_Byte(0xDB,OLED_CMD); /*set vcomh*/ OLED_WR_Byte(0x30,OLED_CMD); OLED_WR_Byte(0x8D,OLED_CMD); /*set charge pump disable*/ OLED_WR_Byte(0x14,OLED_CMD); OLED_WR_Byte(0xAF,OLED_CMD); /*display ON*/ } //SPI2初始化 void SPI2_Init(void) { SPI_InitTypeDef SPI_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; //配置SPI2管脚 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOB, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_15; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); //SPI2配置选项 RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2 ,ENABLE); SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//全双工 SPI_InitStructure.SPI_Mode = SPI_Mode_Master;//主机模式 SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;//SPI数据大小 SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;//空闲状态时SCK 的状态,这里为高下面为2,这里为低下面为1 SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;//偶数沿边采样 SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;//NSS接口由软件操作 SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_2;//时钟的预分频 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;//MSB高位在前 SPI_InitStructure.SPI_CRCPolynomial = 7;//CRC校验 SPI_Init(SPI2, &SPI_InitStructure);//初始化SPI2总线 //使能SPI2 SPI_Cmd(SPI2, ENABLE); } #include "dht11.h" #include "delay.h" //复位DHT11 void DHT11_Rst(void) { DHT11_IO_OUT(); //SET OUTPUT DHT11_DQ_OUT=0; //拉低DQ Delay_Ms(20); //拉低至少18ms DHT11_DQ_OUT=1; //DQ=1 Delay_Us(30); //主机拉高20~40us } //等待DHT11的回应 //返回1:未检测到DHT11的存在 //返回0:存在 u8 DHT11_Check(void) { u8 retry=0; DHT11_IO_IN();//SET INPUT while (DHT11_DQ_IN&&retry<100)//DHT11会拉低40~80us { retry++; Delay_Us(1); }; if(retry>=100)return 1; else retry=0; while (!DHT11_DQ_IN&&retry<100)//DHT11拉低后会再次拉高40~80us { retry++; Delay_Us(1); }; if(retry>=100)return 1; return 0; } //从DHT11读取一个位 //返回值:1/0 u8 DHT11_Read_Bit(void) { u8 retry=0; while(DHT11_DQ_IN&&retry<100)//等待变为低电平 { retry++; Delay_Us(1); } retry=0; while(!DHT11_DQ_IN&&retry<100)//等待变高电平 { retry++; Delay_Us(1); } Delay_Us(40);//等待40us if(DHT11_DQ_IN)return 1; else return 0; } //从DHT11读取一个字节 //返回值:读到的数据 u8 DHT11_Read_Byte(void) { u8 i,dat; dat=0; for (i=0;i<8;i++) { dat<<=1; dat|=DHT11_Read_Bit(); } return dat; } //从DHT11读取一次数据 //temp:温度值(范围:0~50°) //humi:湿度值(范围:20%~90%) //返回值:0,正常;1,读取失败 u8 DHT11_Read_Data(u8 *temp,u8 *humi) { u8 buf[5]; u8 i; DHT11_Rst(); if(DHT11_Check()==0) { for(i=0;i<5;i++)//读取40位数据 { buf=DHT11_Read_Byte(); } if((buf[0]+buf[1]+buf[2]+buf[3])==buf[4]) { *humi=buf[0]; *temp=buf[2]; } }else return 1; return 0; } //初始化DHT11的IO口 DQ 同时检测DHT11的存在 //返回1:不存在 //返回0:存在 u8 DHT11_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能PG端口时钟 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; //PG11端口配置 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStructure); //初始化IO口 GPIO_SetBits(GPIOA,GPIO_Pin_11); //PG11 输出高 DHT11_Rst(); //复位DHT11 return DHT11_Check();//等待DHT11的回应 } |
stm32进入stop模式被莫名其妙唤醒(应该是systick)但是无法被WKUP引脚唤醒。
头文件找不到
软件为keil5,头文件未找到
通过FATFS文件系统读写SD卡创建文件可以了,但加入MSC,一直显示一个没有格式化的U盘盘符,也不能格式化,这是什么问题导致的
stm32f103汇编求助
cubemx 生成的freertos代码 在keil ac6下不能编译,有什么解决的方法吗
报错Could not determine GDB version using command: arm-none-eabi-gdb --version
stm32f107vct6配RTL8201例程
L9663驱动开发
STM32F103VGT6 能代替 STM32F103VFT6 吗?
功能的异常。建议你重点检查下有无GPIO管脚复用冲突的问题。尽量使用CubeMx进行初始配置,这样很容易发现管脚冲突方面的问题。再就是,你软件上可以先大刀阔斧地先屏蔽可能导致问题的代码,然后逐步增加功能模块,看看哪里会产生问题,这样慢慢定位查找。
因为oled程序是我要添加到主程序的,主程序是阿里云的数据数据上下发。顺序是线初始化串口、定时器、DHT11,再连接wifi和阿里云设备。这两个程序分开都是能正常运行,但是把oled程序引入主程序就出问题了。
NVIC_Configuration(); //设置NVIC中断分组2:2位抢占优先级,2位响应优先级
Delay_Init(); //延时功能初始化
led_init(); //灯光初始化
SG90_Init(); //舵机初始化
Usart1_Init(9600); //串口1功能初始化,波特率9600,调试串口
Usart2_Init(115200); //串口2功能初始化,波特率115200 ,上传数据串口
TIM4_Init(300,7200); //TIM4初始化,定时时间 300*7200*1000/72000000 = 30ms
// KEY_Init(); //按键初始化
while(DHT11_Init()) //DHT11初始化
{
u1_printf("DHT11_INIT error \r\n");
}
u1_printf("DHT11_INIT success \r\n");
WiFi_ResetIO_Init(); //初始化WiFi的复位IO
MQTT_Buff_Init(); //初始化接收,发送,命令数据的 缓冲区 以及各状态参数
AliIoT_Parameter_Init(); //初始化连接阿里云IoT平台MQTT服务器的参数
然后没有添加oled的话,各功能都是正常的,但是添加了oled之后,不管在放在哪里初始化,oled初始化之后的其他模块初始化都会出问题,比如放在dht11初始化之前,程序就会卡在dht11初始化,因为dht11要获取到引脚状态之后才能初始化成功。
u8 DHT11_Check(void)
{
u8 retry=0;
DHT11_IO_IN();//SET INPUT
while (DHT11_DQ_IN&&retry<100)//DHT11会拉低40~80us
{
retry++;
Delay_Us(1);
};
if(retry>=100)return 1;
else retry=0;
while (!DHT11_DQ_IN&&retry<100)//DHT11拉低后会再次拉高40~80us
{
retry++;
Delay_Us(1);
};
if(retry>=100)return 1;
return 0;
}
如果放在dht11之后,wifi又会连不上,然后oled的所有引脚都是PB组的包括B11,B12,1B3,B15,dht11是PA11,串口引脚定义是A2,A3,A9,A10,也就是串口1串口2,开发板是stm32f103c8t6,然后开发板上就还只有两个舵机的引脚B5和B6,这样的话引脚应该不冲突吧。