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.

problem facing interfacing external sensor to msp exp-430f5529

Other Parts Discussed in Thread: MSP430WARE

Dear sir/madam,
I have been facing serious issues to interface external temperature sensor to msp exp-430f5529 kit please verify the code and let me know where is the mistake

#include<msp430x552x.h>
#include "lcd.h"
#include "HAL_Board.h"
#define CALADC12_15V_30C *((unsigned int *)0x1A10) // Temperature Sensor Calibration-30 C
//See device datasheet for TLV table memory mapping
#define CALADC12_15V_85C *((unsigned int *)0x1A12) // Temperature Sensor Calibration-85 C
unsigned int i;
unsigned int conv_val;
volatile float temp_val;
char array[9];

void LCD_INIT(void)
{
Dogs102x6_init();
Dogs102x6_backlightInit();
Dogs102x6_setContrast(15);
Dogs102x6_setBacklight(10);
Dogs102x6_clearScreen();
}
void convert(volatile float x)
{
unsigned int temp;
x=x*100;
temp=x/1000;
array[0]=temp+48;
x=((int)x%1000);
temp=x/100;
array[1]=temp+48;
array[2]='.';
x=((int)x%100);
temp=x/10;
array[3]=temp+48;
x=((int)x%10);
array[3]=x+48;
array[4]='d';
array[5]='e';
array[6]='g';
array[7]='C';
array[8]='\0';
}
int main(void)
{
WDTCTL = WDTPW + WDTHOLD;
Board_init();
LCD_INIT();


P7SEL=0x02; //select P7.1 as analog channel

// P1DIR=BIT1;
// P1OUT=0x00;
ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
ADC12CTL1 = ADC12SHP; // Use sampling timer
ADC12IE = 0x01; // Enable interrupt
ADC12MCTL0|=ADC12INCH_13;
ADC12CTL0 |= ADC12ENC;

// P1DIR |= 0x01; // P1.0 output

while (1)
{
ADC12CTL0 |= ADC12SC; // Start sampling/conversion

__bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit
__no_operation(); // For debugger
}
}


#pragma vector = ADC12_VECTOR
__interrupt void ADC12_ISR(void)

{
switch(__even_in_range(ADC12IV,34))
{
case 0: break; // Vector 0: No interrupt
case 2: break; // Vector 2: ADC overflow
case 4: break; // Vector 4: ADC timing overflow
case 6: // Vector 6: ADC12IFG0
if (ADC12MEM0) //>= 0x7ff) // ADC12MEM = A0 > 0.5AVcc?
{
conv_val=ADC12MEM0;//copy Conversion result into buffer
//temp_val=((float)conv_val*0.61035-713)/2.25;//convert the value into corresponding voltage
temp_val = (float)(((long)conv_val - CALADC12_15V_30C)/(CALADC12_15V_85C - CALADC12_15V_30C)) + 30.0f;
convert(temp_val);

Dogs102x6_stringDraw(2,10,"TEMPERATURE ",DOGS102x6_DRAW_NORMAL);


Dogs102x6_stringDraw(4,10,array,DOGS102x6_DRAW_NORMAL);


__delay_cycles(100000);
__delay_cycles(100000);
_bic_SR_register_on_exit(LPM0_bits);//exit low power mode
}

// P1.0 = 0

__bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
case 8: break; // Vector 8: ADC12IFG1
case 10: break; // Vector 10: ADC12IFG2
case 12: break; // Vector 12: ADC12IFG3
case 14: break; // Vector 14: ADC12IFG4
case 16: break; // Vector 16: ADC12IFG5
case 18: break; // Vector 18: ADC12IFG6
case 20: break; // Vector 20: ADC12IFG7
case 22: break; // Vector 22: ADC12IFG8
case 24: break; // Vector 24: ADC12IFG9
case 26: break; // Vector 26: ADC12IFG10
case 28: break; // Vector 28: ADC12IFG11
case 30: break; // Vector 30: ADC12IFG12
case 32: break; // Vector 32: ADC12IFG13
case 34: break; // Vector 34: ADC12IFG14
default: break;
}
}


for this code i'm getting constant temperature of 30 deg celsius
where should i change the code please mention it out

