AT90S2313 GNU Compiler UART Question

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hello,


I'm trying to pass information to my terminal by using the UART on a
AT90S213 board.

However, if I send more then 2 bytes, e.g a complete line, only the first
two characters are shown
on the screen. I checked the baudrate and the clockfrequency. I'm using the
poll UART routines.

/* Initialize UART */
void InitUART( unsigned char baudrate )
{
 UBRR = baudrate;                  /* Set the baud rate */
 UCR = ( (1<<RXEN) | (1<<TXEN) );  /* Enable UART receiver and transmitter
*/
}

void TransmitByte( unsigned char data )
{
 while ( !(USR & (1<<UDRE)) ) ;  /* Wait for empty transmit buffer */ <---
After the second byte this will be an INFINITE LOOP
  UDR = data;                                /* Start transmittion */
}

void main( void )
{
 InitUART( 52 );
 for(;;)      /* Forever */
 {
  TransmitByte( 'A' ); TransmitByte( 'B' ); TransmitByte( 'C' ); By C it
hangs in the while loop of ThransmitByte.....
 }
}


Any help is helpfull.


Regards,


Bernard



Re: AT90S2313 GNU Compiler UART Question

Quoted text here. Click to load it
the

I'd rewrite it to use interrupts. See Volker Oth's gcctest program 4.
http://www.mikrocontroller.net/avr-gcc-installation.en.htm

Peter



Re: AT90S2313 GNU Compiler UART Question

Quoted text here. Click to load it

If it does't work polling, then something very fundamental is broken (e.g.
wrong register addresses). Adding interrupts to the problem isn't going to
make things better.

--
Grant Edwards                   grante             Yow!  Where's th' DAFFY
                                  at               DUCK EXHIBIT??
We've slightly trimmed the long signature. Click to see the full one.
Re: AT90S2313 GNU Compiler UART Question

Quoted text here. Click to load it

After the second byte this will be an INFINITE LOOP
Quoted text here. Click to load it

Did you forget to delcare the UART registers as volatile?  That would cause
all sorts of strange behavior.

--
Grant Edwards                   grante             Yow!  Where's th' DAFFY
                                  at               DUCK EXHIBIT??
We've slightly trimmed the long signature. Click to see the full one.
Re: AT90S2313 GNU Compiler UART Question

Quoted text here. Click to load it
the

Another thought... would it help to change this line?
Quoted text here. Click to load it
into
      outb(UDR,data);                                /* Start transmission
*/

Peter



Re: AT90S2313 GNU Compiler UART Question
Hello,


Here is the current code.


I'm using volatile variables

===========================

#define __AVR_AT90S2313__
#include <io.h>

#define UARTCONTROL     0x18
                /* b00011000
                   0- RXCIE interrupt disabled
                   0- TXCIE interrupt disabled
                   0- UDRIE interrupt disabled
                   1- RXEN Receiver enabled
                   1- TXEN Transmitter enabled
                   0- 9 bit characters (for parity) disabled
                   0- Rest (8th bit I/O) ignore */
#define BAUDRATE    51
                /* 8MHz oscillator - 9600 baud


void initUART()
{
    outp(BAUDRATE, UBRR);                
    outp(UARTCONTROL, UCR);                
}

void TransmitByte (volatile unsigned char data)
{
    volatile unsigned char uS;

  {
  uS = inp(USR);
  }
  while (!(uS & 0x40));
  outp(data , UDR);
}



int main()
{
    volatile unsigned char uartStatus;
    volatile unsigned char serialData;
    initUART();

TransmitByte ('b');
TransmitByte ('A');
TransmitByte ('h');
TransmitByte ('o');
TransmitByte ('i');
TransmitByte ('j');
TransmitByte ('d');
TransmitByte ('e');

}

==============
The output is only 'bA' that's all !


Regards,


Bernard



Quoted text here. Click to load it

Re: AT90S2313 GNU Compiler UART Question
...
Quoted text here. Click to load it

It looks that you are using outdated version of GNU toolchain. Use the
latest stable versions, please. At least if you want to get real support
from other users.


#include <avr/io.h>

#define UARTCONTROL _BV(RXEN)|_BV(TXEN)

void initUART()
{
      UBRR = BAUDRATE;
      UCR = UARTCONTROL;    
}

void TransmitByte (unsigned char data)
{
    while (bit_is_clear(USR, UDRE))
        ;
    UDR = data;
}

or

void TransmitByte (unsigned char data)
{
    while (bit_is_clear(USR, TXC))
        ;
    USR |= _BV(TXC);
    UDR = data;
}


Regards,
--
Artur Lipowski

Re: AT90S2313 GNU Compiler UART Question

Quoted text here. Click to load it

Huh?  You read the USR once, then execute an empty while loop????

Quoted text here. Click to load it

--
Grant Edwards                   grante             Yow!  Where's th' DAFFY
                                  at               DUCK EXHIBIT??
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline