Re: [avr-gcc-list] Small program for UART not working

2005-09-12 Thread Vincent Trouilliez
> >Send 0xAA continiously. That way you get a nice
> >square wave at the baud rate frequency. If you drop
> 
> I thought it was 0x55 (or ASCII 'U') that you wanted, rather than 0xAA.
> 
> An idle RS-232 line is in the "Mark" state.  Start bit is "Mark" to "Space" 
> transition.  Data bits are then sent LSB first, with "Mark" == 1, "Space" == 
> 0, so the LSB has to be a '1'.  After the last databit (bit 7 is zero, or 
> "Space"), the stop bit puts the line back into idle ("Mark") for 1 bit time.
> 
> This should work for 8N1.
> 
> Regards,
>-=Dave

Indeed, when I started playing with my AVR's UART a few days ago and
sent an 0xAA, the frame looked weird on the scope, at first I thought I
got the frame format wrong, 5 data bit instead of 8 or something ! ;-)
0x55 would probably have looked much better indeed...


--
Vince



___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Small program for UART not working

2005-09-12 Thread Dave Hansen

From: "Anton Erasmus" <[EMAIL PROTECTED]>
[...]

> I tried to calculate the baud rate on scope, I found I
> can't get a exactly number, I can only get an
> estimate. Do you know if there's way to set the baud
> rate accurately?

Send 0xAA continiously. That way you get a nice
square wave at the baud rate frequency. If you drop


I thought it was 0x55 (or ASCII 'U') that you wanted, rather than 0xAA.

An idle RS-232 line is in the "Mark" state.  Start bit is "Mark" to "Space" 
transition.  Data bits are then sent LSB first, with "Mark" == 1, "Space" == 
0, so the LSB has to be a '1'.  After the last databit (bit 7 is zero, or 
"Space"), the stop bit puts the line back into idle ("Mark") for 1 bit time.


This should work for 8N1.

Regards,
  -=Dave




___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Small program for UART not working

2005-09-12 Thread Anton Erasmus


On 29 Aug 2005 at 17:24, Gary Bi wrote:

> Hi David and Ian,
> 
> Thanks for the help. I checked the fuses for mega101
> mode, it did set to ON. I uncheck it in AVR studio and
> program it, but this did not make improvement to the
> issue.
> 
> I shorted the PIN2 and PIN3 at the end of cable (the
> end plugs to PC RS232), I still can see the data was
> received through the loopback, demonstrated through
> LEDs on STK board. The RS232 cable is good, since I
> short the other end, I can see the chars typed
> displayed on the termial.
> 
> I'm suspecting the baud rate was not set accurately in
> Atmega128L, so cause the reception of PC side is not
> synchronized. For example, if I set to 115200, but not
> accurate, the number could be set as 115000, so I have
> some errors in PC terminal.
> 
> I tried to calculate the baud rate on scope, I found I
> can't get a exactly number, I can only get an
> estimate. Do you know if there's way to set the baud
> rate accurately?

Send 0xAA continiously. That way you get a nice
square wave at the baud rate frequency. If you drop
your baud rate to something like 9600, then you 
do not need such an accurate baud rate to get good results.
If it works at this low baud rate, but not at the higher baud rate,
then you know it is baud rate issues.

Regards
  Anton Erasmus


> Thanks,
> Gary
> 
> 
> 
> 
> --- David Brown <[EMAIL PROTECTED]> wrote:
> 
> > Hi,
> > 
> > Since you can see the data on your scope, and
> > loopback works fine when
> > shorting RX and TX pins, there seems to be nothing
> > wrong with the
> > microcontroller.  The things I would now check are
> > the baud rate (using the
> > scope), the RS-232 line drivers, the TX-RX
> > orientation (I've fixed many
> > communications problems by swapping the TX and RX
> > lines !), the cable
> > between the board and the PC (including the ground
> > line), and the PC serial
> > port.  It can be worth shorting the TX and RX pins
> > at the board end of the
> > cable and testing loop-back from the PC side using
> > TTP.
> > 
> > mvh.,
> > 
> > David
> > 
> > 
> > 
> > > Hi David,
> > >
> > > Thanks for the info. I downloaded Tera Term Pro
> > and
> > > installed it in my PC, it's a defenitely a better
> > > terminal simulation. Unfortunately I got the same
> > > result.
> > >
> > > My problem are:
> > >
> > > 1. Atmel128L has successfully sent out characters
> > in
> > > TX, but I can not receive it correctly in PC
> > termimal.
> > > When monitoring the TX pin in scope, I can see
> > char
> > > 'B' has been sent out continuouly.
> > > /* UART Transmit Complete Interrupt Function */
> > > SIGNAL(SIG_UART0_TRANS){
> > > outp('B',UDR0);
> > > }
> > > When I short TX and RX pin together in Atmel STK
> > > board, I can see the 'B' was displayed correctly
> > > (demonstrated using LEDs, PIN7-0 is for Bit7-0).
> > > /* UART Receive Complete Interrupt Function */
> > > SIGNAL(SIG_UART0_RECV){
> > > RxChar = inp(UDR0);
> > > outp(RxChar, PORTB);
> > > }
> > > What I receivd in TTP teminal is 0xA2 instead of
> > > character 'B' (0x42).
> > >
> > > 2. I did not set baud rate in the codes for Atmel,
> > in
> > > TTP, I will need to set the baud rate to 57600,
> > 8-N-1
> > > to get the RX working, so if I type 'C', I can see
> > the
> > > LEDs is demonstrated 'C' correctly. If the set the
> > > baud rate to 9600, 115200, etc. I can not get the
> > Rx
> > > working. This is very strange.
> > > So I have to comment out the two lines for baud:
> > > //outp(0x0, UBRR0H);
> > > //outp( (u08)UART_BAUD_SELECT, UBRR0L);
> > >
> > > The MCU is running at 7.3728Mhz, I set the baud
> > > parameter to 0x2F according to the datasheet.
> > > #define UART_BAUD_SELECT 0x2F //9600 baud
> > >
> > > There's typo in my previous email, what I want to
> > say
> > > is: I can see the character 'B' is sending out, I
> > just
> > > did not receive it correctly in PC.
> > >
> > > 3. Do you think it's possible it's related to a
> > defect
> > > MCU (ATMEGA128L)? I'm trying to buy a new
> > MCU(order
> > > ATMEGA128-16AI (16Mhz), but not sure if it will
> > work
> > > with 7.3728MHz crystal on STK or not.
> > >
> > > Thanks,
> > > Gary
> > >
> > >
> >
> ==
> > > #include 
> > > #include 
> > > #include 
> > > #include 
> > >
> > > #define outp(a,b) b=a
> > > #define inp(a) a
> > > typedef unsigned char  u08;
> > > typedef unsigned short u16;
> > > #define UART_BAUD_SELECT 0x2F //9600 baud
> > >
> > > #define PRG_RDB( addr )   __LPM((unsigned
> > > short)(addr))
> > > #define BV(bit) (1 << (bit))
> > >
> > > /* UART global variables */
> > >
> > > volatile u08   RxChar;
> > > volatile int i = 0;
> > >
> > > /* UART Transmit Complete Interrupt Function */
> > > SIGNAL(SIG_UART0_TRANS)
> > > {
> > >  outp(0x43,UDR0);
> > > }
> > >
> > >
> > > /* UART Receive Complete Interrupt Function */
> > > SIGNAL(SIG_UART0_RECV)
> > > {
> > > RxChar = inp(UDR0);
> > > outp(RxChar, PORTB);
> > > }
> > >
> > > voi

