![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
test program to test / develop the SOLID slow control
Dependencies: AD5384 SWSPI S25FL216K S_SCTRL_SMlib T_adt7320 adc_ad9249 sscm_comm mbed
main.cpp@0:35e1c447c9e8, 2014-09-23 (annotated)
- Committer:
- wbeaumont
- Date:
- Tue Sep 23 08:25:38 2014 +0000
- Revision:
- 0:35e1c447c9e8
- Child:
- 2:51bbbc3fc8c2
version with response from ADC
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wbeaumont | 0:35e1c447c9e8 | 1 | #include "mbed.h" |
wbeaumont | 0:35e1c447c9e8 | 2 | #include "mbed.h" |
wbeaumont | 0:35e1c447c9e8 | 3 | #include "SWSPI.h" |
wbeaumont | 0:35e1c447c9e8 | 4 | #include "SWSPI_BI.h" |
wbeaumont | 0:35e1c447c9e8 | 5 | #include "S25FL216K.h" |
wbeaumont | 0:35e1c447c9e8 | 6 | #include "AD5384.h" |
wbeaumont | 0:35e1c447c9e8 | 7 | #include "AD9249.h" |
wbeaumont | 0:35e1c447c9e8 | 8 | #include "S_SCTRL_SM1_PinDef.h" |
wbeaumont | 0:35e1c447c9e8 | 9 | #include "S_SCTRL_SM1_hwfunct.h" |
wbeaumont | 0:35e1c447c9e8 | 10 | |
wbeaumont | 0:35e1c447c9e8 | 11 | #define VERSION 1 |
wbeaumont | 0:35e1c447c9e8 | 12 | #define SUBVERSION 3 |
wbeaumont | 0:35e1c447c9e8 | 13 | #define DEBUGPF(x) printf((x)); |
wbeaumont | 0:35e1c447c9e8 | 14 | // pin function pin id |
wbeaumont | 0:35e1c447c9e8 | 15 | // SPI 1 |
wbeaumont | 0:35e1c447c9e8 | 16 | |
wbeaumont | 0:35e1c447c9e8 | 17 | |
wbeaumont | 0:35e1c447c9e8 | 18 | S25FL216K flash(F_MOSI, F_MISO, F_SCLK,F_CS); |
wbeaumont | 0:35e1c447c9e8 | 19 | Serial pc(USBTX,USBRX); |
wbeaumont | 0:35e1c447c9e8 | 20 | |
wbeaumont | 0:35e1c447c9e8 | 21 | |
wbeaumont | 0:35e1c447c9e8 | 22 | char c='.'; |
wbeaumont | 0:35e1c447c9e8 | 23 | void callback() { |
wbeaumont | 0:35e1c447c9e8 | 24 | // Note: you need to actually read from the serial to clear the RX interrupt |
wbeaumont | 0:35e1c447c9e8 | 25 | c = pc.getc(); |
wbeaumont | 0:35e1c447c9e8 | 26 | printf("%c:",c ); |
wbeaumont | 0:35e1c447c9e8 | 27 | } |
wbeaumont | 0:35e1c447c9e8 | 28 | |
wbeaumont | 0:35e1c447c9e8 | 29 | |
wbeaumont | 0:35e1c447c9e8 | 30 | //++++++++++++++++++++++ |
wbeaumont | 0:35e1c447c9e8 | 31 | int main() { |
wbeaumont | 0:35e1c447c9e8 | 32 | |
wbeaumont | 0:35e1c447c9e8 | 33 | pc.attach(&callback);// handles the input on the RS232 interface |
wbeaumont | 0:35e1c447c9e8 | 34 | HWlines hwl ; |
wbeaumont | 0:35e1c447c9e8 | 35 | assignports( &hwl ); |
wbeaumont | 0:35e1c447c9e8 | 36 | setdefault(hwl ); |
wbeaumont | 0:35e1c447c9e8 | 37 | |
wbeaumont | 0:35e1c447c9e8 | 38 | SWSPI spi(hwl.mosi[0],hwl.miso[0],hwl.sclk[0]); // mosi, miso, sclk |
wbeaumont | 0:35e1c447c9e8 | 39 | SWSPI spi2(hwl.mosi[1],hwl.miso[1],hwl.sclk[1]); // mosi, miso, sclk |
wbeaumont | 0:35e1c447c9e8 | 40 | SWSPI_BI spi_adc(hwl.msio[0],hwl.direction[0],hwl.stio_mo[0] ,hwl.sclk[0]); // msio, dir , sclk |
wbeaumont | 0:35e1c447c9e8 | 41 | SWSPI_BI spi_adc2(hwl.msio[1],hwl.direction[1],hwl.stio_mo[1],hwl.sclk[1]); // msio, dir , sclk |
wbeaumont | 0:35e1c447c9e8 | 42 | |
wbeaumont | 0:35e1c447c9e8 | 43 | |
wbeaumont | 0:35e1c447c9e8 | 44 | AD9249 adc[2][2]={AD9249( &spi_adc,hwl.csb1[0]), AD9249( &spi_adc,hwl.csb2[0]), |
wbeaumont | 0:35e1c447c9e8 | 45 | AD9249( &spi_adc2,hwl.csb1[1]), AD9249 ( &spi_adc2,hwl.csb2[1])}; |
wbeaumont | 0:35e1c447c9e8 | 46 | |
wbeaumont | 0:35e1c447c9e8 | 47 | AD5384 dac[2]={AD5384(&spi,hwl.dac_cs[0]), AD5384(&spi2,hwl.dac_cs[1]) }; |
wbeaumont | 0:35e1c447c9e8 | 48 | |
wbeaumont | 0:35e1c447c9e8 | 49 | //float humi; |
wbeaumont | 0:35e1c447c9e8 | 50 | |
wbeaumont | 0:35e1c447c9e8 | 51 | |
wbeaumont | 0:35e1c447c9e8 | 52 | |
wbeaumont | 0:35e1c447c9e8 | 53 | DEBUGPF("start"); |
wbeaumont | 0:35e1c447c9e8 | 54 | printf(" version %d.%02d compiled %s %s \n\r" , VERSION , SUBVERSION, __DATE__, __TIME__ ); |
wbeaumont | 0:35e1c447c9e8 | 55 | printf(" boardserialnr %d \n\r", get_serialnr(&hwl)); |
wbeaumont | 0:35e1c447c9e8 | 56 | u8 consel1=0; |
wbeaumont | 0:35e1c447c9e8 | 57 | u8 consel2=1; |
wbeaumont | 0:35e1c447c9e8 | 58 | u8 conls=0, conle=0; // connector select loop start , connector select loop stop |
wbeaumont | 0:35e1c447c9e8 | 59 | // cc == connector counter |
wbeaumont | 0:35e1c447c9e8 | 60 | if( consel1==1 && consel2== 0) { conls=0; conle=1;} // only first connector connected |
wbeaumont | 0:35e1c447c9e8 | 61 | else if( consel1==0 && consel2== 1) { conls=1; conle=2;} // only second connector connected |
wbeaumont | 0:35e1c447c9e8 | 62 | else if( consel1==1 && consel2== 1) { conls=0; conle=2;} // |
wbeaumont | 0:35e1c447c9e8 | 63 | else { conls=0; conle=0;} // no connectors connected |
wbeaumont | 0:35e1c447c9e8 | 64 | unsigned char id, grade ; |
wbeaumont | 0:35e1c447c9e8 | 65 | |
wbeaumont | 0:35e1c447c9e8 | 66 | |
wbeaumont | 0:35e1c447c9e8 | 67 | /* for (u8 cc= conls; cc < conle ; cc++) { |
wbeaumont | 0:35e1c447c9e8 | 68 | adc[cc][0].getDevInfo(id,grade);printf(" %d %d ",id, grade); |
wbeaumont | 0:35e1c447c9e8 | 69 | adc[cc][1].getDevInfo(id,grade);printf(" %d %d ",id, grade); |
wbeaumont | 0:35e1c447c9e8 | 70 | |
wbeaumont | 0:35e1c447c9e8 | 71 | }*/ |
wbeaumont | 0:35e1c447c9e8 | 72 | u32 count =0; |
wbeaumont | 0:35e1c447c9e8 | 73 | while(1) { |
wbeaumont | 0:35e1c447c9e8 | 74 | for (u8 cc= conls; cc < conle ; cc++) { |
wbeaumont | 0:35e1c447c9e8 | 75 | u16 rb,rb2; |
wbeaumont | 0:35e1c447c9e8 | 76 | adc[cc][0].getDevId(id); |
wbeaumont | 0:35e1c447c9e8 | 77 | adc[cc][0].getGrade(grade); |
wbeaumont | 0:35e1c447c9e8 | 78 | //adc[cc][0].getDevInfo(id,grade,rb); |
wbeaumont | 0:35e1c447c9e8 | 79 | printf("id %02X grade %02X",id, grade ); |
wbeaumont | 0:35e1c447c9e8 | 80 | printf("\n\r"); |
wbeaumont | 0:35e1c447c9e8 | 81 | adc[cc][0].setPattern1(0x1235); |
wbeaumont | 0:35e1c447c9e8 | 82 | adc[cc][0].setPattern2(0xA5FF); |
wbeaumont | 0:35e1c447c9e8 | 83 | adc[cc][0].readPattern1(rb); |
wbeaumont | 0:35e1c447c9e8 | 84 | adc[cc][0].readPattern2(rb2); |
wbeaumont | 0:35e1c447c9e8 | 85 | printf("pattern1 %04X pattern2 %04X",rb,rb2); |
wbeaumont | 0:35e1c447c9e8 | 86 | printf("\n\r"); |
wbeaumont | 0:35e1c447c9e8 | 87 | // dac[cc].set_volt(count%32,count%163834); |
wbeaumont | 0:35e1c447c9e8 | 88 | } |
wbeaumont | 0:35e1c447c9e8 | 89 | wait(.5);count++; |
wbeaumont | 0:35e1c447c9e8 | 90 | |
wbeaumont | 0:35e1c447c9e8 | 91 | /* |
wbeaumont | 0:35e1c447c9e8 | 92 | DEBUGPF("spi2\n\r"); |
wbeaumont | 0:35e1c447c9e8 | 93 | spi.format(8, 0); |
wbeaumont | 0:35e1c447c9e8 | 94 | spi.frequency(10000000); |
wbeaumont | 0:35e1c447c9e8 | 95 | cs.write(0); |
wbeaumont | 0:35e1c447c9e8 | 96 | spi.write(0x9f); |
wbeaumont | 0:35e1c447c9e8 | 97 | jedecid = (spi.write(0) << 16) | (spi.write(0) << 8) | spi.write(0); |
wbeaumont | 0:35e1c447c9e8 | 98 | cs.write(1); |
wbeaumont | 0:35e1c447c9e8 | 99 | printf( "Jedec %d /n/r", jedecid); |
wbeaumont | 0:35e1c447c9e8 | 100 | |
wbeaumont | 0:35e1c447c9e8 | 101 | DEBUGPF("spi3\n\r"); |
wbeaumont | 0:35e1c447c9e8 | 102 | spi_adc.format(8,0); |
wbeaumont | 0:35e1c447c9e8 | 103 | spi_adc.frequency(10000000); |
wbeaumont | 0:35e1c447c9e8 | 104 | cs_adc.write(0); |
wbeaumont | 0:35e1c447c9e8 | 105 | spi_adc.write(0x9f); |
wbeaumont | 0:35e1c447c9e8 | 106 | jedecid = (spi_adc.write(0) << 16) | (spi_adc.write(0) << 8) | spi_adc.write(0); |
wbeaumont | 0:35e1c447c9e8 | 107 | cs_adc.write(1); |
wbeaumont | 0:35e1c447c9e8 | 108 | char c=0x12; |
wbeaumont | 0:35e1c447c9e8 | 109 | flash.write(0,&c,1); |
wbeaumont | 0:35e1c447c9e8 | 110 | DEBUGPF("dacset"); |
wbeaumont | 0:35e1c447c9e8 | 111 | (void) dac.set_dac(4,2.21); |
wbeaumont | 0:35e1c447c9e8 | 112 | humi=ain1.read(); |
wbeaumont | 0:35e1c447c9e8 | 113 | printf("humid %f \n ",humi); |
wbeaumont | 0:35e1c447c9e8 | 114 | */ |
wbeaumont | 0:35e1c447c9e8 | 115 | } |
wbeaumont | 0:35e1c447c9e8 | 116 | } |
wbeaumont | 0:35e1c447c9e8 | 117 | |
wbeaumont | 0:35e1c447c9e8 | 118 |