我是靠谱客的博主 粗暴酸奶,最近开发中收集的这篇文章主要介绍物联网项目之-------XF600 M5311NB模块移动卡 IIS328DQ 消防栓项目 调试记录,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

2019/2/21

现在单片机  STM32L151C8U6A+5311NB模块的电流 是  40uA左右

加速度 传感器的电流是 60uA左右,所以加起来差不多到100多uA了。

/** I2C Device Address 8 bit format  if SA0=0 -> 0x31 if SA0=1 -> 0x33 **/
#define IIS328DQ_I2C_ADD     0x33

/** I2C Device Address 8 bit format  if SA0=0 -> 0x31 if SA0=1 -> 0x33 **/
#define IIS328DQ_I2C_ADD     0x33
//以上这个引脚的电平是用于选择I2C器件地址的,如果为高 那么地址为 0x33 如果为低那么地址为0x31
//但是实际测试 知道 器件内部默认上拉了,如果外部还去下拉的话就会增加电流消耗,所以这个由于项目需要不
//能接下拉电阻,这个时候 传感器 IIS328DQ的功耗差不多在1Hz采集时候是10uA

上图当中注意 SA0不应该拉低,图上是错误的

现在程序将 功耗在100多uA-20多uA之间跳(这是由传感器的采集时候的功耗会上升,如果降低采集频率相应的功耗也会跳变的慢一些)。

在整个程序调试的过程当中  逻辑和功耗都出现了不少问题。这也是一些宝贵经验。单片机不管是软件还是硬件都很重要,有时候你明明觉得不是自己的问题,但是死后就是找不到原因。需要转换思路从多方面分析问题,一点点排查。

下面说一说此次项目的经历:

应用场景;消防栓塞帽。我们知道有时候户外的消防栓很多时候由于监管不及时,分散等原因。在出现故障,(例如被撞倒、被人为拧开、)很难即使发现,物联网出现很好的解决了这一问题。通过在消防栓上加装传感器和通信模块可以实现对消防栓状态的实时监控。防止意外事故的发生。废话说到这,下面谈一谈项目经历

首先说 NB模块 5311 的开发流程:

1.供电  

void MY_GPIO_Init(void)
{
  GPIO_InitTypeDef  GPIO_InitStructure;
 
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOB, ENABLE);
  //======================  默认端口 ==================================
  //PB5 用于A9500 开机
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1| GPIO_Pin_3;    
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;  
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;   
// GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOB, &GPIO_InitStructure);                      

 

    //PA1  用于A9500 供电
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_12 ;    
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;  
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;   
// GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  GPIO_Init(GPIOA, &GPIO_InitStructure); 

}

上面这一段是初始化我的 开机脚和pwerkey脚,

供电:我们的控制电路利用单片机上啦相关引脚给模块供电

#define LS_7030_PWH  (GPIO_SetBits(GPIOA, GPIO_Pin_1))

void NB_GONGdian(void)
{
    LS_7030_PWH;
    sysdelay(2000000);
}

2开机   

开机是给NB模块的pwerkey 脚一个低电平脉冲

void NBM5311_start(void)
{
    LS_7030_KEYH;
    sysdelay(2000000);
    LS_7030_KEYL;
    sysdelay(2000000);
}

  3 参数配置包括:

#define A9500_CLEAR_RECEIVE       Usart2_Clear()

void Usart2_Clear(void)
{
 memset(UART2_RX_BUF, '', UART2_MAX_RECV_LEN);
 UART2_Data_Length = 0;

}

