AD2ch Module library for MCU Gear with LPC1114. It contains wiring data.

AD2chModuleLPC1114

(日本語は英語の次に書いてあります。)

This library is for MCU Gear 12bit AD 2ch module with LPC1114FN28. You do not need thik about wiring to AD 2ch module. It contain wiring setting function.

http://www.mcugear.com/en/

How to use it?

include

#include "mbed.h"

#include "MCUGearBaseALPC1114.h"
#include "MCUGearALPC1114.h"
#include "commonALPC1114.h"

#include "AD2chModuleLPC1114.h"

You need SPI bus, cs pin and I2C bus.

bus

SPI spi(dp2, dp1, dp6); // mosi, miso, sclk
DigitalOut cs(dp25); //for SPI communications

make MCU Gear instance.

MCU Gear instance

MCUGear AD2(dp5, dp27, N_SCL_SCL_VSS);        //AD 2ch Module

Save location data in the instance.

detect location

    AD2.detectModule();    //save location data in MCUGear class.

make ADmodule instance.

ADmodule instance

    AD2chModule myAD2(spi,dp25,&AD2); //make instance for AD module

There are 2 type of AD function. These are similar operation,

1, separately connect (you can check the operation separately.)

1, separately connect

        myAD2.initAD2ch(&AD2);
        AD2.connectModuleA();
        data = myAD2.readADm(&AD2, 0); //0ch
        pc.printf("AD 0ch = %d  ",data);
        data = myAD2.readADm(&AD2, 1); //1ch
        pc.printf("AD 1ch = %d\r\n",data);
        AD2.disconnectModule();

2, automatically connect (It is similar to separately connection but little bit slow. )

1, manually connect

        data = myAD2.readADa(&AD2,0); //0ch
        pc.printf("AD 0ch = %d  ",data);
        data = myAD2.readADa(&AD2,1); //1ch
        pc.printf("AD 1ch = %d\r\n",data);

The sample progarm is here.

sample

#include "mbed.h"

#include "MCUGearBaseALPC1114.h"
#include "MCUGearALPC1114.h"
#include "commonALPC1114.h"

#include "AD2chModuleLPC1114.h"

Serial pc(dp16, dp15); // tx, rx Set BaudRate = 115200 in main()
SPI spi(dp2, dp1, dp6); // mosi, miso, sclk
DigitalOut cs(dp25); //for SPI communications

MCUGear AD2(dp5, dp27, N_SCL_SCL_VSS);        //AD 2ch Module

//output pins = P0_3, P0_7, P0_11, P1_0, P1_1, P1_2, P1_4, P1_5
DigitalOut Dout1(dp26);
DigitalOut Dout2(dp28);
DigitalOut Dout3(dp4);
DigitalOut Dout4(dp9);
DigitalOut Dout5(dp10);
DigitalOut Dout6(dp11);
DigitalOut Dout7(dp14);
DigitalOut Dout8(dp15);

//inputpins = P1_8, P1_9
DigitalIn Din1(dp17);
DigitalIn Din2(dp18);

int main() {
    
    pc.printf("Hello World!\r\n");
        
    wait(1);
    
    initBase(); //initialize Baseboard
    
    AD2.detectModule();    //save location data in MCUGear class.
    AD2chModule myAD2(spi,dp25,&AD2); //make instance for AD module
    
    int data = 0;
    
    while(1) {
/*
        //manually connect      
        myAD2.initAD2ch(&AD2);
        AD2.connectModuleA();
        data = myAD2.readADm(&AD2, 0);
        pc.printf("AD 0ch = %d  ",data);
        data = myAD2.readADm(&AD2, 1);
        pc.printf("AD 1ch = %d\r\n",data);
        AD2.disconnectModule();
*/        
        //automatically connect
        data = myAD2.readADa(&AD2,0);  //0ch
        pc.printf("AD 0ch = %d  ",data);
        data = myAD2.readADa(&AD2,1);   //1ch
        pc.printf("AD 1ch = %d\r\n",data);
        
        wait(0.5);

    }
}

