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.

using usci in port isr

Hi everyone;


my program don't enter PORT1_VECTOR ISR second time. It enter first time,but don't enter secondly unless reset the msp430.

* My project, reading RTC & send through UART using ISR

* I use button on P1.4 for enter ISR

* In ISR, i read second via USCI (SPI) & send via USCI(UART) , after read and send minute, it is easy.

my program

#include <msp430.h>
#include "pcf2123_reg.h"


 unsigned short i;
 unsigned short j;
 unsigned char sec ;
 unsigned char hour ;

void ClockConfig()
{

 BCSCTL1 = CALBC1_8MHZ;
 DCOCTL = CALDCO_8MHZ;
 BCSCTL2= DIVS_3 + DIVM_0;
 BCSCTL3 |= LFXT1S_2;
 //MCLK =DCO
 //SMCLK=DCO/8

}


void PinConfig()
{

P1SEL = BIT1+BIT2+ BIT5 + BIT6 + BIT7;
P1SEL2 = BIT1+BIT2+ BIT5 + BIT6 + BIT7;

P1DIR |= BIT0+BIT3;
P1OUT |= BIT0+BIT3+BIT4;

P1IE |= BIT4;                             // P1.4 interrupt enabled
P1IES |= BIT4;                            // P1.4 Hi/lo edge
P1REN |= BIT4;                            // P1.4 pullup


P1IFG &= ~BIT4;                           // P1.4 IFG cleared

}


void UartConfig(){

    UCA0CTL1 = UCSSEL_2;
    UCA0BR0 = 104;
    UCA0BR1 = 0;
    UCA0MCTL = UCBRS0;
    UCA0CTL1 &= ~UCSWRST;


}

void SpiConfig()
{
//USCI initialization and configuration

UCB0CTL1 = UCSWRST;

UCB0CTL0 |=  UCMST + UCMODE_0 + UCSYNC + UCMSB + UCCKPH ;
UCB0CTL1 |= UCSSEL_2;
//Master,3 pin SPI,Senkron,MSB first,..,..
//Source:SMCLK

UCB0BR0 = 4;
UCB0BR1 = 0;
//Bit Rate

//UCB0MCTL = 0;
//SPI modda modülasyon kullanılmaz


UCB0CTL1 &= ~UCSWRST;
//USCI modül RX ve TX'e hazır
}




int main(void) {
    WDTCTL = WDTPW | WDTHOLD;
    ClockConfig();
    PinConfig();
    SpiConfig();
    UartConfig();


     _BIS_SR(LPM4_bits + GIE);

}



// Port 1 interrupt service routine
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{



   read_rtc(cmd_rd_seconds,&sec);
    UCA0TXBUF = bcd_to_dec(sec) + 80 ;
    while(!(IFG2 & UCA0TXIFG));


  read_rtc(cmd_rd_minutes,&hour);
   UCA0TXBUF = bcd_to_dec(hour) + 80 ;
    while(!(IFG2 & UCA0TXIFG));

    P1OUT ^= 0x01;

    P1IFG &= ~BIT4;
    P1IFG = 0;



}


 

  • Avoid subcalls to functions inside a IRQ.
    You are doing read_rtc() and who knows what that does.

    Avoid using while() inside a IRQ.
    Irq's need to be Short and Sweet™

    How can anything be done then?
    Start up main by doing a clear lpm4 bits on exit.
    if you have many handlers in main, set a flag and let main sort it out.

    I'm doing this and I have 7 different task going at the same time on 2553,
    all multitasking as no task is allowed to use while()

  • Thank you Tony,

    1)While() inside the IRQ vector, is it related my problem?

    2)I will post tomorrow detailed code

    I have 2 USCI(as SPI,UART). Both clock source SMCLK. When occur IRQ, i use these respectively. When exit IRQ;
        P1IFG &= ~BIT4;
        P1IFG = 0;

    I  debug project and IFG really clear then go LPM sleep. But it is anormal?? Next press button it will not generate IRQ.

     

  • The problem solved, but i dont understand still.

    When exit IRQ , pin P1.4(irq sensitive pin) value was '0', i changed it while exit '1' . The codes works.

**Attention** This is a public forum