Because of the Thanksgiving holiday in the U.S., TI E2E™ design support forum responses may be delayed from November 25 through December 2. Thank you for your patience.

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.

MSP430F5529: Temperature Reading from MSP430f5529

Part Number: MSP430F5529
Other Parts Discussed in Thread: LM35

Hello, got a project to do but I got problems that I can't solve. So briefly I am taking output from lm35dz to msp430f5529 then converting it via ADC and sending those to 3-bit 7 segment display but my segment showing random numbers and do not work intended. Any helps? Thanks. (Code below)

#include <msp430.h>
#define A BIT0
#define B BIT1
#define C1 BIT2
#define D BIT3 // P2.3
#define E BIT4
#define F BIT5
#define G BIT6
#define DP BIT7
#define LM35 BIT0 // analog input P4.0 LM35

#define Digit1 BIT2
#define Digit2 BIT3
#define Digit3 BIT4

void configPins(void);
void configTimer(void);
void configADC(void);
void DisplaySSD(int value, int digit, int showdecimal);

int voltage;
int temp = 0;

void main(void) {
WDTCTL = WDTPW | WDTHOLD; // Disable Watchdog Timer
configTimer();
configADC();
__bis_SR_register(GIE);

P6DIR |= (A + B + C1 + D + E + F + G + DP); // Set P6 pins as output
P1DIR |= (Digit1 + Digit2 + Digit3); // Set P1 pins as output

while (1) {
ADC12CTL0 |= ADC12SC; // Start ADC conversion
while (!(ADC12IFG & BIT0)); // Wait for conversion to complete

voltage = ADC12MEM0; // Read ADC value
voltage = (voltage * 3300) / 1023; // Convert ADC reading to millivolts

// Convert millivolts to degrees Celsius
temp = voltage / 10;

// Display the temperature on the 7-segment display
DisplaySSD(temp % 10, 3, 1); // Display the decimal part
P1OUT |= (Digit3);
__delay_cycles(5000);
P1OUT &= ~(Digit3);

DisplaySSD((temp / 10) % 10, 2, 0); // Display the tens digit
P1OUT |= (Digit2);
__delay_cycles(5000);
P1OUT &= ~(Digit2);

DisplaySSD(temp / 100, 1, 0); // Display the hundreds digit
P1OUT |= (Digit1);
__delay_cycles(5000);
P1OUT &= ~(Digit1);
}
}


void configTimer(void) {
TA0CTL = TASSEL_2 + MC_1; // SMCLK Up mode, /1
TA0CCR0 = 1000000; // 1 MHz SMCLK, 1 Hz sampling rate
TA0CCTL0 |= CCIE; // Enable interrupt for Timer A0
}

void configADC(void) {
P4SEL |= LM35; // Select ADC input pin

ADC12CTL0 = ADC12SHT0_8 + ADC12ON; // Set ADC12ON, ADC12CLKDIV = 0, ADC12SHT0_8
ADC12CTL1 = ADC12SHP+ADC12CONSEQ_1; // Use sampling timer
ADC12MCTL0 = ADC12INCH_0; // ADC input channel
ADC12CTL0 |= ADC12ENC; // Enable conversion
}
void DisplaySSD(int value, int digit, int showdecimal) {
P6OUT = 0; // Clear all segments

switch(value) {
case 0:
P6OUT |= A + B + C1 + D + E + F;
break;
case 1:
P6OUT |= B + C1;
break;
case 2:
P6OUT |= A + B + G + E + D;
break;
case 3:
P6OUT |= A + B + C1 + D + G;
break;
case 4:
P6OUT |= B + C1 + F + G;
break;
case 5:
P6OUT |= A + C1 + D + F + G;
break;
case 6:
P6OUT |= A + C1 + D + E + F + G;
break;
case 7:
P6OUT |= A + B + C1;
break;
case 8:
P6OUT |= A + B + C1 + D + E + F + G;
break;
case 9:
P6OUT |= A + B + C1 + D + F + G;
break;
default:
break;
}

if (showdecimal && digit == 3) {
P6OUT |= DP; // Turn on decimal point
}
}

#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A(void) {
voltage = ADC12MEM0; // Read ADC value
__bic_SR_register_on_exit(CPUOFF); // Exit LPM0
}

**Attention** This is a public forum