This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430G2553 & SHT75 question?

Other Parts Discussed in Thread: MSP430G2553

Hello!

I'm new to msp430 and currently have a project on humidity sensor. I'm using the MSP-EXP430G2 launchpad for testing the sht75 sensor.

I have a look in the sample code which is provided here:

http://www.sensirion.com/en/products/humidity-temperature/download-center/

I made some modifications to the code in order to run it on msp430g2553 (compiler IAR). However, it seems that I can't read anything from the sensor (I read the information by printing to the Terminal I/O). I have also checked the connections, pull-up resistor and removed the jumper on P1.0 and P1.6 which are used for the

SCK and DATA line. Can anyone take a look at my code here:

/* 
 *  Humidity Sensor Code
 */

#include <msp430g2553.h> 
#include <intrinsics.h> // (is used for __no_ operation())   
#include <math.h>    
#include <stdio.h>   

typedef union  
{ unsigned int i; 
  float f; 
} value;
 
//----------------------------------------------
// modul-var 
//----------------------------------------------
enum {TEMP,HUMI}; 
#define SCK     P1OUT  //Clock for sensor (port 1.0)
#define DATAIN  P1IN   //Data receives from sensor (port 1.6)   
#define DATAOUT P1OUT  //Write Data to sensor 
#define DATAON() {P1DIR |= BIT6;} //Data writable
#define DATAOFF() {P1DIR &= ~BIT6;} //Data readale

#define noACK 0 
#define ACK   1 
                            //adr  command  r/w 
#define STATUS_REG_W 0x06   //000   0011    0 
#define STATUS_REG_R 0x07   //000   0011    1 
#define MEASURE_TEMP 0x03   //000   0001    1 
#define MEASURE_HUMI 0x05   //000   0010    1 
#define RESET        0x1e   //000   1111    0 
 
//---------------------------------------------------------------------------------- 
char s_write_byte(unsigned char value) 
//---------------------------------------------------------------------------------- 
// writes a byte on the Sensibus and checks the acknowledge  
{  
  unsigned char i,error=0;   
  for (i=0x80;i>0;i/=2)               //shift bit for masking 
  { if (i & value)
      DATAOFF();          //masking value with i , write to SENSI-BUS 
    if (i & value == 0) 
    {
      DATAON();
      DATAOUT &= ~BIT6;
    }
    __no_operation();                        //observe setup time 
    SCK |= BIT0;                          //clk for SENSI-BUS 
    __delay_cycles(3);        //pulswith approx. 5 us    
    SCK &= ~BIT0; 
    __no_operation();                         //observe hold time 
  }
  DATAOFF();                        //release DATA-line         
  __no_operation();                          //observe setup time 
  SCK |= BIT0 ;                            //clk #9 for ack
  if(DATAIN&BIT6)  
    error = 1;                         //check ack (DATA will be pulled down by SHT11)
  SCK &= ~BIT0;         
  return error;                     //error=1 in case of no acknowledge 
}

//---------------------------------------------------------------------------------- 
char s_read_byte(unsigned char ack) 
//---------------------------------------------------------------------------------- 
// reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"  
{  
  unsigned char i,val=0;
  DATAOFF();                  //release DATA-line
  for (i=0x80;i>0;i/=2)             //shift bit for masking 
  { SCK |= BIT0;                          //clk for SENSI-BUS 
    if (DATAIN&BIT6) val=(val | i);        //read bit   
    SCK &= ~BIT0;              
  }
  DATAON();
  if(ack == 1)
    DATAOUT &= ~BIT6;                        //in case of "ack==1" pull down DATA-Line 
  else
    DATAOFF();
  __no_operation();                          //observe setup time 
  SCK |= BIT0;                            //clk #9 for ack 
  __delay_cycles(3);          //pulsewidth approx. 5 us  
  SCK &= ~BIT0; 
  __no_operation();                          //observe hold time
  DATAOFF();                           //release DATA-line 
  return val; 
}
 