このライブラリはMCU Gear の12bit AD 2ch モジュールをLPC1114で使用する場合のライブラリです。 ライブラリの中に配線情報が入っているため、回路に差し込むだけで簡単に使用できます。

http://www.mcugear.com/

使い方

include

#include "mbed.h"

#include "MCUGearBaseALPC1114.h"
#include "MCUGearALPC1114.h"
#include "commonALPC1114.h"

#include "AD2chModuleLPC1114.h"

SPI、cs, I2Cを準備します。

bus

SPI spi(dp2, dp1, dp6); // mosi, miso, sclk
DigitalOut cs(dp25); //for SPI communications

MCU Gear のインスタンスを作ります。

MCU Gear instance

MCUGear AD2(dp5, dp27, N_SCL_SCL_VSS);        //AD 2ch Module

次に接続位置を保存します。

detect location

    AD2.detectModule();    //save location data in MCUGear class.

DAモジュール のインスタンスを作り先ほどのインスタンスに渡します。

ADmodule instance

    AD2chModule myAD2(spi,dp25,&AD2); //make instance for AD module

ライブラリには2つの種類がありますが、処理をバラバラに行いたい場合と、まとめて一行で行いたい場合とで使い分けてください。 結果は同じものです。

1, separately connect (you can check the operation separately.)

1, separately connect

        myAD2.initAD2ch(&AD2);
        AD2.connectModuleA();
        data = myAD2.readADm(&AD2, 0); //0ch
        pc.printf("AD 0ch = %d  ",data);
        data = myAD2.readADm(&AD2, 1); //1ch
        pc.printf("AD 1ch = %d\r\n",data);
        AD2.disconnectModule();

2, automatically connect (same as separately connect )

1, manually connect

        data = myAD2.readADa(&AD2,0); //0ch
        pc.printf("AD 0ch = %d  ",data);
        data = myAD2.readADa(&AD2,1); //1ch
        pc.printf("AD 1ch = %d\r\n",data);

以下、サンプルプログラムです。

sample

#include "mbed.h"

#include "MCUGearBaseALPC1114.h"
#include "MCUGearALPC1114.h"
#include "commonALPC1114.h"

#include "AD2chModuleLPC1114.h"

Serial pc(dp16, dp15); // tx, rx Set BaudRate = 115200 in main()
SPI spi(dp2, dp1, dp6); // mosi, miso, sclk
DigitalOut cs(dp25); //for SPI communications

MCUGear AD2(dp5, dp27, N_SCL_SCL_VSS);        //AD 2ch Module

//output pins = P0_3, P0_7, P0_11, P1_0, P1_1, P1_2, P1_4, P1_5
DigitalOut Dout1(dp26);
DigitalOut Dout2(dp28);
DigitalOut Dout3(dp4);
DigitalOut Dout4(dp9);
DigitalOut Dout5(dp10);
DigitalOut Dout6(dp11);
DigitalOut Dout7(dp14);
DigitalOut Dout8(dp15);

//inputpins = P1_8, P1_9
DigitalIn Din1(dp17);
DigitalIn Din2(dp18);

int main() {
    
    pc.printf("Hello World!\r\n");
        
    wait(1);
    
    initBase(); //initialize Baseboard
    
    AD2.detectModule();    //save location data in MCUGear class.
    AD2chModule myAD2(spi,dp25,&AD2); //make instance for AD module
    
    int data = 0;
    
    while(1) {
/*
        //manually connect      
        myAD2.initAD2ch(&AD2);
        AD2.connectModuleA();
        data = myAD2.readADm(&AD2, 0);
        pc.printf("AD 0ch = %d  ",data);
        data = myAD2.readADm(&AD2, 1);
        pc.printf("AD 1ch = %d\r\n",data);
        AD2.disconnectModule();
*/        
        //automatically connect
        data = myAD2.readADa(&AD2,0);  //0ch
        pc.printf("AD 0ch = %d  ",data);
        data = myAD2.readADa(&AD2,1);   //1ch
        pc.printf("AD 1ch = %d\r\n",data);
        
        wait(0.5);

    }
}


All wikipages