sensor connections which i did is vcc of sensor to vcc of kit
gnd of sensor to gnd of kit
vout of sensor to port 7.1 of kit

  • Hello Jyothsna

    Moving it to the MSP430 Forum

    Amit
  • Hello sir ,
    I didn't get u sir. Can u explain briefly
  • Amit just told you that he has moved your question to the MSP430 forum because you placed it wrong. Since your problem is MSP430 related, the chance of getting it solved is best in here. I will re-insert your code using the syntax highlighter - please use it directly next time:

    #include<msp430x552x.h>
    #include "lcd.h"
    #include "HAL_Board.h"
    
    #define CALADC12_15V_30C *((unsigned int *)0x1A10) // Temperature Sensor Calibration-30 C
    
    //See device datasheet for TLV table memory mapping
    #define CALADC12_15V_85C *((unsigned int *)0x1A12) // Temperature Sensor Calibration-85 C
    
    unsigned int i;
    unsigned int conv_val;
    volatile float temp_val;
    char array[9];
    
    void LCD_INIT(void)
    {
      Dogs102x6_init();
      Dogs102x6_backlightInit();
      Dogs102x6_setContrast(15);
      Dogs102x6_setBacklight(10);
      Dogs102x6_clearScreen();
    }
    
    void convert(volatile float x)
    {
      unsigned int temp;
      x=x*100;
      temp=x/1000;
      array[0]=temp+48;
      x=((int)x%1000);
      temp=x/100;
      array[1]=temp+48;
      array[2]='.';
      x=((int)x%100);
      temp=x/10;
      array[3]=temp+48;
      x=((int)x%10);
      array[3]=x+48;
      array[4]='d';
      array[5]='e';
      array[6]='g';
      array[7]='C';
      array[8]='\0';
    }
    
    int main(void)
    {
      WDTCTL = WDTPW + WDTHOLD;
      Board_init();
      LCD_INIT();
    
      P7SEL=0x02; //select P7.1 as analog channel
    
      // P1DIR=BIT1;
      // P1OUT=0x00;
      ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
      ADC12CTL1 = ADC12SHP; // Use sampling timer
      ADC12IE = 0x01; // Enable interrupt
      ADC12MCTL0|=ADC12INCH_13;
      ADC12CTL0 |= ADC12ENC;
    
      // P1DIR |= 0x01; // P1.0 output
    
      while (1)
      {
        ADC12CTL0 |= ADC12SC; // Start sampling/conversion
    
        __bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit
        __no_operation(); // For debugger
      }
    }
    
    
    #pragma vector = ADC12_VECTOR
    __interrupt void ADC12_ISR(void)
    {
      switch(__even_in_range(ADC12IV,34))
      {
        case 0: break; // Vector 0: No interrupt
        case 2: break; // Vector 2: ADC overflow
        case 4: break; // Vector 4: ADC timing overflow
        case 6: // Vector 6: ADC12IFG0
    
        if (ADC12MEM0) //>= 0x7ff) // ADC12MEM = A0 > 0.5AVcc?
        {
          conv_val=ADC12MEM0;//copy Conversion result into buffer
          //temp_val=((float)conv_val*0.61035-713)/2.25;//convert the value into corresponding voltage
          temp_val = (float)(((long)conv_val - CALADC12_15V_30C)/(CALADC12_15V_85C - CALADC12_15V_30C)) + 30.0f;
          convert(temp_val);
    
          Dogs102x6_stringDraw(2,10,"TEMPERATURE ",DOGS102x6_DRAW_NORMAL);
          Dogs102x6_stringDraw(4,10,array,DOGS102x6_DRAW_NORMAL);
    
          __delay_cycles(100000);
          __delay_cycles(100000);
          _bic_SR_register_on_exit(LPM0_bits);//exit low power mode
        }
    
        // P1.0 = 0
        __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
    
        case 8: break; // Vector 8: ADC12IFG1
        case 10: break; // Vector 10: ADC12IFG2
        case 12: break; // Vector 12: ADC12IFG3
        case 14: break; // Vector 14: ADC12IFG4
        case 16: break; // Vector 16: ADC12IFG5
        case 18: break; // Vector 18: ADC12IFG6
        case 20: break; // Vector 20: ADC12IFG7
        case 22: break; // Vector 22: ADC12IFG8
        case 24: break; // Vector 24: ADC12IFG9
        case 26: break; // Vector 26: ADC12IFG10
        case 28: break; // Vector 28: ADC12IFG11
        case 30: break; // Vector 30: ADC12IFG12
        case 32: break; // Vector 32: ADC12IFG13
        case 34: break; // Vector 34: ADC12IFG14
        default: break;
      }
    }

  • sir..i'm totally confused by this code
    please can you send me complete code for interfacing external sensor to msp exp430f5529
  • Where do you have that code from?
  • sir,
    I got this code from my seniors the below is the actual code for
    interfacing external sensor .where this code will perform blinking led when temperature sensor is connected .
    and now what i want is ...
    when temp sensor is connected to the ports lcd should display temperature values. so i made the above mentioned changes please help me in code or can you give the code so that i can practice much more programes and try to do some more projects
  • /* --COPYRIGHT--,BSD_EX
    * Copyright (c) 2012, Texas Instruments Incorporated
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *
    * * Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    *
    * * Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in the
    * documentation and/or other materials provided with the distribution.
    *
    * * Neither the name of Texas Instruments Incorporated nor the names of
    * its contributors may be used to endorse or promote products derived
    * from this software without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    *
    *******************************************************************************
    *
    * MSP430 CODE EXAMPLE DISCLAIMER
    *
    * MSP430 code examples are self-contained low-level programs that typically
    * demonstrate a single peripheral function or device feature in a highly
    * concise manner. For this the code may rely on the device's power-on default
    * register values and settings such as the clock configuration and care must
    * be taken when combining code from several examples to avoid potential side
    * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware
    * for an API functional library-approach to peripheral configuration.
    *
    * --/COPYRIGHT--*/
    //******************************************************************************
    // MSP430F552x Demo - ADC12, Sample A0, Set P1.0 if A0 > 0.5*AVcc
    //
    // Description: A single sample is made on A0 with reference to AVcc.
    // Software sets ADC12SC to start sample and conversion - ADC12SC
    // automatically cleared at EOC. ADC12 internal oscillator times sample (16x)
    // and conversion. In Mainloop MSP430 waits in LPM0 to save power until ADC12
    // conversion complete, ADC12_ISR will force exit from LPM0 in Mainloop on
    // reti. If A0 > 0.5*AVcc, P1.0 set, else reset.
    //
    // MSP430F552x
    // -----------------
    // /|\| |
    // | | |
    // --|RST |
    // | |
    // Vin -->|P7.1/A13 P1.0|--> LED
    //
    // Bhargavi Nisarga
    // Texas Instruments Inc.
    // April 2009
    // Built with CCSv4 and IAR Embedded Workbench Version: 4.21
    //******************************************************************************

    #include <msp430.h>

    int main(void)
    {
    WDTCTL = WDTPW + WDTHOLD;


    P7SEL=0x02; //select P7.1 as analog channel

    P1DIR=BIT1;
    P1OUT=0x00;
    ADC12CTL0 = ADC12SHT02 + ADC12ON; // Sampling time, ADC12 on
    ADC12CTL1 = ADC12SHP; // Use sampling timer
    ADC12IE = 0x01; // Enable interrupt
    ADC12MCTL0|=ADC12INCH_13;
    ADC12CTL0 |= ADC12ENC;

    P1DIR |= 0x01; // P1.0 output

    while (1)
    {
    ADC12CTL0 |= ADC12SC; // Start sampling/conversion

    __bis_SR_register(LPM0_bits + GIE); // LPM0, ADC12_ISR will force exit
    __no_operation(); // For debugger
    }
    }


    #pragma vector = ADC12_VECTOR
    __interrupt void ADC12_ISR(void)

    {
    switch(__even_in_range(ADC12IV,34))
    {
    case 0: break; // Vector 0: No interrupt
    case 2: break; // Vector 2: ADC overflow
    case 4: break; // Vector 4: ADC timing overflow
    case 6: // Vector 6: ADC12IFG0
    if (ADC12MEM0 >= 0x7ff) // ADC12MEM = A0 > 0.5AVcc?
    P1OUT |= BIT0; // P1.0 = 1
    else
    P1OUT &= ~BIT0; // P1.0 = 0

    __bic_SR_register_on_exit(LPM0_bits); // Exit active CPU
    case 8: break; // Vector 8: ADC12IFG1
    case 10: break; // Vector 10: ADC12IFG2
    case 12: break; // Vector 12: ADC12IFG3
    case 14: break; // Vector 14: ADC12IFG4
    case 16: break; // Vector 16: ADC12IFG5
    case 18: break; // Vector 18: ADC12IFG6
    case 20: break; // Vector 20: ADC12IFG7
    case 22: break; // Vector 22: ADC12IFG8
    case 24: break; // Vector 24: ADC12IFG9
    case 26: break; // Vector 26: ADC12IFG10
    case 28: break; // Vector 28: ADC12IFG11
    case 30: break; // Vector 30: ADC12IFG12
    case 32: break; // Vector 32: ADC12IFG13
    case 34: break; // Vector 34: ADC12IFG14
    default: break;
    }
    }
  • Have you tried going through the code step by step, having a look at the program flow and the values that are read from the ADC and calculated?
  • yes i went through the code and did the above changes that is .... instead of blinking led i put the lcd to get adc converted value please help me in the code
  • Is your value wrong before outputting it on the LCD or is the result on the LCD wrong?
  • Sir...result on lcd is wrong
  • I am not sure if you have explored this, but it may help in getting your code running...

    http://processors.wiki.ti.com/index.php/Getting_Started_with_the_MSP430_LaunchPad_Workshop

    A very good place to get started or refreshed on getting up to speed on the MSP430, especially if you are working with the F5529 or FR5969!  And the contrasts between the 5xx family, FRAM family and the Value Line family of parts!

    Also, here is an earlier workshop that is not based on driverlib:

    http://processors.wiki.ti.com/index.php/MSP430_5xx_One_Day_Workshop

     

  • Then you have to go into your LCD functions and search for the error. This code isn't shown here. What I would try: Take a fixed value (a constant) and throw it into your function for outputting it on the LCD. Does it show that value? Try this first:

    ...
    convert(23.5); // <- CONSTANT
    Dogs102x6_stringDraw(2,10,"TEMPERATURE ",DOGS102x6_DRAW_NORMAL);
    Dogs102x6_stringDraw(4,10,array,DOGS102x6_DRAW_NORMAL);
    ...

    Does it show 23.5degC?

    Dennis

  • 23 is coming sir
  • Then your problem is somewhere between the ADC and your calculation. Start with the ADC and have a look at the data. Is there any? Does it make sense compared to the voltage applied to the pin measured with a multimeter? If not check your configuration of the ADC. Is there an interrupt request caused by the ADC?

    Btw.: Don't do that floating point calculations in the ISR - set a flag and move it to the main.

    Dennis
  • Sir..if u have that code for interfacing temperature sensor externally please can u provide me
  • Hello...can u provide me the code for connecting temperature sensor externally to mspexp430f5529
  • Jyothsna,

    I'm absolutely willing to help you, no problem at all. But at least for the moment it seems as if you do not want to do anything yourself. And that is not OK. I will definitely not do the work for you.

    You are asking for source code to connect a temperature sensor...you do not even tell something about it. There are tens, maybe hundreds of different sensors. Only from the posted source code, which you don't understand yourself (seems so), it is obvious that you use some kind of resistive sensor because you want to read the voltage with the ADC12. But there are serial ones, too.

    Furthermore you do not tell anything about your hardware setup. And you don't want to go through the steps I have told you. Why not starting at the ADC and compare the value against the voltage at the input pin. Is the ISR invoked? Is the configuration of the ADC wrong?

    You want THE FREE SAMPLE CODE, but this doesn't exist. There isn't a usable-for-all-situations-code. Maybe you are lucky and somebody had exact that setup you use...but this is quite unlikely.

    Sorry, but at least I stop at this point. You aren't willing to invest some time yourself - you just want the ready-to-use solution. But this is not the concept of a forum.

    If you go on trying yourself and have issues with your code I will definitely support you! But I won't do your homework. Maybe you are lucky and anyone else here does. Keep in mind that just copying code from other people without knowing anything about it and then change some things to use it for another project will never ever work. And keep in mind, too, that if this is a homework or a project at the university you probably have to write an exam about that...how if you don't understand anything?

    Please don't feel offended now, but that's how it is.

    Help: EVERYTIME
    Doing your work: NO

    Dennis

**Attention** This is a public forum