san m
/
WeightScale
Weight scale using ADS1220
Fork of WeightScale by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "ADS1220.h" 00003 #include "math.h" 00004 00005 00006 #define PGA 128 // Programmable Gain = 1 00007 #define VREF 5.0 // Internal reference of 2.048V 00008 #define VFSR VREF/PGA 00009 #define FSR (((long int)1<<23)) 00010 #define LSB_Size (VFSR/FSR) 00011 00012 ADS1220 ads1220_com(SPI_MOSI, SPI_MISO, SPI_SCK,SPI_CS); 00013 Serial data_serial(USBTX, USBRX); 00014 InterruptIn DRDY(PC_5); 00015 00016 00017 00018 00019 00020 bool New_data_avialable; 00021 void ext_int_DRDY(void); 00022 float code2volt(float c); 00023 00024 signed long tData; 00025 float volt; 00026 00027 int main() 00028 { 00029 data_serial.baud(115200); 00030 wait(0.1); 00031 DRDY.rise(&ext_int_DRDY); 00032 ads1220_com.Config(); 00033 ads1220_com.SendStartCommand(); 00034 while(1) 00035 { 00036 if(New_data_avialable) 00037 { 00038 New_data_avialable = 0; 00039 tData = ads1220_com.ReadData(); 00040 volt = code2volt(tData); 00041 data_serial.printf("\rVoltage : %f\n",volt); 00042 } 00043 } 00044 } 00045 00046 float code2volt(float c) 00047 { 00048 float Vout = 0; 00049 Vout = (float)(c*LSB_Size*1000); //In mV 00050 return Vout; 00051 } 00052 00053 void ext_int_DRDY(void) 00054 { 00055 New_data_avialable = 1; 00056 }
Generated on Fri Jul 22 2022 15:02:09 by 1.7.2