avr-chat
[Top][All Lists]
Advanced

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

[avr-chat] Mega644 bit test problem


From: Robert von Knobloch
Subject: [avr-chat] Mega644 bit test problem
Date: Fri, 08 May 2009 11:41:04 +0200
User-agent: Thunderbird 1.5.0.14 (X11/20060911)

Hallo,

I am writing code for an ATMega 644P and have come across some very
strange behaviour.
A small part of the code is required to read an asynchronous serial
signal (data & clock - low speed) over PORTB pins.
The relevant code snippet is:

snip
#define CLOCK_TIMEOUT    2000
#define ASYNCPIN    PORTB
#define ASYNCCLK    0
#define ASYNCDATA    3

    for (i = 0 ; i < 16 ; ++i)
    {
        while ((ASYNCPIN & _BV(ASYNCCLK)) != 0)        // Wait for clock low
        {
        if (mSecdowncnt == 0)
        {
            noclock = 1;
            break;                    // Timeout
        }
        }

        result = result >> 1;
        if ((ASYNCPIN & _BV(ASYNCDATA)) != 0)
        {
        result |= 0x8000;
        }

        while ((ASYNCPIN & _BV(ASYNCCLK)) != 1)        // Wait for clock
high
        {
        if (mSecdowncnt == 0)
        {
            noclock = 1;
            break;                    // Timeout
        }
        }
        if (noclock == 1)
        {
        break;
        }
    }
/snip

This works fine. I want, however to use portb bits 1 & 3 for clock &
data. I simply change to #define ASYNCCLK    1
and re-compile
Now, nothing works and the code generated is much smaller (0xe5 bytes
instead of 0x193 bytes for the working variant).

I am using OPTIMIZE       = -O1 -fno-inline in my Makefile

Does anyone know why simply changing a bit-mask should have such a
serious effect ?

Best regards,

Robert von Knobloch





reply via email to

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