Re: [avr-gcc-list] Small program for UART not working

2005-09-05 Thread Gary Bi
Hi Joerg,

Thanks for quickly pointing that out. Yes, I'm using
WinAVR, it's not urgent for my project. I will wait 
several weeks later to check it again.

Thanks again,
Gary


--- Joerg Wunsch <[EMAIL PROTECTED]> wrote:

> 
> Gary Bi <[EMAIL PROTECTED]> wrote:
> 
> > Another quick question: does anyone know which
> version
> > of avr-gcc can support C code compiling for
> > ATmega165/Atmega325, I have next version:
> 
> Currently only with patches.  ATmega165 support is
> in binutils-2.16
> natively, but everything else (both MCU types for
> GCC, ATmega325 for
> binutils) require external patches by now.
> 
> Are you using WinAVR?  The next version (which Eric
> keeps promising to
> release really soon now :-) will certainly support
> both.  If you're
> eager to roll your own compiler and binutils, I can
> send you a patch
> URL.  Please note that you'd need an unreleased
> version of avr-libc
> for ATmega325 support (release to happen anytime
> soon).
> 
> -- 
> cheers, J"org   .-.-.   --... ...--  
> -.. .  DL8DTL
> 
> http://www.sax.de/~joerg/   
> NIC: JW11-RIPE
> Never trust an operating system you don't have
> sources for. ;-)
> 
> 
> ___
> AVR-GCC-list mailing list
> AVR-GCC-list@nongnu.org
>
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
> 



___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Small program for UART not working

2005-09-05 Thread Joerg Wunsch

Gary Bi <[EMAIL PROTECTED]> wrote:

> Another quick question: does anyone know which version
> of avr-gcc can support C code compiling for
> ATmega165/Atmega325, I have next version:

Currently only with patches.  ATmega165 support is in binutils-2.16
natively, but everything else (both MCU types for GCC, ATmega325 for
binutils) require external patches by now.

Are you using WinAVR?  The next version (which Eric keeps promising to
release really soon now :-) will certainly support both.  If you're
eager to roll your own compiler and binutils, I can send you a patch
URL.  Please note that you'd need an unreleased version of avr-libc
for ATmega325 support (release to happen anytime soon).

-- 
cheers, J"org   .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Small program for UART not working

2005-09-05 Thread Gary Bi
All,

Thanks a lot for all your advices. I finially have
this worked. Two things are done:

1. The baud rate calculation should be based on
3.686Mhz (default fosc for STK500).
2. Fuse change, I select next option 
Ext. Clock Start-up time:6CK + 0ms [CKSEL= SUT=00]

Another quick question: does anyone know which version
of avr-gcc can support C code compiling for
ATmega165/Atmega325, I have next version:

gcc -v
Using built-in specs.
Configured with: ../gcc-3.4.3/configure
--prefix=m:/WinAVR --build=mingw32 --hos
t=mingw32 --target=avr --enable-languages=c,c++
--with-dwarf2
Thread model: single
gcc version 3.4.3

