ATtiny424 Wake up issue

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello

I am facing issue while wake up ATtiny424 from Standby mode. In data sheet mentioned that controller can wake from Standby using Port pin also need to Set the RUNSTDBY and i have set that also.

still facing issue.

 

Configuration which i have done using Atmel start online tool attached

 

Here i am sharing simple code please have look,  please have look and let me know if any have solution of this issue.

ISR(PORTA_PORT_vect)
{
    //printf("Enter In ISR\r\n");
    PORTA.OUT |= PIN7_bm;
    PORTA.OUT |= 0x10;
    PORTA.OUT |= 0x40;
    PORTA.OUT |= 0x08;
	PORTA.INTFLAGS |= PIN5_bm; // set pin as interrupt
    _delay_ms(10000);
    //printf("Exit ISR\r\n");
}

int main(void)
{
	/* Initializes MCU, drivers and middleware */
	atmel_start_init();
    PORTA_set_pin_dir(PIN2_bm, PORT_DIR_OUT);
    PORTA.DIR |= 0x10;
    PORTA.DIR |= 0x40;
    PORTA.DIR |= 0x08;
    _delay_ms(10000);
    //printf("Program Start\r\n");
	while (1) {
        PORTA.OUT &= ~PIN7_bm;
        PORTA.OUT &= ~0x10;
        PORTA.OUT &= ~0x40;
        PORTA.OUT &= ~0x08;
        //printf("Enter In Sleep\r\n");
        //USART_0_write('A');
        sleep_mode();
        _delay_ms(200);
		//printf("\n");
        _delay_ms(1000);
        PORTA.OUT &= ~PIN7_bm;
        PORTA.OUT &= ~0x10;
        PORTA.OUT &= ~0x40;
        PORTA.OUT &= ~0x08;
	}
}


 

Attachment(s): 

This topic has a solution.

Thanks & Regard
Rajendrasinh Chhasatiya

Last Edited: Wed. Jul 6, 2022 - 04:24 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


Get in the habit of reading data sheets first.

You have not set any of the PORTA pins to trigger an interrupt.

Please stop using the wrong "| =".

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Rajendrasinh Chhasatiya wrote:
I am facing issue while wake up ATtiny424 from Standby mode
So far you haven't actually said what that issue is?

Last Edited: Tue. Jul 5, 2022 - 10:13 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I've modified your code as far as I can tell.
I don't know the actual board so I don't know if it works.

 

ISR(PORTA_PORT_vect)
{
    //printf("Enter In ISR\r\n");
    PORTA.OUTSET = PIN7_bm;
    PORTA.OUTSET = 0x10;
    PORTA.OUTSET = 0x40;
    PORTA.OUTSET = 0x08;
    PORTA.INTFLAGS = PIN5_bm; // Clear interrupt flag
    // _delay_ms(10000);    <- Stupid acts
    //printf("Exit ISR\r\n");
}

int main(void)
{
    /* Initializes MCU, drivers and middleware */
    atmel_start_init();
    PORTA_set_pin_dir(PIN2_bm, PORT_DIR_OUT);
    PORTA.DIRSET = 0x10;
    PORTA.DIRSET = 0x40;
    PORTA.DIRSET = 0x08;
    _delay_ms(10000);

    //printf("Program Start\r\n");

    PORTA.PIN5CTRL = PORT_PULLUPEN_bm | PORT_ISC_LEVEL_gc;
    sei();

    while (1) {
        PORTA.OUTCLR = PIN7_bm;
        PORTA.OUTCLR = 0x10;
        PORTA.OUTCLR = 0x40;
        PORTA.OUTCLR = 0x08;
        //printf("Enter In Sleep\r\n");
        //USART_0_write('A');
        sleep_mode();
        _delay_ms(200);
        //printf("\n");
        _delay_ms(1000);
//      PORTA.OUT &= ~PIN7_bm;
//      PORTA.OUT &= ~0x10;
//      PORTA.OUT &= ~0x40;
//      PORTA.OUT &= ~0x08;
    }
}
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

kabasan wrote:

I've modified your code as far as I can tell.
I don't know the actual board so I don't know if it works.

 

ISR(PORTA_PORT_vect)
{
    //printf("Enter In ISR\r\n");
    PORTA.OUTSET = PIN7_bm;
    PORTA.OUTSET = 0x10;
    PORTA.OUTSET = 0x40;
    PORTA.OUTSET = 0x08;
    PORTA.INTFLAGS = PIN5_bm; // Clear interrupt flag
    // _delay_ms(10000);    <- Stupid acts
    //printf("Exit ISR\r\n");
}

int main(void)
{
    /* Initializes MCU, drivers and middleware */
    atmel_start_init();
    PORTA_set_pin_dir(PIN2_bm, PORT_DIR_OUT);
    PORTA.DIRSET = 0x10;
    PORTA.DIRSET = 0x40;
    PORTA.DIRSET = 0x08;
    _delay_ms(10000);

    //printf("Program Start\r\n");

    PORTA.PIN5CTRL = PORT_PULLUPEN_bm | PORT_ISC_LEVEL_gc;
    sei();

    while (1) {
        PORTA.OUTCLR = PIN7_bm;
        PORTA.OUTCLR = 0x10;
        PORTA.OUTCLR = 0x40;
        PORTA.OUTCLR = 0x08;
        //printf("Enter In Sleep\r\n");
        //USART_0_write('A');
        sleep_mode();
        _delay_ms(200);
        //printf("\n");
        _delay_ms(1000);
//      PORTA.OUT &= ~PIN7_bm;
//      PORTA.OUT &= ~0x10;
//      PORTA.OUT &= ~0x40;
//      PORTA.OUT &= ~0x08;
    }
}

