Communication between the MCU and PC

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

Hi Gents,

 

I am newbie to the MCU world. I am a programmer in general but never had chance to play/work with microcontrollers but I was always interested in (deep inside my brain :) )  them.

 

As I am getting older, I got more free time (haha), so now I would like to play with MCUs a bit. I am mainly interested in projects where the MCU is connected with the PC, where the PC does something via the MCU (blinking LEDs, etc..) or the MCU sends back something to the PC (like the keyboards / controllers...) 

 

So I created a small learning project for myself, I would like to build a start lamp for my rFactor2 simulator game :) Ideally this thing is connected via USB to the PC.

 

This is what I did already:

- I bought an Arduino Micro, played with their IDE, solved my project... But thats not for me, I don't know what is happening :), so I want to go a bit deeper if possible

- so I bought an ATmega1284P plus an Atmel-ICE and successfully build (avr-gcc) and flash (avrdude) my first program using my Linux

 

I really enjoyed this, so I would go this way :)

 

So my questions are:

What are my possibilities if I want to connect my PC with the MCU ? Lets say I want to send characters as well in the future (showing them up in a display or control a 7 segment display etc..).

Is the USB the only way to do this ? Is that the right way forward ?

 

Lets say that USB will work for me:

Do I need to buy an MCU with built in USB right? Or can I buy an additional chip doing the USB part of the job ? I read about a CH... chip somewhere which does the USB part in Arduino.

 

Or should I buy a version which has USB support as well, like ATmega32U4 or AT90USB.... ?

 

If I buy them, do I still need to program the USB layer ? Or will it "just work" ? This is where LUFA comes into the picture ?

 

Could you guys drive me a bit ? I am a bit confused :)

 

Thanks,

Mitya

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

ZMitya wrote:
What are my possibilities if I want to connect my PC with the MCU ?

See: https://www.avrfreaks.net/comment... - it answers exactly that question!

 

 

EDIT

 

ZMitya wrote:
If I buy them, do I still need to program the USB layer ? Or will it "just work" ? This is where LUFA comes into the picture ?
 

Yes. No. Yes.

 

EDIT 2

 

Sorry - there were 3 questions.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Fri. Feb 23, 2018 - 02:29 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

ZMitya wrote:
If I buy them, do I still need to program the USB layer ? Or will it "just work" ? This is where LUFA comes into the picture ?
 

Yes. No. Yes.

 

 

Thank you very much...  I think I will do both U(S)ART and USB way... 

 

Which MCU is recommended for the USB way ?

 

AT90USB... is not in the current list of microchip.com .

Does that mean that it is not in production ?

 

Cheers,

Mitya

Last Edited: Fri. Feb 23, 2018 - 02:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ZMitya wrote:
Which MCU is recommended for the USB way ?

It must be one with the USB built in

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ZMitya wrote:
AT90USB... is not in the current list of microchip.com .
Really? I find that astonishing. But don't forget that the AVR-USB range (mega) stretches beyond the AT90USBxxx anyway. Things like mega16U2, mega16U4, mega32U4 are USB enabled models of mega AVR too. Also (if 3.3V is your thing) then just about any model of Xmega that has a U near the end (so things like atxmega128a1u) are chips that come with "free" USB too. So plenty to choose from there.

 

For the traditionalists (well OK "hobbyists") amongst us that just want an easy DIP package I would just go with mega48/88/168/328 (28 pin DIP) or mega164/324/644/1284 (40 pin DIP) and wire up a $2 USB-TTL from ebay to the TXD/RXD pins of its UART.

 

I guess this depends on whether you want something for a home/hobby project or something you plan to put into production and make 100,000 units of.

 

Of course if you are just looking for a mega328 and a USB-TTL all combined into a single, easy to use board it looks like this and costs about $5:

 

Image result for arduino

 

There are variants of that of course but the "basic model" (the one everyone uses and that is cheap because of economies of scale) is just a mega328 and an off the shelf USB-TTL chip solution. So you don't even need a "special cable" from ebay. You just plug a generic A-B cable into it and off you go. At the PC end it looks like a CDC-ACM interface (a COM port).

 

As Andy says it's coincidental that there are two threads today asking the same thing so keep an eye on that other one too to see how it develops.

 

(I'm now gonna look for AT90USB on Microchip -= even if they shelved things like AT90USB82 and AT90USB162 I would be astonished if that's true of the 647 and 1287 as they are some of the most useful chips Atmel made (because they are the only AVRs with OTG)).

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

So this is intriguing. If I use their parametric selector and just say "1 USB" it says:

 

but as noted in another thread just the other day the title of this selector is "New/Popular". If you scan the list of all AVRs it seems to be about 50..100 taken from the list of 300+ models of AVR. So they aren't listing all the AVRs to choose from. In that same thread the other day there was a link to a "better" parametric selector. Let me try that...

 

