Need Help Following Code Uart Display Temperature Pc Write Start Convert T Command Sensor Q43819714
need help with the following code
UART
Display the temperature on the PC
-
Write the Start Convert T command to the sensor, then writethe Read Temperature command to the sensor
-
Read the 16-bit temperature data
-
Convert the temperature data into real temperature
-
Print the temperature to the PC via UART
/*—————————————————————————-
LAB EXERCISE – I2C interface
SERIAL COMMUNICATION
—————————————-
Access the temperature sensor via I2C interface, printthe current temperature
to the PC via UART
Input: temperature sensor
Output: PC
GOOD LUCK!
*—————————————————————————-*/
#include “mbed.h”
#include “pindef.h”
//I2C interface
I2C temp_sensor(I2C_SDA, I2C_SCL);
Serial pc(UART_TX, UART_RX);
//I2C address of temperature sensor DS1631
const int temp_addr = 0x90;
char cmd[] = {0x51, 0xAA};
char read_temp[2];
/*—————————————————————————-
MAIN function
*—————————————————————————-*/
int main(){
while(1){
/*
Write the Start Convert T commandto the sensor
Write the Read Temperature commandto the sensor
Read the 16-bit temperaturedata
*/
//Write your code here
//Convert temperature toCelsius
float temp = (float((read_temp[0]<< 8) | read_temp[1]) / 256);
//Print temperature to the serialmonitor
//Write your code here
}
}
Expert Answer
Answer to need help with the following code UART Display the temperature on the PC Write the Start Convert T command to the se…
OR