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:
- 7:5295cbdb123c
- Parent:
- 6:c3db4eff9170
- Child:
- 8:882a6cdb1bf3
- Child:
- 10:5f22ca6eb6cd
--- a/main.cpp Wed Jan 10 02:17:31 2018 +0000
+++ b/main.cpp Sat Jan 27 19:48:33 2018 +0000
@@ -27,8 +27,8 @@
SPI spi(MOSI_1, MISO_1, SCLK_1);
MAX11410 adc1(&spi,&cs_pin1);
MAX11410 adc2(&spi,&cs_pin2);
-//Serial pc(USBTX, USBRX,115200);
-Serial pc(USBTX, USBRX, 9600);
+Serial pc(USBTX, USBRX,115200);
+//Serial pc(USBTX, USBRX, 9600);
Serial rpi(PA_9,PA_10,115200);
void starting()
@@ -66,13 +66,20 @@
}
}
+
int main()
{
int32_t channel_data[10];
+ int32_t channel_data2[10];
+ int32_t checksum2 =0;
+ int32_t checksum = 0;
+ char checksum_byte = 0;
+ char byte2print[40];
double vdiff=0.01;
vOut1 = 0.5-vdiff/2;
vOut2 = 0.5+vdiff/2;
starting();
+
bool int_state;
spi.format(8,MAX11410_SPI_MODE); //configure number of spi bits 8, 16
spi.frequency(8000000); // Max 8MHz
@@ -152,6 +159,7 @@
while(!adc1.interrupt() )
{
wait_ms(CONV_DELAY_MS);//do nothing
+// pc.printf("waiting for int");
}
//read conversion
@@ -164,9 +172,9 @@
//config ADC 2: repeat above
-uint32_t checksum;
-char byte2print[40];
-
+
+ pc.printf("beginning while loop");
+ wait_ms(1000);
while(1)
{
for(int n=0; n<5; n++)
@@ -192,6 +200,7 @@
while(!adc1.interrupt() )
{
wait_ms(CONV_DELAY_MS);//do nothing
+// pc.printf("waiting for int");
}
//read conversion
@@ -233,6 +242,7 @@
{
checksum += channel_data[n];
}
+ checksum_byte = (char) checksum;
for (int n=0; n<10; n++)
{
@@ -250,7 +260,24 @@
{
rpi.putc(byte2print[n]);
}
- rpi.putc( (char) checksum );
+ rpi.putc( checksum_byte );
+// now reassemble the bits and print them
+
+ for (int n=0;n<10;n++)
+ {
+ channel_data2[n] = (byte2print[4*n]<<24 ) | ( byte2print[4*n+1]<<16 ) | ( byte2print[4*n+2] << 8 ) | byte2print[4*n+3];
+ }
+ pc.printf("orig reconstructed\r\n");
+ for (int n=0;n<10;n++)
+ {
+ pc.printf("%d, %d, %d\r\n",n,channel_data[n],channel_data2[n]);
+ }
+ checksum2 = 0;
+ for(int n=0;n<10;n++)
+ {
+ checksum2 += channel_data2[n];
+ }
+ pc.printf("checksum %02X, %08X, %08X\r\n",checksum_byte,checksum,checksum2);
} //end while
} //END MAIN
