Codevision USART help request with lots of details

Go To Last Post
26 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Looks like I'm about to fail USART class.
I spent today reading the USART tutorial for AVR-GCC and trying to get it working with codevision.

I'm trying my hardest.

I've read the mega88 data sheet a few times,
read the tutorial a few times,
applied the tutorials to my programs and
made sure not to use any magic numbers....

googled other tutorials and read those,
(You should be able to tell I've done some homework)
I have all the right drivers installed I need I think,
I researched a terminal program,
used codevisions terminal program,
tried crossing my tx and rx wires,
I can't see any UART data on the O-scope sniffer..
but I do see data TX'ing on the O-scope normal screen!

What did I do wrong?
It would seem data is sending but my PC is not receiving it?

Lets walk through this once more.
Then I have more questions at the end!

I have THIS pololu USB rs232 converter hooked up like so..

the pololu drivers are installed and the PC sees the COM3 port. The LED is on on the pololu com device.

So I Wrote some code to try and transmit data to the COM3 port. I tried to send data two different ways.
One, with a function, and two, just regular old send data and wait for it to finish like in the tutorial on this site.

/*******************************************************
This program was created by the
CodeWizardAVR V2.60 Evaluation
Automatic Program Generator
© Copyright 1998-2012 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com

Project : 
Version : 
Date    : 9/26/2012
Author  : 
Company : 
Comments: 


Chip type               : ATmega88PA
Program type            : Application
AVR Core Clock frequency: 7.372800 MHz
Memory model            : Small
External RAM size       : 0
Data Stack size         : 256
*******************************************************/

#include 
#include 
#include  // Standard Input/Output functions???

#define LED1 PORTB.5
#define LED2 PORTB.4
#define USART_BAUDRATE 9600
#define F_CPU 7372800 //zero error clock frequency as set by codevision... faked for no magic numbers
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1) //(((7.372800/(9600*16)))-1)  so 9600*16=153600 /7.372800=48-1=47 no magic numbers

//prototypes
void USARTWriteChar(char data);

void USARTWriteChar(char data)
{
   //Wait until the transmitter is ready
   while(!(UCSR0A & (1<<UDRE0)))
   {
      //Do nothing
   }
   //Now write the data to USART buffer
   UDR0=data;
}

void main(void)
{
...................................
// USART initialization
// Communication Parameters: 8 Data, 1 Stop, No Parity
// USART Receiver: On
// USART Transmitter: On
// USART0 Mode: Asynchronous
// USART Baud Rate: 9600       //RXCO rx complete flag TXCO TX complete flag.........................................................................................
UCSR0A=(0<<RXC0) | (0<<TXC0) | (0<<UDRE0) | (0<<FE0) | (0<<DOR0) | (0<<UPE0) | (0<<U2X0) | (0<<MPCM0);
UCSR0B=(0<<RXCIE0) | (0<<TXCIE0) | (0<<UDRIE0) | (1<<RXEN0) | (1<<TXEN0) | (0<<UCSZ02) | (0<<RXB80) | (0<<TXB80);
UCSR0C=(0<<UMSEL01) | (0<<UMSEL00) | (0<<UPM01) | (0<<UPM00) | (0<<USBS0) | (1<<UCSZ01) | (1<<UCSZ00) | (0<<UCPOL0);
UBRR0H=(BAUD_PRESCALE >> 8); //load upper 8 bits to UBBBR0H 
UBRR0L=BAUD_PRESCALE;  //lower eight bits baud value 47 9600kbps  //use BAUD_PRESCALE ... no magic numbers

............................
while (1)
      {
      i=1;
      UDR0=i; //send i?
      while ((UCSR0A & (1 << TXC0)) == 0) {}; // Do nothing until transmission complete flag set 
      LED1=1;
      LED2=0;
      delay_ms(100);
      i=2;
      UDR0=i; //send i?
      while ((UCSR0A & (1 << TXC0)) == 0) {};
      LED1=0;
      LED2=1;
      delay_ms(100); 
      USARTWriteChar(7E);    //testing function
      
      }
}

And then I open a terminal as I found in a tutorial online. I select COM3

then I Set the baud

And I get nothing from the AVR.
No data, no transmissions received.
Can anyone see what I did wrong?

I set my 0-scope to sniff UART data and get nothing!

But if I use regular O-scope I get data coming out of the TX line on the Mega88 MCU! I know something is coming off the TX pin. does this mean it's working?!

Now for my other questions...