It did not work with this error: MCU `atmega165'
supported for assembler only.

Thanks,
Gary


--- Peter Fuhrmann <[EMAIL PROTECTED]> wrote:

> On Tuesday 30 August 2005 02:37, Gary Bi wrote:
> > From the scope, I can calculate the baud rate
> rough
> > number, for example, if setting it to 9600 in MCU,
> on
> > scope, it was around that range; setting to 57600,
> the
> > reading from scope will be around 57600, etc. But
> I
> > don't know the exacly reading.
> 
> You might try sending 0xAA on the Atmel and 0xAA on
> the PC at the same time, 
> and then use a two channel scope to compare the
> timing of the two waveforms.
> 
> You could try playing with the UBRR0L value a little
> to get the timing 
> correct.
> 
> regards,
> 
> Peter
> 
> 
> ___
> AVR-GCC-list mailing list
> AVR-GCC-list@nongnu.org
>
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list
> 



___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Small program for UART not working

2005-09-01 Thread Peter Fuhrmann
On Tuesday 30 August 2005 02:37, Gary Bi wrote:
> From the scope, I can calculate the baud rate rough
> number, for example, if setting it to 9600 in MCU, on
> scope, it was around that range; setting to 57600, the
> reading from scope will be around 57600, etc. But I
> don't know the exacly reading.

You might try sending 0xAA on the Atmel and 0xAA on the PC at the same time, 
and then use a two channel scope to compare the timing of the two waveforms.

You could try playing with the UBRR0L value a little to get the timing 
correct.

regards,

Peter


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Small program for UART not working

2005-08-30 Thread Parthasaradhi Nayani
Hello,

Some questions, which may lead to solving the problem.

1. Are ysing external crystal? if yes, did you set bit
to external crystal. If you aare using internal 4M
clock, then please refer the doc on possible baud
rates and their errors. If internal clock is used I
suggest you use lower baud rate (less than 115200) and
which has the least error.

2. One way to check if received data is correct or
not, switch ON some specific LEDs for a particular
byte received. example switch ON LED1 if received byte
is A, switch on LED2 if received byte is B etc. Since
you are shorting the TX and RX lines and if the
controller transmits A continously and if the same is
received or not can be verified. I hope this will
atleast give you some pointer to the actual problem.

Regards
Nayani




--- Gary Bi <[EMAIL PROTECTED]> wrote:

> Hi David and Ian,
> 
> Thanks for the help. I checked the fuses for mega101
> mode, it did set to ON. I uncheck it in AVR studio
> and
> program it, but this did not make improvement to the
> issue.
> 
> I shorted the PIN2 and PIN3 at the end of cable (the
> end plugs to PC RS232), I still can see the data was
> received through the loopback, demonstrated through
> LEDs on STK board. The RS232 cable is good, since I
> short the other end, I can see the chars typed
> displayed on the termial.
> 
> I'm suspecting the baud rate was not set accurately
> in
> Atmega128L, so cause the reception of PC side is not
> synchronized. For example, if I set to 115200, but
> not
> accurate, the number could be set as 115000, so I
> have
> some errors in PC terminal.
> 
> I tried to calculate the baud rate on scope, I found
> I
> can't get a exactly number, I can only get an
> estimate. Do you know if there's way to set the baud
> rate accurately?
> 
> Thanks,
> Gary
> 
> 
> 
> 
> --- David Brown <[EMAIL PROTECTED]> wrote:
> 
> > Hi,
> > 
> > Since you can see the data on your scope, and
> > loopback works fine when
> > shorting RX and TX pins, there seems to be nothing
> > wrong with the
> > microcontroller.  The things I would now check are
> > the baud rate (using the
> > scope), the RS-232 line drivers, the TX-RX
> > orientation (I've fixed many
> > communications problems by swapping the TX and RX
> > lines !), the cable
> > between the board and the PC (including the ground
> > line), and the PC serial
> > port.  It can be worth shorting the TX and RX pins
> > at the board end of the
> > cable and testing loop-back from the PC side using
> > TTP.
> > 
> > mvh.,
> > 
> > David
> > 
> > 
> > 
> > > Hi David,
> > >
> > > Thanks for the info. I downloaded Tera Term Pro
> > and
> > > installed it in my PC, it's a defenitely a
> better
> > > terminal simulation. Unfortunately I got the
> same
> > > result.
> > >
> > > My problem are:
> > >
> > > 1. Atmel128L has successfully sent out
> characters
> > in
> > > TX, but I can not receive it correctly in PC
> > termimal.
> > > When monitoring the TX pin in scope, I can see
> > char
> > > 'B' has been sent out continuouly.
> > > /* UART Transmit Complete Interrupt Function */
> > > SIGNAL(SIG_UART0_TRANS){
> > > outp('B',UDR0);
> > > }
> > > When I short TX and RX pin together in Atmel STK
> > > board, I can see the 'B' was displayed correctly
> > > (demonstrated using LEDs, PIN7-0 is for Bit7-0).
> > > /* UART Receive Complete Interrupt Function */
> > > SIGNAL(SIG_UART0_RECV){
> > > RxChar = inp(UDR0);
> > > outp(RxChar, PORTB);
> > > }
> > > What I receivd in TTP teminal is 0xA2 instead of
> > > character 'B' (0x42).
> > >
> > > 2. I did not set baud rate in the codes for
> Atmel,
> > in
> > > TTP, I will need to set the baud rate to 57600,
> > 8-N-1
> > > to get the RX working, so if I type 'C', I can
> see
> > the
> > > LEDs is demonstrated 'C' correctly. If the set
> the
> > > baud rate to 9600, 115200, etc. I can not get
> the
> > Rx
> > > working. This is very strange.
> > > So I have to comment out the two lines for baud:
> > > //outp(0x0, UBRR0H);
> > > //outp( (u08)UART_BAUD_SELECT, UBRR0L);
> > >
> > > The MCU is running at 7.3728Mhz, I set the baud
> > > parameter to 0x2F according to the datasheet.
> > > #define UART_BAUD_SELECT 0x2F //9600 baud
> > >
> > > There's typo in my previous email, what I want
> to
> > say
> > > is: I can see the character 'B' is sending out,
> I
> > just
> > > did not receive it correctly in PC.
> > >
> > > 3. Do you think it's possible it's related to a
> > defect
> > > MCU (ATMEGA128L)? I'm trying to buy a new
> > MCU(order
> > > ATMEGA128-16AI (16Mhz), but not sure if it will
> > work
> > > with 7.3728MHz crystal on STK or not.
> > >
> > > Thanks,
> > > Gary
> > >
> > >
> >
>
==
> > > #include 
> > > #include 
> > > #include 
> > > #include 
> > >
> > > #define outp(a,b) b=a
> > > #define inp(a) a
> > > typedef unsigned char  u08;
> > > typedef unsigned short u16;
> > > #define UART_BAUD_SELECT 0x2F //9600 baud
> > >
> > > #define PRG_RDB( addr )   __LPM((u

Re: [avr-gcc-list] Small program for UART not working

2005-08-29 Thread Bjarne Laursen



My trouble is that the TX is not working, I can see
some garbage character is keeping displayed in the
Hyper terminal Window, but when I turn off the STK
board, I noticed in the bottom, there are some 'B'
characters displayed. My intention is to display one
'A' character and followed many 'B's (display 'B'
forever).



If you are keep sending the same charater all the time, and you doen't 
get the start right (Power on spurius), you can not be sure that 
receiver gets syncronised correct. It might see on of the databits as a 
startbit.

Try to put a delay in start of your code. Or in between characters.
Sending a 0xFF will allso bring the receiver in sync, because no 
databits can be confused with startbits.


-Bjarne Laursen, RoseTechnology, DK




___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Small program for UART not working

2005-08-29 Thread Vincent Trouilliez

> LEDs on STK board. The RS232 cable is good, 
> 
> I'm suspecting the baud rate was not set accurately in
> Atmega128L, so cause the reception of PC side is not
> synchronized. For example, if I set to 115200, but not
> accurate, the number could be set as 115000, so I have
> some errors in PC terminal.


The PC might be set accurately spot on to 115,200 but no uC will ever be
spot on anyway I think, depending on clock period etc, you can only get
as close as possible using the available counters, but rarely spot on.
IIRC the RS-232 allows for at least 1% tolerance/difference in bit
time/speed between the receiver and sender. You only need to be in sync
enough to transmit 10 bits, before syncing with the next start bit, so
in theory, even with 9.9% difference (in case of 10 bits frames) you
could still get your data, well okay that's stretching a bit far but you
get the idea ! ;o)
115,200 vs 115,000 shouldn't be a problem as it's under 0.2% difference.

So if the frames are formed properly, if the speeds are satisfyingly (is
that a word?!) matched, and the cable is good. Well have you checked on
your scope that, on the Atmel side, the Tx line driver was producing the
correct voltage levels ? Maybe it's a bit "weak" and the receiver of the
PC a bit critical ? 

Not sure that's much help, but since your problem seems to persist, some
food for thoughts can't hurt ;-)


Regards,


--
Vince



___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Small program for UART not working

2005-08-29 Thread Jonathan Goldberg

Gary Bi wrote:


From the scope, I can calculate the baud rate rough

number, for example, if setting it to 9600 in MCU, on
scope, it was around that range; setting to 57600, the
reading from scope will be around 57600, etc. But I
don't know the exacly reading, since there's no way to
read it, I can only Icalculate it though the measure of
waveform frequency. I also noticed the start bit
(1bit) and stop bit (bit) is correctly set in the
waveform.

Thanks,
Gary


--- Gary Bi <[EMAIL PROTECTED]> wrote:
 

If measuring baud rate with an o'scope, you can transmit a 0xAA 
character and measure the time delta between a rising edge and the next 
falling edge.  This should give you the bit time.  Taking the inverse of 
the bit time will give you an accurate baud rate.


Jonathan


___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Small program for UART not working

2005-08-29 Thread Gary Bi
Hi David and Ian,

Thanks for the help. I checked the fuses for mega101
mode, it did set to ON. I uncheck it in AVR studio and
program it, but this did not make improvement to the
issue.

I shorted the PIN2 and PIN3 at the end of cable (the
end plugs to PC RS232), I still can see the data was
received through the loopback, demonstrated through
LEDs on STK board. The RS232 cable is good, since I
short the other end, I can see the chars typed
displayed on the termial.

I'm suspecting the baud rate was not set accurately in
Atmega128L, so cause the reception of PC side is not
synchronized. For example, if I set to 115200, but not
accurate, the number could be set as 115000, so I have
some errors in PC terminal.

I tried to calculate the baud rate on scope, I found I
can't get a exactly number, I can only get an
estimate. Do you know if there's way to set the baud
rate accurately?

Thanks,
Gary




--- David Brown <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> Since you can see the data on your scope, and
> loopback works fine when
> shorting RX and TX pins, there seems to be nothing
> wrong with the
> microcontroller.  The things I would now check are
> the baud rate (using the
> scope), the RS-232 line drivers, the TX-RX
> orientation (I've fixed many
> communications problems by swapping the TX and RX
> lines !), the cable
> between the board and the PC (including the ground
> line), and the PC serial
> port.  It can be worth shorting the TX and RX pins
> at the board end of the
> cable and testing loop-back from the PC side using
> TTP.
> 
> mvh.,
> 
> David
> 
> 
> 
> > Hi David,
> >
> > Thanks for the info. I downloaded Tera Term Pro
> and
> > installed it in my PC, it's a defenitely a better
> > terminal simulation. Unfortunately I got the same
> > result.
> >
> > My problem are:
> >
> > 1. Atmel128L has successfully sent out characters
> in
> > TX, but I can not receive it correctly in PC
> termimal.
> > When monitoring the TX pin in scope, I can see
> char
> > 'B' has been sent out continuouly.
> > /* UART Transmit Complete Interrupt Function */
> > SIGNAL(SIG_UART0_TRANS){
> > outp('B',UDR0);
> > }
> > When I short TX and RX pin together in Atmel STK
> > board, I can see the 'B' was displayed correctly
> > (demonstrated using LEDs, PIN7-0 is for Bit7-0).
> > /* UART Receive Complete Interrupt Function */
> > SIGNAL(SIG_UART0_RECV){
> > RxChar = inp(UDR0);
> > outp(RxChar, PORTB);
> > }
> > What I receivd in TTP teminal is 0xA2 instead of
> > character 'B' (0x42).
> >
> > 2. I did not set baud rate in the codes for Atmel,
> in
> > TTP, I will need to set the baud rate to 57600,
> 8-N-1
> > to get the RX working, so if I type 'C', I can see
> the
> > LEDs is demonstrated 'C' correctly. If the set the
> > baud rate to 9600, 115200, etc. I can not get the
> Rx
> > working. This is very strange.
> > So I have to comment out the two lines for baud:
> > //outp(0x0, UBRR0H);
> > //outp( (u08)UART_BAUD_SELECT, UBRR0L);
> >
> > The MCU is running at 7.3728Mhz, I set the baud
> > parameter to 0x2F according to the datasheet.
> > #define UART_BAUD_SELECT 0x2F //9600 baud
> >
> > There's typo in my previous email, what I want to
> say
> > is: I can see the character 'B' is sending out, I
> just
> > did not receive it correctly in PC.
> >
> > 3. Do you think it's possible it's related to a
> defect
> > MCU (ATMEGA128L)? I'm trying to buy a new
> MCU(order
> > ATMEGA128-16AI (16Mhz), but not sure if it will
> work
> > with 7.3728MHz crystal on STK or not.
> >
> > Thanks,
> > Gary
> >
> >
>
==
> > #include 
> > #include 
> > #include 
> > #include 
> >
> > #define outp(a,b) b=a
> > #define inp(a) a
> > typedef unsigned char  u08;
> > typedef unsigned short u16;
> > #define UART_BAUD_SELECT 0x2F //9600 baud
> >
> > #define PRG_RDB( addr )   __LPM((unsigned
> > short)(addr))
> > #define BV(bit) (1 << (bit))
> >
> > /* UART global variables */
> >
> > volatile u08   RxChar;
> > volatile int i = 0;
> >
> > /* UART Transmit Complete Interrupt Function */
> > SIGNAL(SIG_UART0_TRANS)
> > {
> >  outp(0x43,UDR0);
> > }
> >
> >
> > /* UART Receive Complete Interrupt Function */
> > SIGNAL(SIG_UART0_RECV)
> > {
> > RxChar = inp(UDR0);
> > outp(RxChar, PORTB);
> > }
> >
> > void UART_Init(void)
> > {
> > /* enable RxD/TxD and interrupts */
> >
> >
> >
>
outp(BV(RXCIE0)|BV(TXCIE0)|BV(RXEN0)|BV(TXEN0),UCSR0B);
> > //outp(BV(RXCIE0)|BV(RXEN0)|BV(TXEN0),UCSR0B);
> >
> > /* set baud rate */
> > //outp(0x0, UBRR0H);
> > //outp( (u08)UART_BAUD_SELECT, UBRR0L);
> >
> > // Async. mode, 8N1
> >UCSR0C =
> >
>
(0< > /* enable interrupts */
> > sei();
> > }
> >
> > int main(void)
> > {
> > outp(0xff, DDRB); //port B output
> > UART_Init();
> > // for(;;){
> > outp(0x41,UDR0);
> > // }
> > return 0;
> > }
> >
> >
> >
> 
> 
> 
> ___
> AVR-GCC-list mailing list
> AVR-GCC-list@nongnu.org
>
http://lists.nong

Re: [avr-gcc-list] Small program for UART not working

2005-08-29 Thread Gary Bi
>From the scope, I can calculate the baud rate rough
number, for example, if setting it to 9600 in MCU, on
scope, it was around that range; setting to 57600, the
reading from scope will be around 57600, etc. But I
don't know the exacly reading, since there's no way to
read it, I can only calculate it though the measure of
waveform frequency. I also noticed the start bit
(1bit) and stop bit (bit) is correctly set in the
waveform.

Thanks,
Gary


--- Gary Bi <[EMAIL PROTECTED]> wrote:

> Hi David and Ian,
> 
> Thanks for the help. I checked the fuses for mega101
> mode, it did set to ON. I uncheck it in AVR studio
> and
> program it, but this did not make improvement to the
> issue.
> 
> I shorted the PIN2 and PIN3 at the end of cable (the
> end plugs to PC RS232), I still can see the data was
> received through the loopback, demonstrated through
> LEDs on STK board. The RS232 cable is good, since I
> short the other end, I can see the chars typed
> displayed on the termial.
> 
> I'm suspecting the baud rate was not set accurately
> in
> Atmega128L, so cause the reception of PC side is not
> synchronized. For example, if I set to 115200, but
> not
> accurate, the number could be set as 115000, so I
> have
> some errors in PC terminal.
> 
> I tried to calculate the baud rate on scope, I found
> I
> can't get a exactly number, I can only get an
> estimate. Do you know if there's way to set the baud
> rate accurately?
> 
> Thanks,
> Gary
> 
> 
> 
> 
> --- David Brown <[EMAIL PROTECTED]> wrote:
> 
> > Hi,
> > 
> > Since you can see the data on your scope, and
> > loopback works fine when
> > shorting RX and TX pins, there seems to be nothing
> > wrong with the
> > microcontroller.  The things I would now check are
> > the baud rate (using the
> > scope), the RS-232 line drivers, the TX-RX
> > orientation (I've fixed many
> > communications problems by swapping the TX and RX
> > lines !), the cable
> > between the board and the PC (including the ground
> > line), and the PC serial
> > port.  It can be worth shorting the TX and RX pins
> > at the board end of the
> > cable and testing loop-back from the PC side using
> > TTP.
> > 
> > mvh.,
> > 
> > David
> > 
> > 
> > 
> > > Hi David,
> > >
> > > Thanks for the info. I downloaded Tera Term Pro
> > and
> > > installed it in my PC, it's a defenitely a
> better
> > > terminal simulation. Unfortunately I got the
> same
> > > result.
> > >
> > > My problem are:
> > >
> > > 1. Atmel128L has successfully sent out
> characters
> > in
> > > TX, but I can not receive it correctly in PC
> > termimal.
> > > When monitoring the TX pin in scope, I can see
> > char
> > > 'B' has been sent out continuouly.
> > > /* UART Transmit Complete Interrupt Function */
> > > SIGNAL(SIG_UART0_TRANS){
> > > outp('B',UDR0);
> > > }
> > > When I short TX and RX pin together in Atmel STK
> > > board, I can see the 'B' was displayed correctly
> > > (demonstrated using LEDs, PIN7-0 is for Bit7-0).
> > > /* UART Receive Complete Interrupt Function */
> > > SIGNAL(SIG_UART0_RECV){
> > > RxChar = inp(UDR0);
> > > outp(RxChar, PORTB);
> > > }
> > > What I receivd in TTP teminal is 0xA2 instead of
> > > character 'B' (0x42).
> > >
> > > 2. I did not set baud rate in the codes for
> Atmel,
> > in
> > > TTP, I will need to set the baud rate to 57600,
> > 8-N-1
> > > to get the RX working, so if I type 'C', I can
> see
> > the
> > > LEDs is demonstrated 'C' correctly. If the set
> the
> > > baud rate to 9600, 115200, etc. I can not get
> the
> > Rx
> > > working. This is very strange.
> > > So I have to comment out the two lines for baud:
> > > //outp(0x0, UBRR0H);
> > > //outp( (u08)UART_BAUD_SELECT, UBRR0L);
> > >
> > > The MCU is running at 7.3728Mhz, I set the baud
> > > parameter to 0x2F according to the datasheet.
> > > #define UART_BAUD_SELECT 0x2F //9600 baud
> > >
> > > There's typo in my previous email, what I want
> to
> > say
> > > is: I can see the character 'B' is sending out,
> I
> > just
> > > did not receive it correctly in PC.
> > >
> > > 3. Do you think it's possible it's related to a
> > defect
> > > MCU (ATMEGA128L)? I'm trying to buy a new
> > MCU(order
> > > ATMEGA128-16AI (16Mhz), but not sure if it will
> > work
> > > with 7.3728MHz crystal on STK or not.
> > >
> > > Thanks,
> > > Gary
> > >
> > >
> >
>
==
> > > #include 
> > > #include 
> > > #include 
> > > #include 
> > >
> > > #define outp(a,b) b=a
> > > #define inp(a) a
> > > typedef unsigned char  u08;
> > > typedef unsigned short u16;
> > > #define UART_BAUD_SELECT 0x2F //9600 baud
> > >
> > > #define PRG_RDB( addr )   __LPM((unsigned
> > > short)(addr))
> > > #define BV(bit) (1 << (bit))
> > >
> > > /* UART global variables */
> > >
> > > volatile u08   RxChar;
> > > volatile int i = 0;
> > >
> > > /* UART Transmit Complete Interrupt Function */
> > > SIGNAL(SIG_UART0_TRANS)
> > > {
> > >  outp(0x43,UDR0);
> > > }
> > >
> > >
> > > /* UART Receive Complete Inter

Re: [avr-gcc-list] Small program for UART not working

2005-08-29 Thread David Brown
Hi,

Since you can see the data on your scope, and loopback works fine when
shorting RX and TX pins, there seems to be nothing wrong with the
microcontroller.  The things I would now check are the baud rate (using the
scope), the RS-232 line drivers, the TX-RX orientation (I've fixed many
communications problems by swapping the TX and RX lines !), the cable
between the board and the PC (including the ground line), and the PC serial
port.  It can be worth shorting the TX and RX pins at the board end of the
cable and testing loop-back from the PC side using TTP.

mvh.,

David



> Hi David,
>
> Thanks for the info. I downloaded Tera Term Pro and
> installed it in my PC, it's a defenitely a better
> terminal simulation. Unfortunately I got the same
> result.
>
> My problem are:
>
> 1. Atmel128L has successfully sent out characters in
> TX, but I can not receive it correctly in PC termimal.
> When monitoring the TX pin in scope, I can see char
> 'B' has been sent out continuouly.
> /* UART Transmit Complete Interrupt Function */
> SIGNAL(SIG_UART0_TRANS){
> outp('B',UDR0);
> }
> When I short TX and RX pin together in Atmel STK
> board, I can see the 'B' was displayed correctly
> (demonstrated using LEDs, PIN7-0 is for Bit7-0).
> /* UART Receive Complete Interrupt Function */
> SIGNAL(SIG_UART0_RECV){
> RxChar = inp(UDR0);
> outp(RxChar, PORTB);
> }
> What I receivd in TTP teminal is 0xA2 instead of
> character 'B' (0x42).
>
> 2. I did not set baud rate in the codes for Atmel, in
> TTP, I will need to set the baud rate to 57600, 8-N-1
> to get the RX working, so if I type 'C', I can see the
> LEDs is demonstrated 'C' correctly. If the set the
> baud rate to 9600, 115200, etc. I can not get the Rx
> working. This is very strange.
> So I have to comment out the two lines for baud:
> //outp(0x0, UBRR0H);
> //outp( (u08)UART_BAUD_SELECT, UBRR0L);
>
> The MCU is running at 7.3728Mhz, I set the baud
> parameter to 0x2F according to the datasheet.
> #define UART_BAUD_SELECT 0x2F //9600 baud
>
> There's typo in my previous email, what I want to say
> is: I can see the character 'B' is sending out, I just
> did not receive it correctly in PC.
>
> 3. Do you think it's possible it's related to a defect
> MCU (ATMEGA128L)? I'm trying to buy a new MCU(order
> ATMEGA128-16AI (16Mhz), but not sure if it will work
> with 7.3728MHz crystal on STK or not.
>
> Thanks,
> Gary
>
> ==
> #include 
> #include 
> #include 
> #include 
>
> #define outp(a,b) b=a
> #define inp(a) a
> typedef unsigned char  u08;
> typedef unsigned short u16;
> #define UART_BAUD_SELECT 0x2F //9600 baud
>
> #define PRG_RDB( addr )   __LPM((unsigned
> short)(addr))
> #define BV(bit) (1 << (bit))
>
> /* UART global variables */
>
> volatile u08   RxChar;
> volatile int i = 0;
>
> /* UART Transmit Complete Interrupt Function */
> SIGNAL(SIG_UART0_TRANS)
> {
>  outp(0x43,UDR0);
> }
>
>
> /* UART Receive Complete Interrupt Function */
> SIGNAL(SIG_UART0_RECV)
> {
> RxChar = inp(UDR0);
> outp(RxChar, PORTB);
> }
>
> void UART_Init(void)
> {
> /* enable RxD/TxD and interrupts */
>
>
> outp(BV(RXCIE0)|BV(TXCIE0)|BV(RXEN0)|BV(TXEN0),UCSR0B);
> //outp(BV(RXCIE0)|BV(RXEN0)|BV(TXEN0),UCSR0B);
>
> /* set baud rate */
> //outp(0x0, UBRR0H);
> //outp( (u08)UART_BAUD_SELECT, UBRR0L);
>
> // Async. mode, 8N1
>UCSR0C =
> (0< /* enable interrupts */
> sei();
> }
>
> int main(void)
> {
> outp(0xff, DDRB); //port B output
> UART_Init();
> // for(;;){
> outp(0x41,UDR0);
> // }
> return 0;
> }
>
>
>



___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


Re: [avr-gcc-list] Small program for UART not working

2005-08-28 Thread Ian Caddy

Hi Gary,

From your description of your output data, it looks like it is 
configured for either 7 data bits (which will cause the stop bit to look 
like the MSB of the data on the receiver causing it to be set), or that 
somehow parity is being set.


I had a quick look at your program and that doesn't seem to be the case, 
but have you made sure that you don't have your chip in mega103 
compatability mode which does change the function of the UART?  It is 
one of the programming fuses that enables this functionality and it is 
shipped with it ON by default.


Sorry I couldn't be of more help.

regards,

Ian Caddy





Gary Bi wrote:

Hi David,

Thanks for the info. I downloaded Tera Term Pro and
installed it in my PC, it's a defenitely a better
terminal simulation. Unfortunately I got the same
result.

My problem are:

1. Atmel128L has successfully sent out characters in
TX, but I can not receive it correctly in PC termimal.
When monitoring the TX pin in scope, I can see char
'B' has been sent out continuouly. 
/* UART Transmit Complete Interrupt Function */

SIGNAL(SIG_UART0_TRANS){
outp('B',UDR0);
}
When I short TX and RX pin together in Atmel STK
board, I can see the 'B' was displayed correctly
(demonstrated using LEDs, PIN7-0 is for Bit7-0).
/* UART Receive Complete Interrupt Function */
SIGNAL(SIG_UART0_RECV){
RxChar = inp(UDR0);
outp(RxChar, PORTB);
}
What I receivd in TTP teminal is 0xA2 instead of
character 'B' (0x42).

2. I did not set baud rate in the codes for Atmel, in
TTP, I will need to set the baud rate to 57600, 8-N-1
to get the RX working, so if I type 'C', I can see the
LEDs is demonstrated 'C' correctly. If the set the
baud rate to 9600, 115200, etc. I can not get the Rx
working. This is very strange.
So I have to comment out the two lines for baud:
//outp(0x0, UBRR0H);
//outp( (u08)UART_BAUD_SELECT, UBRR0L);

The MCU is running at 7.3728Mhz, I set the baud
parameter to 0x2F according to the datasheet.
#define UART_BAUD_SELECT 0x2F //9600 baud

There's typo in my previous email, what I want to say
is: I can see the character 'B' is sending out, I just
did not receive it correctly in PC.

3. Do you think it's possible it's related to a defect
MCU (ATMEGA128L)? I'm trying to buy a new MCU(order
ATMEGA128-16AI (16Mhz), but not sure if it will work
with 7.3728MHz crystal on STK or not.

Thanks,
Gary

==
#include 
#include 
#include 
#include 

#define outp(a,b) b=a
#define inp(a) a
typedef unsigned char  u08;
typedef unsigned short u16;
#define UART_BAUD_SELECT 0x2F //9600 baud

#define PRG_RDB( addr )   __LPM((unsigned
short)(addr))
#define BV(bit) (1 << (bit))

/* UART global variables */

volatile u08   RxChar;
volatile int i = 0;

/* UART Transmit Complete Interrupt Function */
SIGNAL(SIG_UART0_TRANS)  
{

 outp(0x43,UDR0);
}


/* UART Receive Complete Interrupt Function */
SIGNAL(SIG_UART0_RECV)  
{

RxChar = inp(UDR0);
outp(RxChar, PORTB);
}

void UART_Init(void)
{
/* enable RxD/TxD and interrupts */
   
   
outp(BV(RXCIE0)|BV(TXCIE0)|BV(RXEN0)|BV(TXEN0),UCSR0B);

//outp(BV(RXCIE0)|BV(RXEN0)|BV(TXEN0),UCSR0B);

/* set baud rate */
//outp(0x0, UBRR0H);
//outp( (u08)UART_BAUD_SELECT, UBRR0L);

// Async. mode, 8N1
   UCSR0C =
(0

Re: [avr-gcc-list] Small program for UART not working

2005-08-28 Thread Gary Bi
Hi David,

Thanks for the info. I downloaded Tera Term Pro and
installed it in my PC, it's a defenitely a better
terminal simulation. Unfortunately I got the same
result.

My problem are:

1. Atmel128L has successfully sent out characters in
TX, but I can not receive it correctly in PC termimal.
When monitoring the TX pin in scope, I can see char
'B' has been sent out continuouly. 
/* UART Transmit Complete Interrupt Function */
SIGNAL(SIG_UART0_TRANS){
outp('B',UDR0);
}
When I short TX and RX pin together in Atmel STK
board, I can see the 'B' was displayed correctly
(demonstrated using LEDs, PIN7-0 is for Bit7-0).
/* UART Receive Complete Interrupt Function */
SIGNAL(SIG_UART0_RECV){
RxChar = inp(UDR0);
outp(RxChar, PORTB);
}
What I receivd in TTP teminal is 0xA2 instead of
character 'B' (0x42).

2. I did not set baud rate in the codes for Atmel, in
TTP, I will need to set the baud rate to 57600, 8-N-1
to get the RX working, so if I type 'C', I can see the
LEDs is demonstrated 'C' correctly. If the set the
baud rate to 9600, 115200, etc. I can not get the Rx
working. This is very strange.
So I have to comment out the two lines for baud:
//outp(0x0, UBRR0H);
//outp( (u08)UART_BAUD_SELECT, UBRR0L);

The MCU is running at 7.3728Mhz, I set the baud
parameter to 0x2F according to the datasheet.
#define UART_BAUD_SELECT 0x2F //9600 baud

There's typo in my previous email, what I want to say
is: I can see the character 'B' is sending out, I just
did not receive it correctly in PC.

3. Do you think it's possible it's related to a defect
MCU (ATMEGA128L)? I'm trying to buy a new MCU(order
ATMEGA128-16AI (16Mhz), but not sure if it will work
with 7.3728MHz crystal on STK or not.

Thanks,
Gary

==
#include 
#include 
#include 
#include 

#define outp(a,b) b=a
#define inp(a) a
typedef unsigned char  u08;
typedef unsigned short u16;
#define UART_BAUD_SELECT 0x2F //9600 baud

#define PRG_RDB( addr )   __LPM((unsigned
short)(addr))
#define BV(bit) (1 << (bit))

/* UART global variables */

volatile u08   RxChar;
volatile int i = 0;

/* UART Transmit Complete Interrupt Function */
SIGNAL(SIG_UART0_TRANS)  
{
 outp(0x43,UDR0);
}


/* UART Receive Complete Interrupt Function */
SIGNAL(SIG_UART0_RECV)  
{
RxChar = inp(UDR0);
outp(RxChar, PORTB);
}

void UART_Init(void)
{
/* enable RxD/TxD and interrupts */
   
   
outp(BV(RXCIE0)|BV(TXCIE0)|BV(RXEN0)|BV(TXEN0),UCSR0B);
//outp(BV(RXCIE0)|BV(RXEN0)|BV(TXEN0),UCSR0B);

/* set baud rate */
//outp(0x0, UBRR0H);
//outp( (u08)UART_BAUD_SELECT, UBRR0L);

// Async. mode, 8N1
   UCSR0C =
(0

Re: [avr-gcc-list] Small program for UART not working

2005-08-28 Thread David Brown
- Original Message -
From: "Gary Bi" <[EMAIL PROTECTED]>
>
> My believe the default baud rate is 57600 and 8-N-1
> for Atmega128L, because in my code, I did not set the
> baud rate, but the hyper terminal side, I need to set
> it as 57600, 8-N-1 (eight bit, no parity bit, 1 stop
> bit).
>

Here's a few points to get you started.  First off, there is no such thing
as a "default baud rate" for a UART - you have to set it explicitly in your
software.  The baud rate divisors are entirely dependant on your clock rate,
so you have to make sure that is as expected as well.  Second,
"hyperterminal" is universally acknoweldged to be the worst terminal
emulator program ever created.  Get a real terminal emulator program so that
you avoid any issues there ("Tera Term Pro" is probably the most commonly
used general-purpose terminal emulator on windows - others on the list may
have other favourites, but stick to TTP for simplicity).  Third, if you have
a scope connected to the Tx pin, then you should be able to see the data
transmitted and figure out if it is correct (assuming you have a digital
scope).  If you don't know what the data should look like, read the AVR
datasheet - identifying and debugging UART communications with a scope is a
useful skill.

mvh.,

David




___
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list


[avr-gcc-list] Small program for UART not working

2005-08-27 Thread Gary Bi
I have next small program trying to set the UART0 for
Atmega128L, it is interrupt driven, I connect Atmel
STK502 with a PC, I found Rx is working, when clicking
the key, for example, type 'A', I can see the LED is
toggling: 

LED7-off, LED6-off,
LED5-on,LED4-on,LED3-on,LED2-on,LED1-on, LED0-off
The corresponding ASCII value is: 0x41 ('A').

My trouble is that the TX is not working, I can see
some garbage character is keeping displayed in the
Hyper terminal Window, but when I turn off the STK
board, I noticed in the bottom, there are some 'B'
characters displayed. My intention is to display one
'A' character and followed many 'B's (display 'B'
forever).

My believe the default baud rate is 57600 and 8-N-1
for Atmega128L, because in my code, I did not set the
baud rate, but the hyper terminal side, I need to set
it as 57600, 8-N-1 (eight bit, no parity bit, 1 stop
bit).

I tried to monitoring the TX in oscilloscope, I
noticed, 'A' character is keeping sending out.

Here is the output in my hyter terminal: 



¢ÂÂBBB

I tried setting different baud rate, it became worse,
I can not even see chars displayed in pc side and the
RX is even not working when tried other baud rate.

Does anyone see the similiar issue before?

Attached is the complete code.

Thanks in advance.

Gary

---
#include 
#include 
#include 
#include 
//#include 
//#include "uart.h"

#define outp(a,b) b=a
#define inp(a) a
typedef unsigned char  u08;
typedef unsigned short u16;
#define UART_BAUD_SELECT 0x33 //9600 baud

#define PRG_RDB( addr )   __LPM((unsigned
short)(addr))
#define BV(bit) (1 << (bit))

/* UART global variables */

volatile u08   RxChar;

/* UART Transmit Complete Interrupt Function */
SIGNAL(SIG_UART0_TRANS)  
{

 outp('B',UDR0);
 
}

/* UART Receive Complete Interrupt Function */
SIGNAL(SIG_UART0_RECV)  
{
RxChar = inp(UDR0);
outp(RxChar, PORTB);
}

void UART_Init(void)
{
/* enable RxD/TxD and interrupts */
   
   
outp(BV(RXCIE0)|BV(TXCIE0)|BV(RXEN0)|BV(TXEN0),UCSR0B);
/* set baud rate */
//outp(0x0, UBRR0H);
//outp( (u08)UART_BAUD_SELECT, UBRR0L);

// Async. mode, 8N1
   UCSR0C =
(0