//------------------------------------------------------------------
void s_transstart(void) 
//------------------------------------------------------------------
// generates a transmission start  
//       _____         ________ 
// DATA:      |_______| 
//           ___     ___ 
// SCK : ___|   |___|   |______ 
{  
   DATAOFF();
   SCK &= ~BIT0;                   //Initial state
   __no_operation();
   SCK |= BIT0;
   __no_operation();
   DATAON();
   DATAOUT &= ~BIT6;
   __no_operation();
   SCK &= ~BIT0;
   __delay_cycles(3);
   SCK |= BIT0;
   __no_operation();
   DATAOFF();
   __no_operation();
   SCK &= ~BIT0;
}

//---------------------------------------------------------------------------------- 
void s_connectionreset(void) 
//---------------------------------------------------------------------------------- 
// communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart 
//       _____________________________________________________         ________ 
// DATA:                                                      |_______| 
//          _    _    _    _    _    _    _    _    _        ___     ___ 
// SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______|   |___|   |______ 
{   
  unsigned char i;
  DATAOFF();  
  SCK &= ~BIT0;                    //Initial state 
  for(i=0;i<9;i++)                  //9 SCK cycles 
  { SCK |= BIT0; 
    SCK &= ~BIT0; 
  } 
  s_transstart();                   //transmission start 
} 
 
//---------------------------------------------------------------------------------- 
char s_softreset(void) 
//---------------------------------------------------------------------------------- 
// resets the sensor by a softreset  
{  
  unsigned char error=0;   
  s_connectionreset();              //reset communication 
  error+=s_write_byte(RESET);       //send RESET-command to sensor 
  return error;                     //error=1 in case of no response form the sensor 
} 

 
//---------------------------------------------------------------------------------- 
char s_read_statusreg(unsigned char *p_value, unsigned char *p_checksum) 
//---------------------------------------------------------------------------------- 
// reads the status register with checksum (8-bit) 
{  
  unsigned char error=0; 
  s_transstart();                   //transmission start 
  error=s_write_byte(STATUS_REG_R); //send command to sensor 
  *p_value=s_read_byte(ACK);        //read status register (8-bit) 
  *p_checksum=s_read_byte(noACK);   //read checksum (8-bit)   
  return error;                     //error=1 in case of no response form the sensor 
} 

 
//---------------------------------------------------------------------------------- 
char s_write_statusreg(unsigned char *p_value) 
//---------------------------------------------------------------------------------- 
// writes the status register with checksum (8-bit) 
{  
  unsigned char error=0; 
  s_transstart();                   //transmission start 
  error+=s_write_byte(STATUS_REG_W);//send command to sensor 
  error+=s_write_byte(*p_value);    //send value of status register 
  return error;                    //error>=1 in case of no response form the sensor 
} 