bool M5311LianJIE(void)
{
    char q[30] = {0x00};
    char aH, aL;
GPRSRESTART:
    if(GInitNum >= 2) {
        GInitNum = 0;
        return false;
    }
    if(GInitNum != 0) {
        A9500_CLEAR_RECEIVE;
        A9500_USART_SEND(CMD_AT_CLOSE, strlen(CMD_AT_CLOSE));
        sysdelay(2000000);
        A9500_USART_SEND(CMD_AT_NRB, strlen(CMD_AT_NRB)); //
        sysdelay(2000000);
        NBM5311_start();
    }
    GInitNum++;
    for (int i = 0; i < 10; i++ ) {
        A9500_CLEAR_RECEIVE;
        A9500_USART_SEND("ATrn", strlen("ATrn")); //发送AT指令,查看是否开机
        sysdelay(200000);
        if(strstr(UART2_RX_BUF, strBakValueOK)) {
            A9500_CLEAR_RECEIVE;
            break;
        }
    }
    for (int i = 0; i < CYCLEINDEX; i++ ) {
        int snum = 0;
        A9500_CLEAR_RECEIVE;
        A9500_USART_SEND(CMD_AT_CGSN, strlen(CMD_AT_CGSN));
        sysdelay(250000);
        if(strstr(UART2_RX_BUF, strBakValueOK)) {
            memcpy(q, UART2_RX_BUF, strlen(UART2_RX_BUF));
            for(int i = 0; i < strlen(q); i++) {
                if(q[i] >= '0' && q[i] <= '9') {
                    snum = i;
                    break;
                }
            }
            USART0_TX_Buffer_GHI[3] = 0x00 | ((q[snum]) & 0x0f);
            USART0_TX_XT_GHI[3] = 0x00 | ((q[snum]) & 0x0f);
            for(int i = 1; i < 8; i++) {
                aH = q[++snum];
                aL = q[++snum];
                USART0_TX_Buffer_GHI[3 + i] = ((aH) & 0x0f) << 4 | ((aL) & 0x0f);  // ?? imei
                USART0_TX_XT_GHI[3 + i] = ((aH) & 0x0f) << 4 | ((aL) & 0x0f);  // ?? imei
            }

 

            break;
        } else {
            if (i <= (CYCLEINDEX - 2)) {
                continue;
            } else {
                goto GPRSRESTART;
            }

 

        }
    }

 

    for (int i = 0; i < 20; i++ ) {
        A9500_CLEAR_RECEIVE;
        A9500_USART_SEND("AT+CGATT?rn", strlen("AT+CGATT?rn")); //发送AT指令,查看是否开机
        Delay_ms(3000);
       //  IWDG_Feed();
        if(strstr(UART2_RX_BUF, strBakCGATT1)) {
            break;
        }
        else if(i >= 19)
        {
            A9500_CLEAR_RECEIVE;
            goto GPRSRESTART;
        }

    }
    for (int i = 0; i < CYCLEINDEX; i++ ) {
        int test1 = 0;
        A9500_CLEAR_RECEIVE;
        A9500_USART_SEND(CMD_AT_CSQ, strlen(CMD_AT_CSQ));
        sysdelay(100000);
        if(strstr(UART2_RX_BUF, strBakValueOK)) {
            memcpy(q, UART2_RX_BUF, strlen(UART2_RX_BUF));
            for(int j = 0; j < strlen(q); j++) {
                if( (q[j] >= '0') && (q[j] <= '9')) {
                    aH = q[j];
                    aL = q[j + 1];
                    if((aL == '9') && (aH == '9')) {
                        test1 = 0;
                    } else if((aL >= '0') && (aL <= '9')) {
                        //USART0_TX_Buffer[19] = ((aH)&0x0f)<<4|((aL)&0x0f);   // ?? ????
                        //Shangdata_Buffer[1]=((aH)&0x0f)<<4|((aL)&0x0f);
                        test1 = 1;
                    } else {
                        //USART0_TX_Buffer[19] = (((aH)&0x0f)|0x00);
                        //Shangdata_Buffer[1]=(((aH)&0x0f)|0x00);
                        test1 = 1;
                    }
                    break;
                }
//                if(aL>='0'&&aL<='9'){
//                  USART0_TX_Buffer[21] = ((aH)&0x0f)<<4|((aL)&0x0f);   // ?? ????
//                }else{
//                  USART0_TX_Buffer[21] = (((aH)&0x0f)|0x00);
//                }
//                test1 = 1;
//                break;
//              }
            }
        }
        if(test1 == 1) {
            test1 = 0;
            break;
        }
        if (i > (CYCLEINDEX - 2)) {
            A9500_CLEAR_RECEIVE;
            //goto GPRSRESTART;
        }
    }
    for(int i = 0; i < 5; i++)
    {
        A9500_CLEAR_RECEIVE;
        CounterTCP();
        Delay_ms(6000);
   // IWDG_Feed();
        if(strstr(UART2_RX_BUF, strBakValueM5311)) {
            A9500_CLEAR_RECEIVE;
            break;
        }
        else if(strstr(UART2_RX_BUF, strBakValueERROR))
        {
            A9500_CLEAR_RECEIVE;
            A9500_USART_SEND(CMD_AT_CLOSE, strlen(CMD_AT_CLOSE));
            sysdelay(2000000);
        }
    if(i>4)
    {
      A9500_CLEAR_RECEIVE;
           goto GPRSRESTART;
    }
    }
    Delay_ms(3000);
    GInitNum = 0;
    A9500_CLEAR_RECEIVE;
    return true;
}

