Steven Kay
/
MCP9803_NUCLEO_Driver
Initial I2C Working
Diff: main.cpp
- Revision:
- 1:444546e8cd20
- Parent:
- 0:fbf82bf637bb
- Child:
- 2:832cb4376d2a
diff -r fbf82bf637bb -r 444546e8cd20 main.cpp --- a/main.cpp Wed Mar 29 08:33:10 2017 +0000 +++ b/main.cpp Wed Mar 29 12:20:34 2017 +0000 @@ -21,7 +21,27 @@ data[0] = 0x00; TempSensor.I2C_Write(data,1); - TempSensor.I2C_Read(2); + int len = 2; + char *buffer = TempSensor.I2C_Read(len); + + char inBuffer[len]; + + for(int i = 0; i < len; i++) + { + inBuffer[i] = *(buffer+i); + } + + int dat = (((inBuffer[0] << 8) | inBuffer[1])>>4); + + printf("data value = %04x\r\n",dat); + + if(dat > 2047) + { + dat -= 4096; + } + + float tempC = 0.0625*dat; + printf("Temp C = %f\r\n\r\n",tempC);