Lin Team / Mbed 2 deprecated AD7190_LoRa

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /* -- MBED - AD7190
00002 
00003 Porting by Rododo Science. .... 2019/9/13
00004 
00005 -- */
00006 
00007 
00008 #include "mbed.h"
00009 #include "AD7190.h"
00010 SPI spi(D11, D12, D13); // mosi, miso, sclk
00011 DigitalOut cs(D10);      // Different CS operations
00012 DigitalIn  ad_rdy(D9);  // Use of a _RDY Pin
00013 
00014 Serial uart(PC_4, PC_5);//TX4,RX4
00015 int idx=0;
00016 
00017 Serial pc(USBTX, USBRX); // tx, rx
00018 
00019 void setup()
00020 {
00021     cs.write(1);
00022     wait(1);
00023     pc.printf("Example Start\n");
00024     cs.write(0);
00025     while(AD7190_Init(800)==0){
00026     pc.printf("Can't allocate AD7190\n");
00027     wait(5);
00028     }
00029 
00030     /* Calibrates channel AIN3(+) - AIN4(-).  */ 
00031     AD7190_Calibrate(AD7190_MODE_CAL_INT_ZERO, AD7190_CH_AIN3P_AIN4M);
00032 
00033 }
00034 
00035 void loop()
00036 {
00037 
00038     unsigned long val = AD7190_TemperatureRead();
00039     //pc.printf("Temperature = \t =%lu \r\n", val);
00040 
00041     AD7190_ChannelSelect(AD7190_CH_AIN1P_AIN2M);
00042     /* Selects unipolar operation and ADC's input range to +-Vref/1. plesase refer AD7190_CONF_GAIN(x) */
00043     AD7190_RangeSetup(0, AD7190_CONF_GAIN_64);
00044     
00045     //val = AD7190_SingleConversion();
00046     //pc.printf("ADC = \t%lu \r\n", val);
00047 
00048     val = AD7190_ContinuousReadAvg(8);
00049     //pc.printf("ADC_avg = \t%lu \r\n", val);
00050     
00051     double voltageAn34 =  ( val * 0.00000011921 - 1 ) * 4.096 /64 ; //AIN=(輸出碼/2^23-1)*(Vref/gain)
00052    
00053     
00054     pc.printf("%f \r\n", voltageAn34);
00055     
00056      uart.printf("s%f# \r\n", voltageAn34);
00057    
00058     idx=idx+1;
00059     wait(0.01);
00060     //pc.printf("TX send s %f #\r\n",voltageAn34);
00061     //wait(1);
00062   
00063 
00064 }
00065 
00066 
00067 //---DON'T CHANGE BELOW----
00068 // MBED compensate
00069 // main() runs in its own thread in the OS
00070 int main() {
00071     //---Enable Debug---
00072     pc.baud(9600);
00073     uart.baud(9600);
00074     //--Mark out to disable debug
00075     setup();
00076     while (true) {
00077         loop();
00078         
00079             
00080     }
00081 }