Thanks for your valuable time, Now its Working

Thanks & Regard
Rajendrasinh Chhasatiya

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
    PORTA.OUT |= PIN7_bm;
    PORTA.OUT |= 0x10;
    PORTA.OUT |= 0x40;
    PORTA.OUT |= 0x08;

This looks completely ridiculous...why on earth would you write this 4 different times (unless possibly to create some fast waveform)?  Do you expect to make your program 4x longer to look impressive?

Just say PORTA.OUT= what you need.  Maybe just start over, you get better each time.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Rajendrasinh Chhasatiya wrote:

kabasan wrote:

I've modified your code as far as I can tell.
I don't know the actual board so I don't know if it works.

 

ISR(PORTA_PORT_vect)
{
    //printf("Enter In ISR\r\n");
    PORTA.OUTSET = PIN7_bm;
    PORTA.OUTSET = 0x10;
    PORTA.OUTSET = 0x40;
    PORTA.OUTSET = 0x08;
    PORTA.INTFLAGS = PIN5_bm; // Clear interrupt flag
    // _delay_ms(10000);    <- Stupid acts
    //printf("Exit ISR\r\n");
}

int main(void)
{
    /* Initializes MCU, drivers and middleware */
    atmel_start_init();
    PORTA_set_pin_dir(PIN2_bm, PORT_DIR_OUT);
    PORTA.DIRSET = 0x10;
    PORTA.DIRSET = 0x40;
    PORTA.DIRSET = 0x08;
    _delay_ms(10000);

    //printf("Program Start\r\n");

    PORTA.PIN5CTRL = PORT_PULLUPEN_bm | PORT_ISC_LEVEL_gc;
    sei();

    while (1) {
        PORTA.OUTCLR = PIN7_bm;
        PORTA.OUTCLR = 0x10;
        PORTA.OUTCLR = 0x40;
        PORTA.OUTCLR = 0x08;
        //printf("Enter In Sleep\r\n");
        //USART_0_write('A');
        sleep_mode();
        _delay_ms(200);
        //printf("\n");
        _delay_ms(1000);
//      PORTA.OUT &= ~PIN7_bm;
//      PORTA.OUT &= ~0x10;
//      PORTA.OUT &= ~0x40;
//      PORTA.OUT &= ~0x08;
    }
}

Thanks for your valuable time, Now its Working

Hey thanks for your valuable comment, i have write that four time bcz i have measuring current consumption in all three sleep mode.

 

ISR(PORTA_PORT_vect)
{
    //printf("Enter In ISR\r\n");
    PORTA.OUTSET = 0x5C;
    PORTA.INTFLAGS = PIN5_bm; // Clear interrupt flag
}

int main(void)
{
    /* Initializes MCU, drivers and middleware */
    atmel_start_init();
    PORTA.DIRSET = 0x5C;
    sei();

    while (1) {
        PORTA.OUTCLR = 0x5C;
        sleep_mode();
        _delay_ms(200);
    }
}

Above is the final example.

Thanks & Regard
Rajendrasinh Chhasatiya

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

The point being made is that in your original code you had:

    PORTA.OUT |= PIN7_bm;
    PORTA.OUT |= 0x10;
    PORTA.OUT |= 0x40;
    PORTA.OUT |= 0x08;

The question was: why make four writes to the register when you could do it in one:

    PORTA.OUT = PIN7_bm | 0x10 | 0x40 | 0x08;

But if that is your intention (to ensure four bits in PORTA.OUT are set) then I'm afraid that in post #4 when the code was "tidied up" something got lost in translation as the original four lines were changed to:

    PORTA.OUTSET = PIN7_bm;
    PORTA.OUTSET = 0x10;
    PORTA.OUTSET = 0x40;
    PORTA.OUTSET = 0x08;

I know the point was being made to not use "|=" but this has actually changed the action of the code by making them an "=" assignment. Now each line completely REPLACES the action of the previous line. The nett effect is simply:

    PORTA.OUTSET = 0x08;

This is WRONG (assuming the intention was to end with all four bits set)

 

This, however, remains a mystery right from the start:

    PORTA_set_pin_dir(PIN2_bm, PORT_DIR_OUT);
    PORTA.DIRSET = 0x10;
    PORTA.DIRSET = 0x40;
    PORTA.DIRSET = 0x08;

For one thing why is it not consistent? If line 1 of this chose to use an API PORTA_set_pind_dir() then why is that not used again on the next three lines. But as it stands the first three lines are redundant and the nett effect is simply:

    PORTA.DIRSET = 0x08;

Anyway your final solution just uses 0x5C so I guess none of that really matters

 

While I expect most programmers know or can mentally calculate that 0x5C is setting bits 6, 4, 3 and 2 I don't think it would hurt to say that in a comment at least. Or write it in the code:

#define OUTPUTS ((1 << 6) | (1 << 4) | (1 << 3) | (1 << 2)) // 0x5C

ISR(PORTA_PORT_vect)
{
    //printf("Enter In ISR\r\n");
    PORTA.OUTSET = OUTPUTS;
    PORTA.INTFLAGS = PIN5_bm; // Clear interrupt flag
}

int main(void)
{
    /* Initializes MCU, drivers and middleware */
    atmel_start_init();
    PORTA.DIRSET = OUTPUTS;
    sei();

    while (1) {
        PORTA.OUTCLR = OUTPUTS;
        sleep_mode();
        _delay_ms(200);
    }
}