简体   繁体   中英

ATmega4808 32 Pin - Pin PA0 doesn't get set HIGH

I'm using an ATmega4808 32 Pin. I have 2 LEDs connected to the pins PA0 and PA1. I want to set both high. Unfortunatly only the PA1 LED is on.

I figured out the PA0 Pin could be set to EXTCLK by default. If this is the problem i can't find the solution to change the port to GPIO.

int main(int argc, char** argv) {
    PORTA.DIRSET = PIN0_bm; // Config PA0 as output
    PORTA.DIRSET = PIN1_bm; // Config PA1 as output

    PORTA.OUTSET = PIN0_bm; // Set Pin PA0 to HIGH 
    PORTA.OUTSET = PIN1_bm; // Set Pin PA1 to HIGH 

    while(1){
    }


    return (EXIT_SUCCESS);
}

The configuration of PIN0 is lost by writing again to registers PORTA.DIRSET and PORTA.OUTSET .

Try using | (bitwise OR) | (bitwise OR) to not discard PIN0 config:

    PORTA.DIRSET  = PIN0_bm; // Config PA0 as output
    PORTA.DIRSET |= PIN1_bm; // Config PA1 as output

    PORTA.OUTSET  = PIN0_bm; // Set Pin PA0 to HIGH
    PORTA.OUTSET |= PIN1_bm; // Set Pin PA1 to HIGH

Or, to set them at the same time:

    PORTA.DIRSET = PIN0_bm | PIN1_bm; // Config PA0 and PA1 as output

    PORTA.OUTSET = PIN0_bm | PIN1_bm; // Set Pin PA0 and PA1 to HIGH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM