Sunday, March 3, 2019

Ikea Ansluta Hacking - timer and key interrupts

That...was easy.

1) setup interrupt for P1 on P_KEY (the switch) pin

P2IFG = 0; // clear flags register
P2IE = P_KEY; // enable
P2IES = P_KEY; // edge


2) setup timer A0 to use SMCLK/8 and count up, start it

CCTL0 = CCIE; // CCR0 interrupt enabled
TACTL = TASSEL_2 + ID_3 + MC_1; // TASSEL_2 --> SMCLK (~1MHz), MC_1--> up, ID_3 --> SMCLK/8
CCR0 = 50000; // (SMCLK/8)/50000 = 2.5 Hz


3) enter a low power mode with wake on interrupt

_BIS_SR(CPUOFF + GIE);


4) in timer A0 - toggle the LED pin

#pragma vector = TIMERA0_VECTOR
__interrupt void Timer_A(void)
{
   P1OUT ^= P_LED; // toggle LED for now
}

5) in Port 1 interrupt - toggle the max count of timer A0 between 'slow' and 'fast' blinking.

#pragma vector = PORT2_VECTO
__interrupt void Port_2(void)
{
   // TODO - there is no debouncing of the switch
   if( P2IFG & P_KEY )
   {
      CCR0 = CCR0 > 10000 ? 10000 : 50000; // toggle between two blink speeds
   }
   P2IFG = 0; // clear all flags
}


Next: debounce the key, talk to CC2500.

No comments: