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.

CCS/MSP430G2553: interrupt event is interrupting my adc reading

Part Number: MSP430G2553

Tool/software: Code Composer Studio

Hi,

I have a program that combined a keypad (4x4), and an extern ADC.

when i press some key an interrupt is trigger to see which key is pressed, that works well.

when i run the program and not pressing any key the ADC shows what i need.

but when i press any key (meanning trigger the interrupt). the ADC display 0 (wrong value) and stays that way even when the interrupt is ending

how can i make the interrupt not destroy my ADC Reading?

thank you

UPDATE:

I'm adding a lighter code sample that the adc works but when i trigger an interrupt the adc not showing values

here's the main:

#include <msp430.h>
#include "Includes/dcl.h"
#include "Includes/ADC_HX711.h"
#include "Includes/Keypad.h"

/*
 * main.c
 */
void main(void) {
    WDTCTL = WDTPW | WDTHOLD;	// Stop watchdog timer
    DCOCTL = 0; // Select lowest DCOx and MODx settings<
    BCSCTL1 = CALBC1_1MHZ; // Set DCO
    DCOCTL = CALDCO_1MHZ;
    InitADC();
    InitKeypad();

    __bis_SR_register(GIE);

    while(1)
    {
    	wt_zero = (long)bitbang_data_in();
    }

}

#pragma vector=PORT1_VECTOR
__interrupt void port_1(void)
{
	key = ScanKey();
	SetOutputLow();
	ClearFlags();

}

here's the Adc part:

inline void InitADC()
{
	CLOCK_OUT_PORT &= ~CLOCK_OUT_PIN;
	CLOCK_OUT_DIR |= CLOCK_OUT_PIN;
	__delay_cycles(6000);
}

inline void ReenableClock()
{
	CLOCK_OUT_PORT |= CLOCK_OUT_PIN;
	CLOCK_OUT_PORT &= ~CLOCK_OUT_PIN;
}

unsigned char GetByte()
{
	unsigned char data,i;

	for( i = 8; i > 0; i-- )
	{
		CLOCK_OUT_PORT |= CLOCK_OUT_PIN;
		__delay_cycles(1);
		data <<= 1;
		if(IsReady())
			data |= 0x01;
		CLOCK_OUT_PORT &= ~CLOCK_OUT_PIN;

	}

	return data;
}

long  bitbang_data_in()
{
	//unsigned char data[3],i;
	long data;

	while(IsReady());
	__delay_cycles(1);

	data = (long)((long)GetByte() << 16) | ((long)GetByte() << 8) | ((long)GetByte() << 0);
	/*data[2] = GetByte();
	data[1] = GetByte();
	data[0] = GetByte();*/

	//for(i=GAIN;i>0;i--)
		ReenableClock();

	return data;//(long)((long)data[2] << 16) | ((long)data[1] << 8) | ((long)data[0] << 0);
}

inline int IsReady()
{
	return  DATA_IN_PIN & DATA_IN_PORT;
}

and the keypad part:

unsigned char matrix[LEN][LEN] ={'1','2','3','N',
					   '4','5','6','T',
					   '7','8','9','Z',
					   'C','0','F','P'};

inline void InitKeypad()
{
	SetOutputLow();

	DIR_IN_PORT &= ~(PIN_IN_1 + PIN_IN_2 + PIN_IN_3 + PIN_IN_4); //Input Direction p1.3,p1.4,p1.5,p1.7
	P1REN |= (PIN_IN_1 + PIN_IN_2 + PIN_IN_3 + PIN_IN_4);//enable resistor p1.3,p1.4,p1.5,p1.7
	P1OUT |= (PIN_IN_1 + PIN_IN_2 + PIN_IN_3 + PIN_IN_4);// set resistor pull up
	P1IES |= (PIN_IN_1 + PIN_IN_2 + PIN_IN_3 + PIN_IN_4);//high to low
	P1IE |= (PIN_IN_1 + PIN_IN_2 + PIN_IN_3 + PIN_IN_4); //enable interupt


	ClearFlags();
}

unsigned char ScanKey()
{
	unsigned char row_sel=0;
	unsigned char keyrow=0;
	unsigned char i=0;
	unsigned char j=0;

	//DIR_OUT_PORT &= ~(PIN_OUT_5 + PIN_OUT_6 + PIN_OUT_7 + PIN_OUT_8);
	DIR_OUT_PORT = 0;
	for (i = 0 ; i < LEN ; i ++)// each output
	{
		switch(i)
		{
		case 0:
			DIR_OUT_PORT |= PIN_OUT_5; // output p2.0 is high
			break;
		case 1:
			DIR_OUT_PORT |= PIN_OUT_6;// output p2.1 is high
			break;
		case 2:
			DIR_OUT_PORT |= PIN_OUT_7;// output p2.2 is high
			break;
		case 3:
			DIR_OUT_PORT |= PIN_OUT_8;// output p2.3 is high
			break;
		}


		if((IN_PORT & PIN_IN_1) == 0)			// find the pressed button row
			row_sel|=0x08;
		if((IN_PORT & PIN_IN_2) == 0)
			row_sel|=0x04;
		if((IN_PORT & PIN_IN_3) == 0)
			row_sel|=0x02;
		if((IN_PORT & PIN_IN_4) == 0)
			row_sel|=0x01;
		keyrow = BIT3;

		for (j = 0 ; j< LEN ; j++)
		{
			if ((row_sel & keyrow))
			{
				return matrix[i][j];
			}

			keyrow = keyrow >> 1;
		}
		switch(i)
		{
			case 0:
				DIR_OUT_PORT &= ~PIN_OUT_5; // output p2.0 is high
				break;
			case 1:
				DIR_OUT_PORT &= ~PIN_OUT_6;// output p2.1 is high
				break;
			case 2:
				DIR_OUT_PORT &= ~PIN_OUT_7;// output p2.2 is high
				break;
			case 3:
				DIR_OUT_PORT &= ~PIN_OUT_8;// output p2.3 is high
				break;
		}
		row_sel=0;

	}
	 return NONEKEY;
}

inline int IsKeyPressed()
{
	return (P1IFG & IN_PORT);
}

void ClearFlags()
{
	P1IFG = 0;									//Clear Port1 IFG
	P2IFG = 0;
}

void SetOutputLow()
{
	DIR_OUT_PORT |= (PIN_OUT_5 + PIN_OUT_6 + PIN_OUT_7 + PIN_OUT_8); // Output Direction p2.0,p2.1,p2.2,p2.3
	OUT_PORT = 0; // Put output to low
}

dcl.h are just parameters.

thank you

**Attention** This is a public forum