//---------------------------------------------------------------------------------- 
char s_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char 
mode) 
//---------------------------------------------------------------------------------- 
// makes a measurement (humidity/temperature) with checksum 
{  
  unsigned char error=0; 
  unsigned long int i; 
 
  s_transstart();                   //transmission start 
  switch(mode){                     //send command to sensor 
    case TEMP  : error+=s_write_byte(MEASURE_TEMP); break; 
    case HUMI  : error+=s_write_byte(MEASURE_HUMI); break; 
    default     : break;    
  }
  for (i=0;i<1800000;i++) if(DATAIN&BIT6==0) break; //wait until sensor has finished the measurement 
  if(DATAIN&BIT6) error+=1;                // or timeout (~2 sec.) is reached 
  *(p_value)  =s_read_byte(ACK);    //read the first byte (MSB) 
  *(p_value+1)=s_read_byte(ACK);    //read the second byte (LSB) 
  *p_checksum =s_read_byte(noACK);  //read checksum 
  return error; 
}

 
//---------------------------------------------------------------------------------- 
void calc_sth11(float *p_humidity ,float *p_temperature) 
//---------------------------------------------------------------------------------- 
// calculates temperature [�C] and humidity [%RH]  
// input :  humi [Ticks] (12 bit)  
//          temp [Ticks] (14 bit) 
// output:  humi [%RH] 
//          temp [�C] 
{ const float C1=-2.0468;           // for 12 Bit RH 
  const float C2=+0.0367;           // for 12 Bit RH 
  const float C3=-0.0000015955;     // for 12 Bit RH 
  const float T1=+0.01;             // for 12 Bit RH 
  const float T2=+0.00008;          // for 12 Bit RH   
 
  float rh=*p_humidity;             // rh:      Humidity [Ticks] 12 Bit  
  float t=*p_temperature;           // t:       Temperature [Ticks] 14 Bit 
  float rh_lin;                     // rh_lin:  Humidity linear 
  float rh_true;                    // rh_true: Temperature compensated humidity 
  float t_C;                        // t_C   :  Temperature [�C] 
 
  t_C=t*0.01 - 40.1;              //calc. temperature[�C]from 14 bit temp.ticks @5V 
  rh_lin=C3*rh*rh + C2*rh + C1;     //calc. humidity from ticks to [%RH] 
  rh_true=(t_C-25)*(T1+T2*rh)+rh_lin;   //calc. temperature compensated humidity [%RH] 
  if(rh_true>100)rh_true=100;       //cut if the value is outside of 
  if(rh_true<0.1)rh_true=0.1;       //the physical possible range 
 
  *p_temperature=t_C;               //return temperature [�C] 
  *p_humidity=rh_true;              //return humidity[%RH] 
} 

 
//-------------------------------------------------------------------- 
float calc_dewpoint(float h,float t) 
//-------------------------------------------------------------------- 
// calculates dew point 
// input:   humidity [%RH], temperature [�C] 
// output:  dew point [�C] 
{ float k,dew_point ; 
   
  k = (log10(h)-2)/0.4343 + (17.62*t)/(243.12+t); 
  dew_point = 243.12*k/(17.62-k); 
  return dew_point; 
}

void main(void) {
  
  WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
  P1DIR |= BIT0;
  BCSCTL1 = CALBC1_1MHZ;
  DCOCTL = CALDCO_1MHZ;
  value humi_val,temp_val; 
  float dew_point; 
  unsigned char error,checksum; 
  unsigned long int i; 
  s_connectionreset(); 
  while(1) 
  { error=0; 
    error+=s_measure((unsigned char*) &humi_val.i,&checksum,HUMI);  //measure humidity 
    error+=s_measure((unsigned char*) &temp_val.i,&checksum,TEMP);  //measure temperature 
    if(error!=0) s_connectionreset();        //in case of an error: connection reset 
    else 
    { humi_val.f=(float)humi_val.i;                   //converts integer to float 
      temp_val.f=(float)temp_val.i;                   //converts integer to float 
      calc_sth11(&humi_val.f,&temp_val.f);            //calculate humidity, temperature 
      dew_point=calc_dewpoint(humi_val.f,temp_val.f); //calculate dew point 
      printf("temp:%5.1fC humi:%5.1f%% dewpoint:%5.1fC\n",temp_val.f,humi_val.f,dew_point); 
    } 
//----------wait approx. 0.8s to avoid heating up SHTxx----------------------------- 
   for (i=0;i<900000;i++); //(be sure that the compiler doesn't eliminate this line!) 
//---------------------------------------------------------------------------------- 
  } 
	}// main

and see if it's ok? Any help would be greatly appreciated.

  • Can anyone help me please?

  • Use the lot of #define ... ... can make a program more readable. But readable can also hide mistakes and make mistakes more difficult to detect.

    I think you confused yourself. I simply cannot follow your code. I stopped reading after the lines:

     .
        if (i & value == 0)
        {
          DATAON();
          DATAOUT &= ~BIT6;
        }

    Are you trying to send a pulse to pulse BIT6 of P1OUT? Are those lines meant to be:


        if (i & value == 0)
        {
          P1OUT |= BIT6;
          P1OUT &= ~BIT6;
        }

    I did not and do not want to read beyond that point.

  • Sorry for that inconvenience, I've checked again and replaced the defines to original command

    /* 
     *  Humidity Sensor Code
     */
    
    #include <msp430g2553.h> 
    #include <intrinsics.h> // (is used for __no_ operation())   
    #include <math.h>    
    #include <stdio.h>   
    
    typedef union  
    { unsigned int i; 
      float f; 
    } value;
     
    //----------------------------------------------
    // modul-var 
    //----------------------------------------------
    enum {TEMP,HUMI}; 
    #define SCK     P1OUT  //Clock for sensor (port 1.0)
    #define DATAIN  P1IN   //Data receives from sensor (port 1.6)   
    #define DATAOUT P1OUT  //Write Data to sensor 
    #define DATAON() {P1DIR |= BIT6;} //Data writable
    #define DATAOFF() {P1DIR &= ~BIT6;} //Data readale
    
    #define noACK 0 
    #define ACK   1 
                                //adr  command  r/w 
    #define STATUS_REG_W 0x06   //000   0011    0 
    #define STATUS_REG_R 0x07   //000   0011    1 
    #define MEASURE_TEMP 0x03   //000   0001    1 
    #define MEASURE_HUMI 0x05   //000   0010    1 
    #define RESET        0x1e   //000   1111    0 
     
    //---------------------------------------------------------------------------------- 
    char s_write_byte(unsigned char value) 
    //---------------------------------------------------------------------------------- 
    // writes a byte on the Sensibus and checks the acknowledge  
    {  
      unsigned char i,error=0;   
      for (i=0x80;i>0;i/=2)               //shift bit for masking 
      { if (i & value)
          P1DIR &= ~BIT6;          //masking value with i , write to SENSI-BUS 
        if (i & value == 0) 
        {
          P1DIR |= BIT6;
          P1OUT &= ~BIT6;
        }
        __no_operation();                        //observe setup time 
        P1OUT |= BIT0;                          //clk for SENSI-BUS 
        __delay_cycles(3);        //pulswith approx. 5 us    
        P1OUT &= ~BIT0; 
        __no_operation();                         //observe hold time 
      }
      P1DIR &= ~BIT6;                        //release DATA-line         
      __no_operation();                          //observe setup time 
      P1OUT |= BIT0 ;                            //clk #9 for ack
      if(P1IN&BIT6)  
        error = 1;                         //check ack (DATA will be pulled down by SHT11)
      P1OUT &= ~BIT0;         
      return error;                     //error=1 in case of no acknowledge 
    }
    
    //---------------------------------------------------------------------------------- 
    char s_read_byte(unsigned char ack) 
    //---------------------------------------------------------------------------------- 
    // reads a byte form the Sensibus and gives an acknowledge in case of "ack=1"  
    {  
      unsigned char i,val=0;
      P1DIR &= ~BIT6;                  //release DATA-line
      for (i=0x80;i>0;i/=2)             //shift bit for masking 
      { P1OUT |= BIT0;                          //clk for SENSI-BUS 
        if (P1IN&BIT6) val=(val | i);        //read bit   
        P1OUT &= ~BIT0;              
      }
      P1DIR |= BIT6;
      if(ack == 1)
        P1OUT &= ~BIT6;                        //in case of "ack==1" pull down DATA-Line 
      else
        P1DIR &= ~BIT6;
      __no_operation();                          //observe setup time 
      P1OUT |= BIT0;                            //clk #9 for ack 
      __delay_cycles(3);          //pulsewidth approx. 5 us  
      P1OUT &= ~BIT0; 
      __no_operation();                          //observe hold time
      P1DIR &= ~BIT6;                           //release DATA-line 
      return val; 
    }
     
    //------------------------------------------------------------------
    void s_transstart(void) 
    //------------------------------------------------------------------
    // generates a transmission start  
    //       _____         ________ 
    // DATA:      |_______| 
    //           ___     ___ 
    // SCK : ___|   |___|   |______ 
    {  
       P1DIR &= ~BIT6;
       P1OUT &= ~BIT0;                   //Initial state
       __no_operation();
       P1OUT |= BIT0;
       __no_operation();
       P1DIR |= BIT6;
       P1OUT &= ~BIT6;
       __no_operation();
       P1OUT &= ~BIT0;
       __delay_cycles(3);
       P1OUT |= BIT0;
       __no_operation();
       P1DIR &= ~BIT6;
       __no_operation();
       P1OUT &= ~BIT0;
    }
    
    //---------------------------------------------------------------------------------- 
    void s_connectionreset(void) 
    //---------------------------------------------------------------------------------- 
    // communication reset: DATA-line=1 and at least 9 SCK cycles followed by transstart 
    //       _____________________________________________________         ________ 
    // DATA:                                                      |_______| 
    //          _    _    _    _    _    _    _    _    _        ___     ___ 
    // SCK : __| |__| |__| |__| |__| |__| |__| |__| |__| |______|   |___|   |______ 
    {   
      unsigned char i;
      P1DIR &= ~BIT6;  
      P1OUT &= ~BIT0;                    //Initial state 
      for(i=0;i<9;i++)                  //9 SCK cycles 
      { P1OUT |= BIT0; 
        P1OUT &= ~BIT0; 
      } 
      s_transstart();                   //transmission start 
    } 
     
    //---------------------------------------------------------------------------------- 
    char s_softreset(void) 
    //---------------------------------------------------------------------------------- 
    // resets the sensor by a softreset  
    {  
      unsigned char error=0;   
      s_connectionreset();              //reset communication 
      error+=s_write_byte(RESET);       //send RESET-command to sensor 
      return error;                     //error=1 in case of no response form the sensor 
    } 
    
     
    //---------------------------------------------------------------------------------- 
    char s_read_statusreg(unsigned char *p_value, unsigned char *p_checksum) 
    //---------------------------------------------------------------------------------- 
    // reads the status register with checksum (8-bit) 
    {  
      unsigned char error=0; 
      s_transstart();                   //transmission start 
      error=s_write_byte(STATUS_REG_R); //send command to sensor 
      *p_value=s_read_byte(ACK);        //read status register (8-bit) 
      *p_checksum=s_read_byte(noACK);   //read checksum (8-bit)   
      return error;                     //error=1 in case of no response form the sensor 
    } 
    
     
    //---------------------------------------------------------------------------------- 
    char s_write_statusreg(unsigned char *p_value) 
    //---------------------------------------------------------------------------------- 
    // writes the status register with checksum (8-bit) 
    {  
      unsigned char error=0; 
      s_transstart();                   //transmission start 
      error+=s_write_byte(STATUS_REG_W);//send command to sensor 
      error+=s_write_byte(*p_value);    //send value of status register 
      return error;                    //error>=1 in case of no response form the sensor 
    } 
    
    //---------------------------------------------------------------------------------- 
    char s_measure(unsigned char *p_value, unsigned char *p_checksum, unsigned char 
    mode) 
    //---------------------------------------------------------------------------------- 
    // makes a measurement (humidity/temperature) with checksum 
    {  
      unsigned char error=0; 
      unsigned long int i; 
     
      s_transstart();                   //transmission start 
      switch(mode){                     //send command to sensor 
        case TEMP  : error+=s_write_byte(MEASURE_TEMP); break; 
        case HUMI  : error+=s_write_byte(MEASURE_HUMI); break; 
        default     : break;    
      }
      for (i=0;i<1800000;i++) if(P1IN&BIT6==0) break; //wait until sensor has finished the measurement 
      if(P1IN&BIT6) error+=1;                // or timeout (~2 sec.) is reached 
      *(p_value)  =s_read_byte(ACK);    //read the first byte (MSB) 
      *(p_value+1)=s_read_byte(ACK);    //read the second byte (LSB) 
      *p_checksum =s_read_byte(noACK);  //read checksum 
      return error; 
    }
    
     
    //---------------------------------------------------------------------------------- 
    void calc_sth11(float *p_humidity ,float *p_temperature) 
    //---------------------------------------------------------------------------------- 
    // calculates temperature [�C] and humidity [%RH]  
    // input :  humi [Ticks] (12 bit)  
    //          temp [Ticks] (14 bit) 
    // output:  humi [%RH] 
    //          temp [�C] 
    { const float C1=-2.0468;           // for 12 Bit RH 
      const float C2=+0.0367;           // for 12 Bit RH 
      const float C3=-0.0000015955;     // for 12 Bit RH 
      const float T1=+0.01;             // for 12 Bit RH 
      const float T2=+0.00008;          // for 12 Bit RH   
     
      float rh=*p_humidity;             // rh:      Humidity [Ticks] 12 Bit  
      float t=*p_temperature;           // t:       Temperature [Ticks] 14 Bit 
      float rh_lin;                     // rh_lin:  Humidity linear 
      float rh_true;                    // rh_true: Temperature compensated humidity 
      float t_C;                        // t_C   :  Temperature [�C] 
     
      t_C=t*0.01 - 40.1;              //calc. temperature[�C]from 14 bit temp.ticks @5V 
      rh_lin=C3*rh*rh + C2*rh + C1;     //calc. humidity from ticks to [%RH] 
      rh_true=(t_C-25)*(T1+T2*rh)+rh_lin;   //calc. temperature compensated humidity [%RH] 
      if(rh_true>100)rh_true=100;       //cut if the value is outside of 
      if(rh_true<0.1)rh_true=0.1;       //the physical possible range 
     
      *p_temperature=t_C;               //return temperature [�C] 
      *p_humidity=rh_true;              //return humidity[%RH] 
    } 
    
     
    //-------------------------------------------------------------------- 
    float calc_dewpoint(float h,float t) 
    //-------------------------------------------------------------------- 
    // calculates dew point 
    // input:   humidity [%RH], temperature [�C] 
    // output:  dew point [�C] 
    { float k,dew_point ; 
       
      k = (log10(h)-2)/0.4343 + (17.62*t)/(243.12+t); 
      dew_point = 243.12*k/(17.62-k); 
      return dew_point; 
    }
    
    void main(void) {
      
      WDTCTL = WDTPW + WDTHOLD;                 // Stop watchdog timer
      P1DIR |= BIT0;
      BCSCTL1 = CALBC1_1MHZ;
      DCOCTL = CALDCO_1MHZ;
      value humi_val,temp_val; 
      float dew_point; 
      unsigned char error,checksum; 
      unsigned long int i; 
      s_connectionreset(); 
      while(1) 
      { error=0; 
        error+=s_measure((unsigned char*) &humi_val.i,&checksum,HUMI);  //measure humidity 
        error+=s_measure((unsigned char*) &temp_val.i,&checksum,TEMP);  //measure temperature 
        if(error!=0) s_connectionreset();        //in case of an error: connection reset 
        else 
        { humi_val.f=(float)humi_val.i;                   //converts integer to float 
          temp_val.f=(float)temp_val.i;                   //converts integer to float 
          calc_sth11(&humi_val.f,&temp_val.f);            //calculate humidity, temperature 
          dew_point=calc_dewpoint(humi_val.f,temp_val.f); //calculate dew point 
          printf("temp:%5.1fC humi:%5.1f%% dewpoint:%5.1fC\n",temp_val.f,humi_val.f,dew_point); 
        } 
    //----------wait approx. 0.8s to avoid heating up SHTxx----------------------------- 
       for (i=0;i<900000;i++); //(be sure that the compiler doesn't eliminate this line!) 
    //---------------------------------------------------------------------------------- 
      } 
    	}// main
    
    
    (e.g. DATAON() to P1DIR |= BIT6). Still no result. My code is just a modified

    version of the sample code here: which is provide by Sensirion. I only changed the clock and data line to the pins which I want on the msp430, nothing more.

  • Duc_Nguyen_90 said:

     I only changed the clock and data line to the pins which I want on the msp430, nothing more.

    Well, no, you (apparently) also added that code that OCY pointed out. Due to the missing parentheses, it results in every byte being sent as either 0xFE or 0xFF, which as near as I can tell is never correct. (There's a similar mistake in s_measure().)

  • Sorry, but I still don't get the point. The code that old_cow_yellow pointed out:

    if (i & value)
          P1DIR &= ~BIT6;       

    if (i & value == 0)
        {
          P1DIR |= BIT6;
          P1OUT &= ~BIT6;
        }

    I think it just a translation of this part of the sample code:

    if (i&value)  DATA = 1;

    else DATA = 0;

    The same case with s_measure() function:

      for (i=0;i<1800000;i++) if(P1IN&BIT6==0) break;
      if(P1IN&BIT6) error+=1;        

     is similar to the sample code:

    for (i=0;i<65535;i++) if(DATA==0) break;

    if(DATA) error+=1;

    Could you kindly show me where are the mistakes?

    Best regards,

    Duc

     

        

  • Duc,

    I think you already realized the differences between the 8051 port pins and the msp430 port pins; and have tried to use the later to emulate the former. However, the details of your attempts are incorrect.

    In addition, your ultimate goal should be using msp430 to read data from SHT75, not using msp430 to emulate 8051.

    Here are my suggestions:

    (1) At power up, SHT75 expects both SCK and DATA to be driven high by the uC. msp430 port pins power up as high impedance input pins. Thus you need to initialize them with:

       P1OUT |= BIT0 | BIT6;

       P1DIR |= BIT0 | BIT6;

    (2) SHT75 needs at least 11msec before it is ready to accept commands from uC. msp430 starts to work much faster. Thus after the above, you need to delay >11msec before you do anything else to those port pins. Something as simple as this will do:

       __delay_cycles(11000); // delay 11msec at 1MHz

    (3) SCK is unidirectional. Thus to drive it, simply do:

       P1OUT |= BIT0; // to drive SCK high

          or

       P1OUT &= ~BIT0; // to drive SCK low

    (4) DATA is bidirectional. The initial set up is output mode. To drive DATA in output mode, do:

       P1OUT |= BIT6; // to drive DATA high

          or

       P1OUT &= ~BIT6; // to drive DATA low

    (5) To change DATA from output mode to input mode, do:

       P1DIR &= ~BIT6;

    (6) To read DATA in input mode, use the expression:

       (P1IN & BIT6)

    (5) To change DATA from input mode to output mode, do:

       P1DIR |= ~BIT6;

     Hope this helps.

    -- OCY

     

      

     

     

     

     

  • Thank for quick response OCY, just 1 more question I would like to ask if you don't mind:

    In the datasheet of SHT75 there is a pull-up resistor connected between the DATA and Vdd line, so I think if I want to drive DATA high I just simply set DATA at input mode

    P1DIR &= ~BIT6;

    Is it right?

    Best regards,

    Duc

  • Yes, that may work too. But I do not think it is very good way. Pulling up with a resister, the rise time is slower than driving it up. And when you need to drive it low, you are wasting power.

  • old_cow_yellow said:

    Yes, that may work too. But I do not think it is very good way. Pulling up with a resister, the rise time is slower than driving it up. And when you need to drive it low, you are wasting power.

    Due respect, I disagree with this. As near as I can tell "Sensi-Bus" is an I2C variant where the master is expected to drive SCL (but not SDA) all the time. Thus the SDA pullup is important, and standard practice would keep P1OUT.[SDA]=0 all the time, and wiggle P1DIR.[SDA] instead (imitation open-drain).

    If the SHT75 is expecting the pullup to be there, it won't drive SDA high (ever). Thus, e.g. ACK [slave drives SDA=0] will be OK, but NACK [slave floats SDA] will be indeterminate.

    If rise time is a problem, one can use a stronger pullup. My guess is that communication speed is not a big concern for most applications of this device.

  • Thank OCY and Bruce for all your help!

**Attention** This is a public forum