1 Reply Latest reply on Oct 26, 2017 11:20 PM by ctan94x_intel

    C1000 serial monitor do not show any value or read the sensor?

    Amie_coolman93

      Hi,

       

      Why the code do not read the calculation I used and why the C1000 serial monitor do not show any value or read the sensor?

      Right now the sensor do not give a correct reading value  in Serial monitor:

       

      2.JPG3.JPGerror2.JPGWhatsApp Image 2017-10-23 at 3.34.25 PM.jpeg

      #include "qm_gpio.h" /*Calling QMSI GPIO API. See section 3.1 for more details. */

      #include "clk.h"

      #include "qm_pinmux.h"

      #include "qm_pin_functions.h"

       

       

      #include "stdio.h"

      #include "stdlib.h"

      #include "math.h"

       

       

      #define PIN 22

      #define DHT_PIN_ID (QM_PIN_ID_56)

      #define PIN_MUX_FN (QM_PIN_56_FN_GPIO_22)

      #define DELAY 2500000

       

       

      char message1[] = "Tempt  =  00.0   C";

      char message2[] = " RH   = 00.0     %";

      short Time_out;

      uint8_t T_byte1, T_byte2, RH_byte1, RH_byte2, Checksum;

      uint16_t Temp, RH;

       

       

      //static qm_gpio_state_t state;

       

       

      void start_signal()

      {

      qm_gpio_port_config_t cfg;

       

       

      cfg.direction = 0;       //cnfgre pin as o/p

      qm_gpio_set_config(QM_GPIO_0, &cfg);  //cnfgre pin as o/p

      qm_gpio_clear_pin(QM_GPIO_0, PIN); //pin o/p LOW

      QM_PUTS("O/P LOW");

      clk_sys_udelay(25000); //25ms

       

       

      qm_gpio_set_pin(QM_GPIO_0, PIN); // pin o/p HIGH

      QM_PUTS("O/P HIGH");

      clk_sys_udelay(30000); //30ms

      cfg.direction = BIT(PIN);  //cnfgre pin as i/p

      }

       

       

      signed short check_response()

      {

      clk_sys_udelay(40000); //40ms

      //clk_sys_get_ticks_per_us;

       

       

      if(!PIN)    // Read and test if connection pin is low

      {

      clk_sys_udelay(80); //waiting till sensors starts sending data

      if(PIN)

      {

      clk_sys_udelay(50); //just in case delay

      QM_PUTS("LOW");

      }

      }

      return 1;

      }

       

       

      uint8_t read_data()

      {

      uint8_t i, k, _data = 0; // k is used to count 1 bit reading duration

      if(Time_out)

      for(i=0; i<8; i++)

      {

      k=0;

      while(!PIN)   // Wait until pin goes high

      {

      k++;

      if(k>100) {Time_out = 1; break; }

      clk_sys_udelay(1);

      QM_PRINTF("%d", k);

      }

      clk_sys_udelay(30000);

      if(!PIN)

      qm_gpio_clear_pin(QM_GPIO_0, PIN); //bit_clear(_data, (7 - i)); // Clear bit (7 - i)

       

       

      else

      {

      qm_gpio_set_pin(QM_GPIO_0, PIN); //bit_clear(_data, (7 - i)); // Set bit (7 - i)

      while(PIN)

      {

      k++;

      if (k>100) {Time_out = 1; break;}

      QM_PRINTF("%d", k);

      clk_sys_udelay(1);

      }

      }

      }

      return _data;

      }

       

       

      int main()

      {

      //start_signal();

      //clk_sys_udelay(10000);

      //check_response();

      //clk_sys_udelay(10000);

      //read_data();

      //clk_sys_udelay(10000);

       

       

      clk_sys_udelay(10000);

      Time_out = 0;

      start_signal();

       

       

      if(check_response()) // If there is response from sensor

      {

         RH_byte1 = read_data();        // read RH byte1

         RH_byte2 = read_data();       // read RH byte2

         T_byte1 = read_data();        // read T byte1

         T_byte2 = read_data();        // read T byte2

         Checksum = read_data();      // read checksum

       

       

         if(Time_out) // If reading takes long time

         {

         qm_gpio_clear_pin(QM_GPIO_0, PIN);

         QM_PUTS ("Time out!");

         }

         else

         {

         if(Checksum == ((RH_byte1 + RH_byte2 + T_byte1 + T_byte2) & 0xFF))

         {

         RH = RH_byte1;

         RH = (RH << 8) | RH_byte2;

         Temp = T_byte1;

         Temp = (Temp << 8) | T_byte2;

       

       

         if (Temp > 0X8000)

         message1[6] = '-';

             Temp = Temp & 0X7FFF;

         }

         else

             message1[6] = ' ';

             message1[7]  = (Temp / 100) % 10  + 48;

                 message1[8]  = (Temp / 10) % 10  + 48;

                     message1[10] = Temp % 10  + 48;

                 message2[7]  = (RH / 100) % 10 + 48;

                 message2[8]  = (RH / 10) % 10 + 48;

             message2[10] = RH % 10 + 48;

                 message1[11] = 223;                   // Degree symbol

       

       

                 qm_gpio_clear_pin(QM_GPIO_0, PIN); //CLEAR

                 QM_PRINTF("%d \n", Temp);

                 qm_gpio_clear_pin(QM_GPIO_0, PIN); //CLEAR

                 QM_PRINTF("%d \n", message1[11]);

                 qm_gpio_clear_pin(QM_GPIO_0, PIN); //CLEAR

                 QM_PRINTF("%d \n", message2[10]);

       

       

         }

      }

         else

         {

         qm_gpio_clear_pin(QM_GPIO_0, PIN); //CLEAR

         QM_PUTS ("Checksum error!");

       

       

         qm_gpio_clear_pin(QM_GPIO_0, PIN); //CLEAR

         QM_PUTS ("no response from the sensor!");

         }

       

       

       

       

      return 0;

      }