avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-chat] Mega32 PORT A and B interaction ?! Driving me nuts !


From: Vincent Trouilliez
Subject: [avr-chat] Mega32 PORT A and B interaction ?! Driving me nuts !
Date: Sat, 21 Feb 2009 20:58:40 +0100

Sorry for the subject line... but it reallly summarizes things very
well ! ;-/ :-(

Problem: I was trying to debug my LCD module that stopped functionning
somehow. It's attached to PORTA (data bus) and PORTB (control lines).

After checking the wiring 200 times and finding nothing wrong
whatsoever with it, I unplugged the LCD, leaving the AVR alone on the
board, with nothing attached to it. I modified my program to do nothing
but toggle the A and B ports high and low to make sure the AVR could
still drive the pins properly, and there starts the nightmare, the
un-understandable:

void main (void)
{
        DDRA = 0b11111111;
        DDRB = 0b00001111;
        while(1)
        {
                PORTB = 0xFF;
                PORTA = 0xFF;
                _delay_us(100);

                PORTB = 0x00;
                PORTA = 0x00;
                _delay_us(100);
        }
}

This makes PORTA toggle every 100us as expected, fine.
However PORTB does something weird: it is high for 100us as planned,
but is low for much longer than this: 5 MILLI seconds !
Even the scope could barely trigger on it...
All interrupts are disabled, and none of the ISR had anything to do
with PORTB anyhow. My test code is really strictly what's shown
above. What's even MORE weird, is that if I comment out any of the two
(any combination) statements that write to PORT A, then oh magic, PORTB
toggles just fine ! The generated assembly in all cases, looks correct.
I just can't make sense of all that, other than the AVR losing it..
which doesn't make sense either does it.

Anyone had any experience that could give me a clue, before I go see a
doctor ? ;-)

--
Vince, completely baffled

000002d6 <main>:
void main (void)
{
uint8_t key;


        DDRA = 0b11111111;
 2d6:   8f ef           ldi     r24, 0xFF       ; 255
 2d8:   8a bb           out     0x1a, r24       ; 26
        DDRB = 0b00001111;
 2da:   8f e0           ldi     r24, 0x0F       ; 15
 2dc:   87 bb           out     0x17, r24       ; 23
        while(1)
        {
                PORTB = 0xFF;
 2de:   4f ef           ldi     r20, 0xFF       ; 255
    milliseconds can be achieved.
 */
void
_delay_loop_2(uint16_t __count)
{
        __asm__ volatile (
 2e0:   28 ec           ldi     r18, 0xC8       ; 200
 2e2:   30 e0           ldi     r19, 0x00       ; 0
 2e4:   48 bb           out     0x18, r20       ; 24
                PORTA = 0xFF;
 2e6:   4b bb           out     0x1b, r20       ; 27
 2e8:   c9 01           movw    r24, r18
 2ea:   01 97           sbiw    r24, 0x01       ; 1
 2ec:   f1 f7           brne    .-4             ; 0x2ea
<main+0x14> _delay_us(100);

                PORTB = 0x00;
 2ee:   18 ba           out     0x18, r1        ; 24
                PORTA = 0x00;
 2f0:   1b ba           out     0x1b, r1        ; 27
 2f2:   c9 01           movw    r24, r18
 2f4:   01 97           sbiw    r24, 0x01       ; 1
 2f6:   f1 f7           brne    .-4             ; 0x2f4
<main+0x1e> 2f8:        f5 cf           rjmp    .-22
        ; 0x2e4 <main+0xe>




reply via email to

[Prev in Thread] Current Thread [Next in Thread]