1)what is the equivalence of "F_CPU" in Codevision?
I "faked it" for now as you see in the code because I know the processor is set to 7.372800 MHz.

2)How do the 8mhz Fuse Bit settings come into
play when using the system clock at 7.37mhz?!

3)Am I using the right temrinal?
I've used codevision terminal too and it didn't work either!

4)where did I go wrong in the code?

5)Why was stdio.h included when I enabled the USART?
How do I use sdtio.h?

6)I must have missed this in the data sheet.
What is the difference between synchronous and asynchronous?

7) Is USART0 the right thing to be using to do this?

Many thanks guys. I'm lost again as usual.
Feel free to school me.
I'm trying as hard as I can over here.

if (Learning_AVRs)
{
DOH();
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
I spent today reading the USART tutorial for AVR-GCC and trying to get it working with codevision
Why in the world would you want to do that when Codevision has done it all for you already?

Have you looked at the Codevision examples in the example folder like 2USART_LCD?

hmm the rest of the post is too long for my tired eyes. :-)

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I got it!

I don't know what I was overlooking but I fiddled with the wires for a second and it's working now! Sweeeeeeeeeeeeeeeeeeet

Now that was a day well spent! :lol:
Took me from 6am to 11pm to learn to transmit data with USART to PC with AVRFreaks tutorial and codevision.
:P

Quote:

Why in the world would you want to do that when Codevision has done it all for you already?

Yes I'm still trying to learn how to use all the stuff codevision prepares for you!
I think in the long run it enables all the same registers etc so if I just work on the registers my own, I can work around codevison, or with it, as I choose?!

Now I just need to figure out how to make it send characters I can make sense of. I think I might have an idea...

if (Learning_AVRs)
{
DOH();
}

Last Edited: Thu. Sep 27, 2012 - 06:04 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
      i=1;
      UDR0=i; //send i?

Try with something printable instead. i = '1'; for example. Another popular choice is 'U', since it's 01010101 in binary you'll get a nice square wave if you put it in a loop, then you can easily measure the bit time. I can't see your definition of i?

USARTWriteChar(7E);    //testing function 

Did that really compile? 7E isn't a valid symbol in C.

(And you probably run your MCU in the MHz range, (not milli))

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

yes 7E compiled?!. I was just throwing things at it to see if anything came out!

We have something working but I need to output proper characters now!
I think it's a matter of inputting the proper character in the first place.
I have more research to do, and as usual, asked my questions too early! haha

Sheesh I'm happy I just got it to do something after all that. =P

Quote:

(And you probably run your MCU in the MHz range, (not milli))

I'm not sure I understand this one?

Many thanks for the help/input dudes.
I know I'm tough to work with!

if (Learning_AVRs)
{
DOH();
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

cakemonster wrote:
yes 7E compiled?!
Strange compiler ;-) Maybe it take it as 7E0 (== 7)? GCC say
Quote:
error: exponent has no digits
cakemonster wrote:

Quote:

(And you probably run your MCU in the MHz range, (not milli))

I'm not sure I understand this one?
Didn't you click the M? It's a link :-). m is short for milli it's the same as 0.001, M is mega, its 1000000.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Woops I thought that was text color not a link! I'll check it now.

Here's the error compiled in codevision! hehe

if (Learning_AVRs)
{
DOH();
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think CodeVision must be interpreting "7E" as "7E0" which, as snigelen says, is 7.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why do you wait 100 ms when sending chars to your PC at 9600bds (once your leds have shown you parts of your programs are accessible, you can omit them)?

UDR0=i; //send i? 

might be replaced by (works with i between 0 and 9 and gives something readable on a PC) :

unsigned char i_to_send=i+'0'; 
UDR0=i_to_send; 

And my old eyes do see not where and how you declared i;

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just tried:

     PORTB = 7E;

and CodeVision produced this (with no errors)


                 ; 0000 000B      PORTB = 7E;
               
000081 e0e7     LDI R30 , LOW ( 0x7 )
000082 e0f0     LDI R31 , HIGH ( 0x7 )
000083 e060     LDI R22 , BYTE3 ( 0x7 )
000084 e070     LDI R23 , BYTE4 ( 0x7 )
                    __GETD1N 0x7
000085 b9e5         OUT  0x5,R30

So it has parsed "7E" as "0x7uL"

Perhaps Pavel should fix this.

Regarding the original subject. I am amazed that when a Compiler comes out of the box with a full set of libraries, Help system and Wizard, that a punter does not bother to read the documentation.

Users of avr-gcc have to do a lot of homework before they can use the USART, let alone functions like printf().

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

lol If you only knew how much documentation I've read the last month...

I can't read it all at once! I have to take it in strides.
I'm getting there... slowly...

I didn't know how to use a timer a few weeks ago, I'm doing PWM, USART and RC RX stuff now.

You guys have to find a way to go easy on somebody who doesn't know all this stuff. I'm trying really hard to do good! :D It should be evident I've been reading lots of documentation by now. In fact I've been going out of my way to learn things at the base level of register flipping instead of mostly relying on codevision premade code..I'm even trying to honor the
"no magic numbers" way of doing things!

When I let codevision set things up for me, it starts making magic numbers. I usually have to go in and change everything around codevision sets up for me anyway. That's not the first error I've seen in it. Just too busy to remember them all and record them.

I just don't feel like learning to work with another compiler at this time. Too much else going on. Codevision was the way I was introduced to AVR. I kinda like it.

if (Learning_AVRs)
{
DOH();
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

So it has parsed "7E" as "0x7uL"

Perhaps Pavel should fix this.


I think it is closer to Cliff's
Quote:

I think CodeVision must be interpreting "7E" as "7E0" which, as snigelen says, is 7.

However, my reading of the [draft] C standard sez an "exponent part" is "E digit-sequence" and a digit-sequence needs at least one "digit" (which is one of 0-9). So indeed a "fix" seems in order.

I jammed "7E" into a few lines of a test program with the current version of CV, and got a "possible loss of precision" warning on each.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:
When I let codevision set things up for me, it starts making magic numbers. I usually have to go in and change everything around codevision sets up for me anyway. That's not the first error I've seen in it. Just too busy to remember them all and record them.

The current version of the Wizard uses proper BIT_NAMES. It also writes an explanatory comment in plain English.

It also comes with example projects as well as example code in the Help pages.

I suggest that you choose one Compiler and stick with it. Otherwise you will get confused with too much information. When you get more experience, you can flip between different packages quite easily.

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

That's not the first error I've seen in it.

Oh, that's too bad.

Quote:

Just too busy to remember them all and record them.

Oh, that's even worse.

So, CodeVision is rife with errors? Is one of those the "7E" thing? Is that even an error? Pretty subtle if it is.

As a veteran CV user and having done AVR8 apps for many models I will use the Wizard from time to time to aid in peripheral subsystem setup in new apps. Often, the Wizard "picks up" a related I/O register that would have slipped by me so it is an aid even as a "veteran".

I've picked up and reported a few Wizard anomalies over the years, usually in new AVR models. As you mentioned the Wizard is just an aid that needs to be further annotated to put into the context of the particular app. The key is "reported". Just saying that you can't "remember them all" implying that there are lots of them will get my dander up. CV is pretty solid at what it does.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No, it's not a 7E thing.

I forgot what it was already by now but when I remember it I'll post it.
I've been over this before.

I agree, codevision works good, I have no problems with it. But nothing is perfect.

Quote:
So, CodeVision is rife with errors?

You may be reading too much into this..

I think the focus of this thread is USART.

if (Learning_AVRs)
{
DOH();
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

As someone famous recently tweeted:

Quote:
99% of "compiler is broken" complaints boil down to "I don't understand how the compiler works". Remaining 1% is very interesting however.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I agree,
I perfectly accept that half the things I'm doing are noobish and I'll be confusing the compiler.

I think there was actually one error I caught it doing though.
It was an initialization of something.

It said on my Tiny that my clock was initialized with a divider that was not there or something like that. Then it had another initialization error somewhere from the codewizard one time, I'm fairly sure.

But when I know how to operate the registers,
I can work around the codewizard.

That's all I'm saying.
I can still use codevision, without the codewizard, if I know how to operate all the registers like the guys do with GCC.

I didn't mean anything bad toward codevision or insinuate I know more than the compiler. I know I'm new more than anyone else does. lol

It's tough for me to catch all this with 5 windows open (one for compiler, one for AVR data sheet, one tutorial, one google window for searching things I Can't understand and a hyper terminal) while racking my brains trying to keep places while flipping back and fourth between them all and understand it all at the same time. Then I have to keep on top of hardware to boot.

I need to go grab a ream of paper and just print all this stuff out. It would be much easier.

if (Learning_AVRs)
{
DOH();
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm having a problem getting the terminals to work.
Codevision terminal only worked once to display characters and hasn't worked since.

Right now it will send chars but it won't display them.
But Windows Terminal has no problem displaying stuff, but I can't send with it?!

if (Learning_AVRs)
{
DOH();
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When things stop making sense. STOP! With regard to the 'terminals' - where is the problem? the PC side or your dodgy hardware side? Do a loopback from rx to tx so that takes the AVR out of the equation. Try your 'terminals' - do they work or not work? Sort that problem out first. Solve one problem at a time and reduce the unknowns. Personally, rather than poke wires into a breadboard, I'd much rather start from something a bit more stable so I don't waste time with dodgy wires etc. Writing and debugging code is complex enough without introducing hardware problems into the mix, so I use an Arduino board. In terms of my time, they're worth about 20 minutes but will save me hours. Whether or not you 'like' Arduino is purely an emotional response - if this is the case, get a STK500, but i can plug the UNO board into my USB on my computer which powers it (no need for another power supply) and gives me a USB to serial interface with a crystal on the AVR and the fuses set correctly. At least 10 points of potential problems have been avoided before you start.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You guys are a tough crowd.
I'd rather not relearn another IDE right now.
I'm working with the ones I know.

With arduino I have to plug stuff into it a breadboard anyway too and still learn all this, right?

Wires are what I'm good with. Coding AVR, not so much.

Loopback isn't working right in either terminal.
There's one one wire involved to do loopback and I'm certain there's continuity.

maybe I'll look for a new terminal.
Codevision terminal connected once as far as receiving and that's it. It's not wires. It will receive by itself and it can send. it's not doing both at once though. I can use one program or the other to do one or the other, but not both.

That should mean it's not wires. Something else funny I have to sniff down. Maybe the new send receive code I wrote.

It's right out of codevision stdio, though.

if (Learning_AVRs)
{
DOH();
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The suggestion was to use the Arduino hardware! We're not tough - we're just battle hardened. We could sugar coat our responses, but that would only lead to more confusion. Also, to us oldies, a 'terminal' is an actual device - I gather you mean 'terminal program'. The last 'Windows terminal' i saw was in win 3.1. Hyperterminal was in the later ones up to XP. Be precise.
Until you get the loopback sorted, no use moving on. Some use Br@ys terminal, but I use PuTTy. Hyperterminal has worked well for me over the years. Make sure you set handshake to NONE. That could explain your problems.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Loopback working in codevision.
Trying to figure out what I'm missing now..
messing with code.

if (Learning_AVRs)
{
DOH();
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

cakemonster wrote:
Loopback working in codevision
...and for the benefit of future readers of his thread who may have the same problem, and as a small contribution from yourself, the problem was...?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I still don't know the problem.
I'm still having problems..
Things take time for me to figure out. Nothing happens instant here. Just like I don't know all the data sheets and code right away without studying it and then learning it.

I can send and receive separately but not both at the same time.

i=USARTReadChar();
      LED1=1;
      LED2=0;
      delay_ms(50);
      USARTWriteChar(i);  
      LED1=0;
      LED2=1; 

Seems like people here make such a big deal out of teaching somebody such a tiny snippet of code..
It's not all that hard once I figure it out for myself. I don't think I really need to switch out to "Audry"-uno. It may be nice if I could switch out to a more supportive atmosphere though.

I have 10 other hobbies in my life. Trying to learn something here about AVR while getting railed all the time isn't something I have time for. I'm better off studying the data and shotgunning the whole way through it than asking questions here.

To receive such responses for something I simply threw at the compiler as "7E"... wow...
I wonder who the adults are?

HAs nobody ever "just tried something to see if it works?"

BTW 7E DOES output a character! Weather or not it's illegal.

if (Learning_AVRs)
{
DOH();
}

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

cakemonster wrote:

I can send and receive separately but not both at the same time.

What do you mean by 'at the same time'?

#1 Hardware Problem? https://www.avrfreaks.net/forum/...

#2 Hardware Problem? Read AVR042.

#3 All grounds are not created equal

#4 Have you proved your chip is running at xxMHz?

#5 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand."

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman :

Quote:
so I use an Arduino board

Hopefully not hijacking this thread :oops:
This reminded me that I am starting to look at the Arduino
hardware too. With all of the shields that are available
it would make things easier to prototype, at least to develop the code concept.

I am a bit hesitant concerning using the USB interface.
Recently, I tried to install a driver for a Digi XBEE module in order access the XBEE module. I got the "Blue Screen of Death" on my XP_PRO PC.. I had to do a system restore to get my other USB drivers back to work after deleting the installed driver. . I do have the Arduino app installed on my Linux box, so perhaps that is the better way to go.

I'll believe corporations
are people when Texas executes one.