EDIT: OK form that thread (about Xmega popularity) the link Brian gave (the post marked as "solution") takes you to:

 

https://www.microchip.com/maps/m...

 

Selecting "1 USB" in that hits 34 devices and all the "old school" are there.

 

This is a very strange strategy from M'chip - to have their "main" search (the one you get to via products-micros list a radically reduced range of what's available ?!? Presumably they are angling to phase out the ones they don't list as "popular" ?

Last Edited: Fri. Feb 23, 2018 - 03:22 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

For the traditionalists (well OK "hobbyists") amongst us that just want an easy DIP package I would just go with mega48/88/168/328 (28 pin DIP) or mega164/324/644/1284 (40 pin DIP) and wire up a $2 USB-TTL from ebay to the TXD/RXD pins of its UART.

 

I would definitely prefer a DIP packaged one. I would like design it, solder it  if possible, so I am doing this only just for fun / learning ..  Both U(S)ART and the USB communication seems to be interesting for me at the moment :)

Once I could go through these learning phases, I will use the pre-built boards... 

 

clawson wrote:

As Andy says it's coincidental that there are two threads today asking the same thing so keep an eye on that other one too to see how it develops.

 

Will do :) When I started to write mine, the other was not there, but it took some time to finish, because I had a long call as well.

Sorry for that..

 

Thanks for your comments !

Last Edited: Fri. Feb 23, 2018 - 04:51 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

It must be one with the USB built in

 

Ok, thanks !

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

clawson wrote:

 

https://www.microchip.com/maps/m...

 

Selecting "1 USB" in that hits 34 devices and all the "old school" are there.

 

wow, thanks, good to know this...

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

ZMitya wrote:
.. Both U(S)ART and the USB communication seems to be interesting for me at the moment
Can you just confirm exactly what kind of "link" you want to make between PC and AVR. If it's just a simple "comms link" where you type "hello" at hte PC and the AVR then receives this then the simple/(best?) option is what's being discussed here. At the AVR end you just program the UART. But you connect the Transmit/Receive pins of the AVR UART to a UART to USVB converter of some sort. As far as the PC is concerned this is a "USB device" but it's not just any USB device, it's very specifically a "serial" USB device. In USB speak they call this CDC (Communication Device Class) and actually within that it is more specially a CDC-ACM device (ACM = Abstract Control Model). But if you wire up your AVR like this AVR->UART_2_USB_converter->PC then as far as the PC is concerned this thing can only ever be a CDC-ACM. That is the "burnt in" functionality of the UART_2_USB_converter chip that is used.

 

If you actually want AVR->all_sorts_of_USB_classes->PC then you really need a true USB Device interface as either found in chips like AT90USB (and the other 34 models they list) or a software simulation of it (which is what V-USB does). In this case the AVR could "appear" to the PC not just as a send/receive byte device (CDC-ACM) but as any of the USB Device classes:

 

(that table comes from http://microchipdeveloper.com/us... ). So the AVR isn't tied to 02h in that list but can "look" like a printer or a MIDI or HID (mice/keyboards etc) or Mas Storage or any of those others.

 

But if the goal is just to get "hello" from the PC to AVR (and back) then CDC-ACM is the easy option and especially if done with a dedicated chip (about $1 of what you are paying for in a $2 USB-TTL cable).

 

BTW the chips that do USB-TTL (FTDI, Prolific, Silabs, NXP etc - see https://www.avrfreaks.net/forum/f... ) can also be bought and laid down in your own design. But most folks just have 2 or 3 of the cables from ebay and just use the chips that are "inline" in those. (for one off / hobby projects anyway). With one of the cables you have a USB plug that goes into your PC at one end and four wires (usually) that go to Vcc, Gnd, TXD, RXD on the AVR at the other end. They usually terminate in those 0.1" pin sockets so if your board has header pins near Vcc, Gnd, TXD, RXD the cable easily plugs onto those signals. For example....

 

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

Hi clawson,

 

For this start light project I will go for the UART connection I think. I just want to try it and the communication is so simple in this case. I just need to send over a byte, the MCU can decide which LED should be turned on/off.

After that, I will have an other small learning project which will be a panel with ~10 buttons + maybe a few analog inputs. I would like to get that act as a game controller.

 

As I could understand from your post, there I will need to get a real USB device. As you guys said there I might need the LUFA library as well, so that will be interesting again :)

 

Can't wait to get it done I am so excited these days (like a kid :) )

 

Really appreciate your help.

 

Thanks,

Mitya

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

LUFA is not what I'd call "first project" software. You'll have a much easier start using a USB-TTL.