Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
init.h
00001 #define byte unsigned char 00002 #define uint32 unsigned long 00003 #define uint16 unsigned short 00004 //#define debug 1 00005 #define BUF_SIZE 512 00006 00007 /* Test specific constants */ 00008 #define CMD_ID 0x00 // return requested ID msg 00009 #define CMD_ADC 0x01 // trigger ADC sampling loop 00010 #define CMD_DAC 0x21 // control the DAC 00011 #define CMD_IDAC 0x22 // send DAC init command 00012 #define CMD_DAC_WR 0x23 // send DAC control command 00013 #define CMD_ADC_RD 0x81 // requested ADC values 00014 #define CMD_VSAMPL 0x82 // set DAC and sample adc values 00015 #define CMD_DAC_RD 0x83 // read DAC register 00016 00017 // some more may be added 00018 00019 #define mbed_SlaveAddr 0x22 00020 00021 __packed struct ADC_CmdSet { 00022 byte adc_reg_width; /* 1 or 2 byte register address width */ 00023 byte adc_samples; /* Number of ADC samples per DAC step */ 00024 byte slv_addr; /* pmic slave address */ 00025 uint16 man_trig_reg; /* register address to control manual conv. */ 00026 byte man_trig_val; /* adc manual control value */ 00027 byte man_conv_mask; /* adc mask to detect manuanl conv. done */ 00028 uint16 adc_lsb_reg; /* register address for adc value readout */ 00029 }; 00030 00031 00032 char INBUF[64]; // set to the biggest CmdSet 00033 00034 // reserve data buffer unsigned int for adc values 00035 uint16 ADC_BUF[BUF_SIZE] __attribute__ ((section("AHBSRAM0"))); 00036 00037 DigitalOut led_1(LED1); 00038 DigitalOut cs0(p8); // SYNC signal for DAC 00039 00040 I2C mI2C(p28, p27); 00041 I2CSlave sI2C(p9, p10); 00042 SPI spi(p5, p6, p7); // mosi, miso, sclk 00043 #ifdef debug 00044 Serial pc(USBTX, USBRX); 00045 #endif 00046 00047 char IDSTR[] = "mbed_DAC-ADC-control rev 1.1\n"; 00048 // SDODIS=0, 2sC=1, DACTRI=0, OPGND=0, RBUF=1, RW=0, Control Register 00049 byte DAC_INIT_CMD [3] = {0x20, 0x00, 0x12}; // MSB first 00050 byte DAC_ZERO_CMD [3] = {0x18, 0x00, 0x00}; // 0V if VREFpos = 5V and VREFneg = -5V 00051 00052 char BUSY = 0; 00053 char ADC_SAMPLES = 0; 00054 struct ADC_CmdSet ADC_CMD[1]; 00055 00056 00057 void sample_adc(); 00058 void dac_wr(byte *cmd); 00059 void set_dac(byte *dn_value);
Generated on Thu Jul 14 2022 04:58:45 by
1.7.2