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.
Diff: main.cpp
- Revision:
- 4:e0dbf2bdb967
- Parent:
- 3:a8c38c3fe967
- Child:
- 5:630aefee388b
--- a/main.cpp Fri Mar 16 18:35:06 2018 +0000 +++ b/main.cpp Sat Mar 17 04:43:32 2018 +0000 @@ -29,14 +29,14 @@ // 3 - 2048 // 4 - 4096 MS5611(&D1,&D2,4); - pc.printf("D1 = %i\r\nD2 = %i\r\n",D1,D2); + pc.printf("%i\t%i\t",D1,D2); MS5611_phys(D1,D2,PROM,&T,&P); - pc.printf("Temperature = %f deg C\r\n",T/100.0); - pc.printf("Pressure = %f mbar\r\n",P/100.0); + pc.printf("%f\t",T/100.0); + pc.printf("%f\r\n",P/100.0); - wait(10.0); + wait(1.0); } } @@ -96,9 +96,9 @@ if(spi.write(0x00)!=0xfe) { // can I have the result?; pc.printf("Error reading D1\r\n"); } - register uint8_t d1h=spi.write(0x00); - register uint8_t d1m=spi.write(0x00); - register uint8_t d1l=spi.write(0x00); + *D1=((uint32_t) spi.write(0x00))<<16; + *D1|=((uint32_t) spi.write(0x00))<<8; + *D1|=((uint32_t) spi.write(0x00)); cs.write(1); // and terminate the command wait_us(10); // Pause after putting CSB high cs.write(0); // Enable the MS5611 intercae @@ -111,19 +111,17 @@ if(spi.write(0x00)!=0xfe) { // can I have the result?; pc.printf("Error reading D2\r\n"); } - register uint8_t d2h=spi.write(0x00); - register uint8_t d2m=spi.write(0x00); - register uint8_t d2l=spi.write(0x00); + *D2=((uint32_t) spi.write(0x00))<<16; + *D2|=((uint32_t) spi.write(0x00))<<8; + *D2|=((uint32_t) spi.write(0x00)); cs.write(1); // and terminate the command - *D1=((uint32_t) d1h<<16)|((uint32_t) d1m<<8)|((uint32_t) d1l); - *D2=((uint32_t) d2h<<16)|((uint32_t) d2m<<8)|((uint32_t) d2l); } void MS5611_phys(uint32_t D1,uint32_t D2, int *PROM, double *T, double *P) { int64_t dt=((int64_t) D2)-(((int64_t) PROM[5])<<8); *T=2000.0+((double) dt*PROM[6])/8388608.0; - int64_t off=(((int64_t) PROM[2])<<16)+((((int64_t) PROM[4])*dt)>>7); - int64_t sens=(((int64_t) PROM[1])<<15)+((((int64_t) PROM[3])*dt)>>8); - *P=(((double) D1)*((double) sens)/2097152.0-((double) off))/32768.0; + int64_t off128=(((int64_t) PROM[2])<<23)+(((int64_t) PROM[4])*dt); + int64_t sens256=(((int64_t) PROM[1])<<23)+(((int64_t) PROM[3])*dt); + *P=(((double) D1)*((double) sens256)/4194304.0-((double) off128))/4194304.0; } \ No newline at end of file