int main(void)
{

 

    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置中断优先级分组2
    Base_TIM6_Init();
    MY_GPIO_AN();//全部 模拟输入

 

    USART_Config(115200);
    SYS_RTCInit(60 * 60 * 24); //12h 一分钟参数为6
    RTC_WakeUpCmd(DISABLE);
    ADC_SX_DMA_Config(); //初始化 四项电压采集 A 046
    MY_GPIO_Init();//9500开关
    NB_GONGdian();//5311供电
    NBM5311_start();//5311开机
    PeiZhiPSM();
 //my_iwdog();

 

    while (1)
    {
        IIS328DQ_Init();
        if((1 == QD_Wakeup_Flag) || (1 == C_RTC_Flag) || (1 == YL_Wakeup_Flag))
        {
            IIS328DQ_Init();
            aacx = iis328dq_acceleration_raw_X_LH_get();
            aacy = iis328dq_acceleration_raw_Y_LH_get();
            aacz = iis328dq_acceleration_raw_Z_LH_get();
            lmd = 16384 / 4; //计算 加速度计灵敏度
            ax = aacx / lmd; //x轴加速度
            ay = aacy / lmd;
            az = aacz / lmd;
            pr = -ax / sqrt(az * az + ay * ay);
            rr = ay / sqrt(az * az + ax * ax);
            zz = az / sqrt(ax * ax + ay * ay);
      //IWDG_Feed();

 

            pitch = ((atan(pr) * 180) / 3.1415926); //俯仰角
            roll = ((atan(rr) * 180) / 3.1415926); //横滚角  用于判断开盖
            yaw = ((atan(zz) * 180) / 3.1415926); //用于判断撞倒

 

            one_r = abs((int)roll);
            one_p = abs((int)pitch);
            one_y = abs((int)yaw);
            Open_Cover();//开盖报警
            if(Times>1)
            {
        QingWeiDongFlag =false;
                USART0_TX_Buffer_GHI[20] = 0x01;
                USART0_TX_XT_GHI[20] = 0x01;
            }
            else
            {
        QingWeiDongFlag = true;
                USART0_TX_Buffer_GHI[20] = 0x00;
                USART0_TX_XT_GHI[20] = 0x00;
            }
            if(one_y > 8) //判断是否撞倒
            {  
        // IWDG_Feed();
                ZhuangDaoFlag = true;
                USART0_TX_Buffer_GHI[19] = 0x01;
                USART0_TX_XT_GHI[19] = 0x01;
            }
            else if(one_y < 8) //大于0小于15没撞倒
            {
                ZhuangDaoFlag = false;
                USART0_TX_Buffer_GHI[19] = 0x00;
                USART0_TX_XT_GHI[19] = 0x00;
            }
            if((QingWeiDongFlag == false) || (ZhuangDaoFlag == true) || (YL_Wakeup_Flag == 1))
            {
        //IWDG_Feed();
                GpioState1 = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_11);
                if(1 == GpioState1) //高电平状态为正常
                {
                    YaLiSecetFlag = true;
                    USART0_TX_Buffer_GHI[18] = 0x0A;
                    USART0_TX_XT_GHI[18] = 0x0A;
                }
                else if(0 == GpioState1) //低电平状态为压力到来
                {
                    YaLiSecetFlag = true;
                    USART0_TX_Buffer_GHI[18] = 0x0F;
                    USART0_TX_XT_GHI[18] = 0x0F;
                }
                A9500_CLEAR_RECEIVE;

 

                MY_GPIO_Init();
                // NB_GONGdian();
                NBM5311_start();
        //IWDG_Feed();
                sysdelay(2000000);
                //PeiZhiPSM();
                QD_Wakeup_Flag = 0;
                YL_Wakeup_Flag = 0;
        
                if(M5311LianJIE())
                {
          //IWDG_Feed();

 

                    ADC_SX_DMA_Config(); //初始化 四项电压采集 A 046
                    C_Get_State();
                    //Lora_Isconnect();//退出透传进入指令模式
                    Send_Server();
                    CloseTCp();
                }
            }
            if(C_RTC_Flag == 1)
            {
                GpioState1 = GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_11);
                if(1 == GpioState1) //高电平状态为正常
                {
                    YaLiSecetFlag = true;
                    USART0_TX_Buffer_GHI[18] = 0x0A;
                    USART0_TX_XT_GHI[18] = 0x0A;
                }
                else if(0 == GpioState1) //低电平状态为压力到来
                {
                    YaLiSecetFlag = true;
                    USART0_TX_Buffer_GHI[18] = 0x0F;
                    USART0_TX_XT_GHI[18] = 0x0F;
                }
                A9500_CLEAR_RECEIVE;
                MY_GPIO_Init();
                //NB_GONGdian();
                NBM5311_start();
                sysdelay(2000000);
               // PeiZhiPSM();
                C_RTC_Flag = 0;
                if(M5311LianJIE())
                {      
         //IWDG_Feed();

                    ADC_SX_DMA_Config(); //初始化 四项电压采集 A 046
                    C_Get_State();
                    Send_heartbeat();
                    CloseTCp();
                }
            }
        }
        Turn_OFF_A9500();
        MY_GPIO_AN1();
        XF600_YaLiKaiGuang();   //压力开关中断触发
        mpu6050int_init(); //LSM6DSL中断初始化    
        RCC_Enter_Stop();
        MY_GPIO_Init();//9500开关
        USART_Config(115200);
        LS_7030_PWH;
    }//while
}//mian

最后

以上就是粗暴酸奶为你收集整理的物联网项目之-------XF600 M5311NB模块移动卡 IIS328DQ 消防栓项目 调试记录的全部内容,希望文章能够帮你解决物联网项目之-------XF600 M5311NB模块移动卡 IIS328DQ 消防栓项目 调试记录所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部