Jump to content

Can not config Pin Osc for capacitive sensing

Recommended Posts

Hi everyone,

I am a newbie with capacitive touch, I did a example which I can not config P1.1, P1.2, P1.3 as capacitive sensing function, another pins is ok. The code as below, I just change which PIN, and Port.

/ Middle Element (P2.5)
const struct Element middle_element = {

              .inputPxselRegister = (uint8_t *)&P1SEL,
              .inputPxsel2Register = (uint8_t *)&P1SEL2,
              .inputBits = BIT2,
              // When using an abstracted function to measure the element
              // the 100*(maxResponse - threshold) < 0xFFFF
              // ie maxResponse - threshold < 655
              .maxResponse = 450+655,
              .threshold = 450

//*** CAP TOUCH HANDLER *******************************************************/
// This defines the grouping of sensors, the method to measure change in
// capacitance, and the function of the group

// One Button Sensor
const struct Sensor one_button =
                  .halDefinition = RO_PINOSC_TA0_WDTp,	// Sensing Method
                  .numElements = 1,						// # of Elements
                  .baseOffset = 0,						// First element index = 0
                  // Pointer to elements
                  .arrayPtr[0] = &middle_element,  		// point to middle element
                  // Timer Information
                  .measGateSource= GATE_WDT_ACLK,     //  0->SMCLK, 1-> ACLK
                  .accumulationCycles= WDTp_GATE_64   //64 - Default                                                
void main(void)

  // Initialize System Clocks
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  BCSCTL1 = CALBC1_1MHZ;                // Set DCO to 1, 8, 12 or 16MHz
  BCSCTL2 |= DIVS_2;                    // divide SMCLK by 4 for 250khz
  BCSCTL3 |= LFXT1S_2;                  // LFXT1 = VLO
  P1OUT = 0x00;							// Clear Port 1 bits
  P1DIR |= BIT0;

  P2SEL &= ~(BIT6 + BIT7);				// Configure XIN (P2.6) and XOUT (P2.7) to GPIO
  P2OUT = 0x00;							// Drive all Port 2 pins low
  P2DIR = 0xFF;							// Configure all Port 2 pins outputs

  // Initialize Baseline measurement
  // Update baseline measurement (Average 5 measurements)

  // Main loop starts here
  while (1)

	// Get the raw delta counts for element characterization
	__no_operation(); 					// Set breakpoint here

	// Check if the middle element sensor has been triggered. The API call
	// compares the value from the sensor against the threshold to determine
	// trigger condition
		// Do something
		P1OUT |= BIT0;                            // Turn on center LED
		P1OUT &= ~BIT0;                           // Turn off center LED

    // Put the MSP430 into LPM3 for a certain DELAY period

} // End Main

Please give me an instruction to config them as capacitive sensing.

Thank you!

Link to post
Share on other sites

Maybe not useful, but are you running this on a G2 launchpad?


P1.1,P1.2 are connected to the debugger, removing the serial link should isolate them....


But, P1.3 is connected to a switch, and actually has a pull-up and debounce cap (R34/C24) populated on the PCB. this will mess with the capacitive sense, and drain the parasitic capacitance before it can be measured.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...