Question: need help with the following code UART Display the temperature on the PC Write the Start Convert T command to the sensor, then write the

need help with the following code

UART

Display the temperature on the PC

  • Write the Start Convert T command to the sensor, then write the 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, print the 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 command to the sensor Write the Read Temperature command to the sensor Read the 16-bit temperature data */ //Write your code here //Convert temperature to Celsius float temp = (float((read_temp[0] << 8) | read_temp[1]) / 256); //Print temperature to the serial monitor //Write your code here } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!