推荐星级:
  • 1
  • 2
  • 3
  • 4
  • 5

STM32F407单片机24bit_ADC_AD7190称重模块+电流采集实验KEIL工程源码

更新时间:2021-09-07 17:20:27 大小:7M 上传用户:xzxbybd查看TA发布的资源 标签:stm32f407单片机集keil 下载积分:7分 评价赚积分 (如何评价?) 打赏 收藏 评论(0) 举报

资料介绍

int main(void)

{

  float data_temp;      

  int32_t weight_count;  

  uint8_t cali_flag=0;

  /* 复位所有外设,初始化Flash接口和系统滴答定时器 */

  HAL_Init();

  /* 配置系统时钟 */

  SystemClock_Config();


  /* 初始化串口并配置串口中断优先级 */

  MX_DEBUG_USART_Init();

  /* 初始化LED */

  LED_GPIO_Init(); 

  

  KEY_GPIO_Init();

  /* 初始化BEEP */

  BEEP_GPIO_Init();

  /********************************电流采集模块初始化******************************/  

  /* 初始化AD7190检测通信状态 */

  if(AD7190_Init()==0)

  {

    printf("获取不到 AD7190 !\n");

    while(1)

    {

      HAL_Delay(1000);

      if(AD7190_Init())

        break;

    }

  }

  printf("检测到  AD7190 !\n");

  /* AD7190四路单端采集配置 */

  ad7190_unipolar_multichannel_conf();

  flag=1;


  

  /********************************电子秤初始化************************************/

  if(WEIGHT_Init()==0)

  {

    printf("获取不到 WEIGHT模块 !\n");

    while(1)

    {

      HAL_Delay(1000);

      if(WEIGHT_Init())

        break;

    }

  }

  printf("检测到  WEIGHT_Init !\n");

  weight_conf();

  

  HAL_Delay(500);

  weight_Zero_Data = weight_ReadAvg(6);

  printf("zero:%d\n",weight_Zero_Data);

  while(1)

  {

    weight_count=weight_ReadAvg(3);

    data_temp=weight_count-weight_Zero_Data;

    weight=data_temp*1000/weight_proportion;

    printf("重量:%d->%.2f\n",weight_count,weight);

    HAL_Delay(500);

    if(KEY1_StateRead()==KEY_DOWN)  // 清零

    {      

      weight_Zero_Data = weight_ReadAvg(6);

      printf("zero:%d\n",weight_Zero_Data);

      cali_flag=1;

    }

    if(KEY2_StateRead()==KEY_DOWN) // 校准:必须先按“清零”键,然后把20g砝码放在称上,按下校准键

    {

      if(cali_flag)

      {

        weight_count = weight_ReadAvg(6);

        weight_proportion=(weight_count-weight_Zero_Data)*1000/100;

        printf("weight_proportion:%d\n",weight_proportion);

      }

      cali_flag=0;

    }

    if(flag==2)

    {

      current_data[number]=ad7190_data[number]>>4;

      current_data[number]=current_data[number]*REFERENCE_VOLTAGE/0xFFFFF*1000/SAMPLE_RESISTANCE+error_compensation[number];

      printf("电流值:%d. 0x%05X->%0.3fmA\n",number,ad7190_data[number],current_data[number]/1000);

      flag=1;

    } 

  }

}


/**

  * 函数功能: 滴答定时回调函数

  * 输入参数: 无

  * 返 回 值: 无

  * 说    明: 无

  */

void HAL_SYSTICK_Callback(void)

{

  if((flag)&&(AD7190_RDY_STATE==0))

  {

    uint8_t sample[4];

    int8_t temp;

    /* SPI接收数据 */

    HAL_SPI_Receive(&hspi_AD7190,sample,4,0xFF); 

    if((sample[3]&0x80)==0)

    {

      temp=(sample[3]&0x07)-4;

      if(temp>=0)

      {

        flag=2;

        ad7190_data[temp]=((sample[0]<<16) | (sample[1]<<8) | sample[2]);

        number=temp;

      }

      else

      {

        printf("error:0x%X\n",sample[3]);

        flag++;

        if(flag>=10)

        {

          flag=0;

          printf("失败!!!\n"); 

        }       

      }

    }

  }


部分文件列表

文件名文件大小修改时间
YSF4_HAL_AD_DA-100. 24bit_ADC_AD7190称重模块+电流采集/.mxproject6KB2017-03-31 17:13:56
YSF4_HAL_AD_DA-100. 24bit_ADC_AD7190称重模块+电流采集/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f401xc.h707KB2017-05-27 11:05:48
YSF4_HAL_AD_DA-100. 24bit_ADC_AD7190称重模块+电流采集/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f401xe.h707KB2017-05-27 11:05:48
YSF4_HAL_AD_DA-100. 24bit_ADC_AD7190称重模块+电流采集/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f405xx.h1203KB2017-05-27 11:05:48
YSF4_HAL_AD_DA-100. 24bit_ADC_AD7190称重模块+电流采集/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.h1316KB2017-05-27 11:05:48
YSF4_HAL_AD_DA-100. 24bit_ADC_AD7190称重模块+电流采集/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f410cx.h591KB2017-05-27 11:05:48
YSF4_HAL_AD_DA-100. 24bit_ADC_AD7190称重模块+电流采集/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f410rx.h592KB2017-05-27 11:05:48
YSF4_HAL_AD_DA-100. 24bit_ADC_AD7190称重模块+电流采集/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f410tx.h587KB2017-05-27 11:05:48
YSF4_HAL_AD_DA-100. 24bit_ADC_AD7190称重模块+电流采集/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f411xe.h710KB2017-05-27 11:05:48
YSF4_HAL_AD_DA-100. 24bit_ADC_AD7190称重模块+电流采集/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f412cx.h1141KB2017-05-27 11:05:48
YSF4_HAL_AD_DA-100. 24bit_ADC_AD7190称重模块+电流采集/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f412rx.h1227KB2017-05-27 11:05:48
...

全部评论(0)

暂无评论

上传资源 上传优质资源有赏金

  • 打赏
  • 30日榜单

推荐下载