avr-gcc-list
[Top][All Lists]
Advanced

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

[avr-gcc-list] Re: USART - Interrupt - problem -Similar


From: Steve
Subject: [avr-gcc-list] Re: USART - Interrupt - problem -Similar
Date: Sun, 23 May 2004 19:33:11 +0200

Hi,

I have a similar problem to Onno below.

Using a STK500 and the AT90S8515 I have been playing with the UART. I
can get the receive interrupt to fire but not the two transmit related
interrupts. (UART_UDRE and UART_TXC). I should re-phase that, that
UART_UDRE I can definitely see fires during some circumstances but
UART_TXC I can not see any indication of.

Code follows:

#include <io.h>
#include <interrupt.h>
#include <signal.h>

char a;

int     main(void)
{
        long int x,y;
        // set the I/O ports
        // all PORTC pins are outputs
        DDRC=0xff;
        // turn off leds
        PORTC=0xFF;

        UCR     = 0xF8;
        UBRR    = 23;   /*9600*/
        sei();
        
        while(1)
        {
                for(y=0;y<65000;y++)
                        for(x=0;x<20;x++);
                UDR = 'A';
                
        }
}

/*data register empty*/
SIGNAL(SIG_UART_DATA)
{
        //UDR = 'A';
}

/*char has been received*/
SIGNAL(SIG_UART_RECV)
{
        PORTC ^=0x01;
        a = UDR;
}

/*transmit complete*/
SIGNAL(SIG_UART_TRANS)
{
}

Using the code above, a char is outputted every ~2secs and if I enter a
char in Teraterm, the LED connected to PORT C toggles after every press.
But if I move this toggle code into one of the other two interrupts then
I don't see any indication from the LED. I would expect that once a new
char has been added to UDRE and is moved out, that UDRE interrupt would
fire and once the char has been transmitted on the serial line that TXC
would fire. In the code above I don't see this.

If I change the code and uncomment the code (//UDR = 'A';) in
SIG_UART_DATA and block comment the code (for loops and reg loading) in
main, then I can clearly see that SIG_UART_DATA is entered each time
that the previous char has been sent out. But why does it not 'seem' to
enter this interrupt when I use the code in main()? 
With regards to SIG_UART_TRANS I can not verify that this is ever
entered. Any suggestions?

I checked the header as Theodore suggested in the mail earlier and found
the following:
io8515.h
#define SIG_UART_RECV           _VECTOR(9)
#define SIG_UART_DATA           _VECTOR(10)
#define SIG_UART_TRANS          _VECTOR(11)

The datasheet says

UART,RX         vector. 10
UART,UDRIE              vector. 11
UART,TX         vector. 12

So I changed the header to 
io8515.h
#define SIG_UART_RECV           _VECTOR(10)
#define SIG_UART_DATA           _VECTOR(11)
#define SIG_UART_TRANS          _VECTOR(12)

The receive interrupt then didn't seem to fire either.

Thanks v. much in advance.

Steve

-----Original Message-----
From: address@hidden
[mailto:address@hidden On Behalf Of
address@hidden
Sent: Sonntag, 23. Mai 2004 02:00
To: address@hidden
Subject: avr-gcc-list Digest, Vol 16, Issue 18

Send avr-gcc-list mailing list submissions to
        address@hidden

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.avr1.org/mailman/listinfo/avr-gcc-list
or, via email, send a message with subject or body 'help' to
        address@hidden

You can reach the person managing the list at
        address@hidden

When replying, please edit your Subject line so it is more specific
than "Re: Contents of avr-gcc-list digest..."


Today's Topics:

   1. USART - Interrupt - problem (Onno van Eijk)
   2. Re: USART - Interrupt - problem (Theodore A. Roth)


----------------------------------------------------------------------

Date: Sat, 22 May 2004 21:20:42 +0200
From: Onno van Eijk <address@hidden>
To: address@hidden
Subject: [avr-gcc-list] USART - Interrupt - problem
Message-ID: <address@hidden>
Content-Type: text/plain
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Precedence: list
Message: 1

Hi,

Just recently I have started programming micro controllers. I am using
the ATMega32 on an stk500 with avr-gcc (on Debian), and I have run into
trouble I cannot solve.
I just want to use receive data by Interrupt, but I can't get it going.
See the sample code below. While running this code nothing happens. I
have tried different variations but nothing seems to help.
(Disabling the interrupt and enabling the code in the main.while loop
does work; so the serial USART + Connection work fine)

settings
lfuse:  0xca
hfuse:  0x59
lock:   0x3f

Any Idea's?
grz,
Onno

#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>

SIGNAL(SIG_USART_RECV)
{
        while ( !(UCSRA & (1 << RXC) ) );
        PORTC = UDR;
}
 
 int main (void)
{
        cli();  /* Disable all interrupts */
        
        UCSRB = 0x90;           /*RXCIE on, RXEN on */
        UCSRC = 0x86;           /*8bit char, no parity, 1 stop bit */
        UBRRH = 0x00;           /*(Bautrate 19.2 kHz @ fosc=1.8432
Mhz)*/
        UBRRL = 0x05;
        
        DDRC  = 0xFF;           /* All PortC pins are outputs */
        PORTC = 0xFF;
        
        MCUCR = 0x00;   
        
        sei();  /* Enable interrupts */ 
                        
        while (1)
        {
                //while ( !(UCSRA & (1 << RXC) ) );
                //PORTC = UDR;
                
        };
}



------------------------------

Date: Sat, 22 May 2004 14:26:05 -0700 (PDT)
From: "Theodore A. Roth" <address@hidden>
To: Onno van Eijk <address@hidden>
Cc: AVR GCC List <address@hidden>
Subject: Re: [avr-gcc-list] USART - Interrupt - problem
Message-ID: <address@hidden>
In-Reply-To: <address@hidden>
References: <address@hidden>
Content-Type: TEXT/PLAIN; charset=US-ASCII
MIME-Version: 1.0
Precedence: list
Message: 2

On Sat, 22 May 2004, Onno van Eijk wrote:

> Hi,
>
> Just recently I have started programming micro controllers. I am using
> the ATMega32 on an stk500 with avr-gcc (on Debian), and I have run
into
> trouble I cannot solve.
> I just want to use receive data by Interrupt, but I can't get it
going.
> See the sample code below. While running this code nothing happens. I
> have tried different variations but nothing seems to help.
> (Disabling the interrupt and enabling the code in the main.while loop
> does work; so the serial USART + Connection work fine)
>
> settings
> lfuse:        0xca
> hfuse:        0x59
> lock: 0x3f
>
> Any Idea's?
> grz,
> Onno
>
> #include <avr/io.h>
> #include <avr/signal.h>
> #include <avr/interrupt.h>
>
> SIGNAL(SIG_USART_RECV)

The mega32 header defines this:

  #define SIG_UART_RECV           _VECTOR(13)

Fix that and you should get things working.

> {
>       while ( !(UCSRA & (1 << RXC) ) );

I don't think you need this while loop.

---
Ted Roth
PGP Key ID: 0x18F846E9
Jabber ID: address@hidden

------------------------------

_______________________________________________
avr-gcc-list mailing list
address@hidden
http://www.avr1.org/mailman/listinfo/avr-gcc-list


End of avr-gcc-list Digest, Vol 16, Issue 18
********************************************

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.689 / Virus Database: 450 - Release Date: 21.05.2004
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.689 / Virus Database: 450 - Release Date: 21.05.2004
 



reply via email to

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