Charles Soulen
/
Lab_6_I2C_MCP9808_ALERT
MCP alert
Fork of I2C_MCP9808_V2 by
Revision 1:3baecb064743, committed 2018-11-05
- Comitter:
- csoulen
- Date:
- Mon Nov 05 14:17:14 2018 +0000
- Parent:
- 0:80fb3c4621be
- Commit message:
- To Ben
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Oct 23 19:39:34 2018 +0000 +++ b/main.cpp Mon Nov 05 14:17:14 2018 +0000 @@ -15,8 +15,8 @@ // Note MCP9808 also needs VCC (3.3 V) and GND float TempValue; -float data[20]; -char data_write[3], data_read[2]; +float data[20],data_f[20]; +char data_write[3], data_read[2],data_write_crit_temp[3]; int ii, status; int main() { char text[128]; @@ -32,12 +32,21 @@ // Wake up data_write[0] = MCP9808_REG_CONF; // Register address data_write[1] = 0x00; // Data MSB, b11-15 not used, b9-10 =>T_HYS=0, b8 => continuous conversions - data_write[2] = 0x04; // Data LSB, Alert Off, Alert Disabled, Alert T>T_Crit, Alert active low, Alert interrupt + data_write[2] = 0x1E; // Data LSB, Alert Off, Alert Disabled, Alert T>T_Crit, Alert active low, Alert interrupt status = i2c.write(MCP9808_ADDR, data_write, 3, 0); // address,data,length,repeat // address is chip addess // First byte of data has register address // repeat true for multiple write when the chip autoincrements the address // MCP9808 does not do this, so we leave it at 0 + + // Now we set the critical temperature + data_write_crit_temp[0] = MCP9808_REG_CRIT; + data_write_crit_temp[1] = 0x01; + data_write_crit_temp[2] = 0xB0; + status = i2c.write(MCP9808_ADDR, data_write_crit_temp, 3, 0); + + + while(1){ int i=0; @@ -50,14 +59,15 @@ i2c.read(MCP9808_ADDR, data_read, 2, 0); status = data_read[0] >> 5; // Shift flags to b0-b2 // 1 in flag means: T>T_crit(b2), T>T_Upper(b1), T<T_Lower(b0) - // pc.printf("the status is %n",status); + pc.printf("the status is %X\n\r",status); data_read[0] = data_read[0] & 0x1F; // clear flag bits for temperature data[i] = (data_read[0] * 16) + (data_read[1] / 16.0); // combine two bytes + data_f[i] = (data[i]+40)*9/5-40; // Display the flags, if you wish // pc.printf("Flags are %i \n\r",status); // This displays to the user - pc.printf("%i Temperature is %3.1f\n\r",i,data[i]); + pc.printf("%i Temperature is %3.1f C and %3.1f F\n\r",i,data[i],data_f[i]); i=i+1; wait(1); }