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.
Fork of MAX11410-test by
Diff: main.cpp
- Revision:
- 6:c3db4eff9170
- Parent:
- 5:d7b803aa9079
- Child:
- 7:5295cbdb123c
--- a/main.cpp Fri Jan 05 22:37:07 2018 +0000
+++ b/main.cpp Wed Jan 10 02:17:31 2018 +0000
@@ -18,6 +18,8 @@
#define MISO_1 D12
#define SCLK_1 D13
#define VDD 3.3
+
+
AnalogOut vOut1(A3);
AnalogOut vOut2(A4);
DigitalOut cs_pin1(CS1);
@@ -27,6 +29,7 @@
MAX11410 adc2(&spi,&cs_pin2);
//Serial pc(USBTX, USBRX,115200);
Serial pc(USBTX, USBRX, 9600);
+Serial rpi(PA_9,PA_10,115200);
void starting()
{
@@ -34,7 +37,10 @@
}
-
+char getNthByte(int32_t data, int ind)
+{
+ return (data>>(8*ind)) & 0x000000FF ;
+}
void print8bitRegsAdc1(char start_reg,char end_reg)
@@ -63,7 +69,7 @@
int main()
{
int32_t channel_data[10];
- float vdiff=0.01;
+ double vdiff=0.01;
vOut1 = 0.5-vdiff/2;
vOut2 = 0.5+vdiff/2;
starting();
@@ -158,10 +164,93 @@
//config ADC 2: repeat above
+uint32_t checksum;
+char byte2print[40];
-// while(1)
-// {
-//
-// }
+ while(1)
+ {
+ for(int n=0; n<5; n++)
+ {
+ //read each channel
+ //select channel
+ char p_ch = 2*n<<4;
+ char n_ch = 2*n+1;
+ adc1.write8bitReg(REG_MUX_CTRL0, p_ch | n_ch );
+
+ //select data output register and begin conversion
+ adc1.write8bitReg(REG_CONV_START, (_DEST(n) | SINGLE_CONV) );
+
+ //optional: cal Gain
+
+ //optional: cal Offset
+
+ //optional: store cal parameters
+
+ //begin conversion
+
+ //wait for interrupt
+ while(!adc1.interrupt() )
+ {
+ wait_ms(CONV_DELAY_MS);//do nothing
+ }
+
+ //read conversion
+ channel_data[n] = adc1.read24bitsSigned(REG_DATA0+n,&int_state);
+
+ }
+ for(int n=0; n<5; n++)
+ {
+ //read each channel
+ //select channel
+ char p_ch = 2*n<<4;
+ char n_ch = 2*n+1;
+ adc2.write8bitReg(REG_MUX_CTRL0, p_ch | n_ch );
+
+ //select data output register and begin conversion
+ adc2.write8bitReg(REG_CONV_START, (_DEST(n) | SINGLE_CONV) );
+
+ //optional: cal Gain
+
+ //optional: cal Offset
+
+ //optional: store cal parameters
+
+ //begin conversion
+
+ //wait for interrupt
+ while(!adc2.interrupt() )
+ {
+ wait_ms(CONV_DELAY_MS);//do nothing
+ }
+
+ //read conversion
+ channel_data[n+5] = adc2.read24bitsSigned(REG_DATA0+n,&int_state);
+ }
+
+ // calc checksum
+ checksum=0;
+ for (int n=0; n<10; n++)
+ {
+ checksum += channel_data[n];
+ }
+
+ for (int n=0; n<10; n++)
+ {
+ for(int m=0;m<4;m++)
+ {
+ byte2print[n*4+m] = getNthByte(channel_data[n],3-m);
+ }
+ }
+ //print data and checksum
+
+ // print header 0x6601
+ rpi.putc(0x66);
+ rpi.putc(0x01);
+ for (int n =0; n<40;n++)
+ {
+ rpi.putc(byte2print[n]);
+ }
+ rpi.putc( (char) checksum );
+ } //end while
} //END MAIN
