#ifndef __ADS1220_H #define __ADS1220_H // #include "main.h" #include #include #include #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_system.h" #include "driver/spi_master.h" #include "driver/gpio.h" typedef uint8_t u8; typedef uint32_t u32; typedef int32_t s32; #define ADS1220_HOST SPI2_HOST #define SPI2_PIN_NUM_MISO 6 #define SPI2_PIN_NUM_MOSI 5 #define SPI2_PIN_NUM_CLK 16 #define SPI2_PIN_NUM_CS 15 #define PARALLEL_LINES 16 #define ADS1220_nCS_HIGH() gpio_set_level(GPIO_NUM_38, 1) #define ADS1220_nCS_LOW() gpio_set_level(GPIO_NUM_38, 0) #define ADS1220_CMD_WREG 0x40 #define ADS1220_CMD_RREG 0x20 #define ADS1220_CMD_RESET 0x06 #define ADS1220_CMD_START 0x08 #define ADS1220_CMD_POWERDOWN 0x02 #define ADS1220_CMD_RDATA 0x10 #define Channal1 0x00 #define Channal2 0x10 #define Channal3 0x20 #define Channal4 0x30 #define ADS1220_REG0 0x00 #define ADS1220_REG1 0x01 #define ADS1220_REG2 0x02 #define ADS1220_REG3 0x03 #define PGAGain1 0x00 #define PGAGain2 0x02 #define PGAGain4 0x04 #define PGAGain8 0x06 #define PGAGain16 0x08 #define PGAGain32 0x0A #define PGAGain64 0x0C #define PGAGain128 0x0E #define ADS1220_Standby 0 #define ADS1220_ConvStart 1 #define ADS1220_ConvFinish 2 #define ADS1220_Channal1 0 #define ADS1220_Channal2 1 #define ADS1220_Channal3 2 #define ADS1220_Channal4 3 #define GPIO_INPUT_IO_39 7 #define GPIO_INPUT_PIN_SEL (1ULL << GPIO_INPUT_IO_39) #define ESP_INTR_FLAG_DEFAULT 0 typedef struct { int ch0_4ma; int ch0_12ma; float ch0_4ma_yl; float ch0_12ma_yl; int ch1_4ma; int ch1_12ma; float ch1_4ma_yl; float ch1_12ma_yl; int ch2_4ma; int ch2_12ma; float ch2_4ma_yl; float ch2_12ma_yl; }ads_cali_t; //extern ads_cali_t ads_cali; uint32_t get_now_20us(void); int32_t tim_diff(uint32_t a,uint32_t b); int ADS1220_get_rate(void); void ADS1220_set_rate(int i); void ADS1220_Init(void); // ADS1220��ʼ�� void ADS1220_Config(void); // ADS1220���� void ADS1220_StartConv(u8 channal); // ADS1220����ת�� void ADS1220_Reset(void); // ADS1220��λ void ADS1220_PowerDown(void); // ADS1220�������ģʽ void ADS1220_PGASet(u8 gain); // ADS1220 PGA���� void ADS1220_WriteCommand(u8 cmd); // ADS1220д���� s32 ADS1220_ReadData(void); // ADS1220������ void ADS1220_WriteReg(u8 reg,u8 dat); // ADS1220д�Ĵ��� u8 ADS1220_ReadReg(u8 reg); // ADS1220���Ĵ��� u8 ADS1220_ReadWriteByte(u8 dat); // ��SPI������д��һ�ֽ� u32 ADS1220_ReadWrite24Bits(u32 dat); // ��ADS1220������д��24Bits void zero_flow1(void); int scale(int raw, int raw_min, int raw_max,int eng_min, int eng_max); #endif