Sample program for lpc1768 with 8ch ADC and Library TRP105F_Spline.
Dependencies: mbed TRP105F_Spline
Diff: main.cpp
- Revision:
- 0:b76e3288e79a
- Child:
- 1:b53d82528534
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jun 01 05:39:10 2016 +0000 @@ -0,0 +1,80 @@ +#include "mbed.h" +#include "TRP105F_Spline.h" + +Serial pc(USBTX, USBRX); // tx, rx ( the usb serial communication ) +extern AnalogIn g_Sensor_Voltage; +SPI spi; // mosi(out), miso(in), sclk(clock) +DigitalOut cs; // cs (the chip select signal) +DigitalOut myled1(LED1),myled2(LED2); +Timer t; + + +// For SPI +int DAread(int channel) +{ + int command_high=0x06|((channel&0x04)>>2); + int command_low=(channel&0x03)<<14; + __disable_irq(); // 割り込み禁止 + cs = 0; + spi.write(command_high); + int resultbyte=spi.write(command_low) & 0xfff; + cs = 1; + __enable_irq(); // 割り込み許可 + return(resultbyte); +} + +class SPI_TRP105FS +{ + TRP105FS trp(5); + unsigned int channel; + + void setSample(unsigned short arg_x) { + trp.setSample(arg_x, (unsigned short)DAread(channel)); + } + void calibrate(){ + trp.calibrate(); + } + unsigned short get +} +TRP105FS senseor[8]; +int main() { + // Setup the spi for 7 bit data, high steady state clock, + // second edge capture, with a 1MHz clock rate + spi.format(16,0); + spi.frequency(1000000); + + myled1 = 1; + //pc.printf("start\n"); + pc.printf("\nload save-data or calibration[l/c]>"); + if(pc.getc() == 'l'){ + pc.printf("\n"); + //sensor.loadSetting(); + sensor0.loadSetting("savedata.log"); + } + else { + pc.printf("\n"); + sensor0.calibrateSensor(); + sensor0.printOutData(); + sensor0.saveSetting("savedata.log"); + } + myled2 = 1; + unsigned short dst; + while(1) { + t.start(); + dst=sensor0.getDistance(); + t.stop(); + pc.printf("dst:%d(%f s)\n",dst, t.read()); + t.reset(); + //pc.printf("vol:%d",g_Sensor_Voltage.read_u16()); + pc.printf("vol:%d",DAread(0)); + wait(0.5); + pc.putc('\n'); + if(pc.readable())if(pc.getc() == 'q') break; + }/* + while(1){ + myled2 = 1; + pc.printf("vol:%d\n",DAread(1)); + }*/ + myled1 = myled2 = 0; + +}