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