Solved: USB communication issue

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

Hello everyone!

 

This may be more of a general AVR issue than Arduino, but I'm using an Arduino in the process, so I posted here.

 

I am working on a project that involves two separate ATmega328s with grbl firmware, controlled by a host ATmega164. I am building a custom machine that has six stepper motors (hence the two grbl setups) and various other chores that the host (ATmega164) monitors. The host sends g-code to each ATmega328 (grbl) using its two USARTs. This is all on a custom PCB (not an Arduino).

 

Grbl has parameters that are configured via USB and Universal G-code Sender (or similar). To connect to USB with my custom PCB, I provided access to the RXD and TXD pins of each ATmega328.

 

From the Arduino schematic, the only connection between the ATmega328 and the ATmega16U2 (USB) are the TXD and RXD lines. So my approach seems workable.

 

My idea is to remove the ATmega328 from an Arduino and connect the RXD and TXD lines from the Arduino to their counterparts on my custom PCB. Thus substituting the ATmega328 on my PCB for the one on the Arduino. That way I can use the USB circuitry from the Arduino to talk to the ATmega328 on my PCB.

 

BUT... I can't get it to work.

 

With the Arduino fully intact (ATmega328 installed) I get communication with Universal G-code Sender as I should. But after removing the ATmega328 and connecting to the RXD and TXD of the ATmega328 on my custom PCB, I get nothing. The RX or TX LED on the Arduino flashes once very quickly, then nothing.

 

I have triple checked the connection of RXD an TXD and even swapped them. Still nothing. The RXD and TXD connect to only one ATmega328 so there is no confusion (I confirmed with a meter). The firmware in the Arduino is the same hex file as the ATmega328 on my PCB, and both were uploaded with AVRISP mkII.

 

QUESTION:

 

Is my approach flawed? Or am I missing something?

 

THANKS in advance!

 

Cris

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. Antoine de Saint-Exupery (1900 - 1944)

Last Edited: Fri. Dec 8, 2017 - 12:05 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Did you remember to connect a common Ground connection between the various boards?

 

JC

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

Doc,

 

Yes, power and ground are supplied by the Arduino.

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. Antoine de Saint-Exupery (1900 - 1944)

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

So, does the custom PCB have an Xtal, and is it running at the same clock frequency as the original Arduino?

The USB chip, obviously, needs to be receiving data at the same baud rate as from the original micro.

 

Does the custom PCB have all of the Vcc and AVcc pins powered, and all of the Grounds connected to Ground, and a by-pass cap, (typ 0.1 uF), across each pair of power pins?

 

Does the Arduino USB board still enumerate correctly on the PCB when you plug it in, without its own micro?

 

JC

 

 

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

When you move the 328 to the custom board what is the crystal frequency on the custom board?  And what is the power supply voltage? 

 

THe Arduino uses 16MHZ for the Crystal and 5v for Vcc

 

JIm

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

Last Edited: Thu. Dec 7, 2017 - 06:50 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Arduino USB chip (ATmega16U2) has a 16mHz xtal and the custom PCB has 16mHz xtal.

 

All appropriate pins powered and grounded. Your comment pointed to a bypass cap on AVcc I forgot to populate - THANKS! I will do that but doubt it will solve the problem. I had previously tested the ATmega328s on my PCB with a "blink" program and was successful.

 

When connecting to the Arduino with the ATmega328 removed, Unerversal G-code Sender reports:

 

"**** Connected to COMM 4 @ 115200 baud ****".

 

This points to an error in my description of the symptoms. Above, I said I get nothing, but I DO GET a report that it is connected.

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. Antoine de Saint-Exupery (1900 - 1944)

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

aeroHAWK wrote:
When connecting to the Arduino with the ATmega328 removed, Unerversal G-code Sender reports:   "**** Connected to COMM 4 @ 115200 baud ****".   This points to an error in my description of the symptoms. Above, I said I get nothing, but I DO GET a report that it is connected.

Thats because the USB chip on the Arduino board is responding...

 

What baud rate do you have the USART in the MEga164 set at?  I do not know off the top of my head what the speed of the 328 is on the Arduino

 

Jim

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

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

Jim,

 

115200 is the default baud rate.

 

The same firmware is used in both chips. When I just talk to the Arduino, communication works correctly and I can access grbl's parameter table. But when I remove the ATmega328 from the Arduino and connect RXD and TXD to the ATmega328 on my custom PCB, I get the comment that it is connected, but no access to the parameters.

 

FYI - The Arduino board provides power and ground.

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. Antoine de Saint-Exupery (1900 - 1944)

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

Okay, I have new data.

 

Instead of trying this with my custom PCB and an Arduino, I thought I'd try it with TWO Arduinos.

 

I removed the ATmega328 from the Arduino connected with USB and with jumpers, I connected another Arduino (with ATmega328 installed) to +5v, GND, RX, and TX.

 

When I connected to USB, I got: "**** Connected to COMM 4 @ 115200 baud ****". But no access to grbl's parameters.

 

Then I tried the same thing - BUT, bent the RXD and TXD pins to the side, so they were NOT connected to the rest of the Arduino.

 

When I jumpered the RXD and TXD of the two Arduinos, it worked as expected. I could get access to the parameter table.

 

So, this demonstrates my thought process is valid, but my execution is suspect. I need to find what is causing conflict. Somewhere I may not have isolated the RXD and TXD....

 

P.S. Doc, I added the bypass caps that I forgot on AVcc and no change.

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. Antoine de Saint-Exupery (1900 - 1944)

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

If There is anything added to the lines then you risk two outputs connected together and fighting each others output stage.  I was under the impression that everything was isolated.

 

My suggestion is that you draw a schematic of your connections...hand drawn and photographed is fine and post it here.  Also compare your connections on paper with real life and see if you see an anomaly somewhere

 

JIm

 

If you want a career with a known path - become an undertaker. Dead people don't sue! - Kartman

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB user

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

With power off, use multi-meter to verify continuity tx to rx1, and tx1 to rx. Also verify isolation rx to tx ... Use chip pins.

It all starts with a mental vision.

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

I can't visualize your configuration from the description.   There is a mega164 and an Arduino involved.  There is a software program called grbl (another really helpful program name from the software crew) that sends commands that operate stepper motors on a CNC machine.  The Arduino (are there two of them? One for each set of three X_Y_Z axis stepper motors?) runs the grbl application. Does the Arduino expect to receive grbl commands through USB (usually from a PC)?    Do you wish to have the mega164 connected to the PC using USB?  Or will the mega164 be sending grbl commands to each Arduino?  If that is the case, then the mega164 can send binary data to each Arduino directly from the mega164's UART ports to each Arduino's USART.  Perhaps the grbl can be configured to accept data from a software serial port running on the host Arduino.  That way the main USART on the Arduino can be used only for programming and connecting to the Arduino IDE on the PC and the software serial port can be connected to the mega164.  The SoftwareSerial library included with the Arduino distribution works up to 115200 baud.

 

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

jgmdesign wrote:
If There is anything added to the lines then you risk two outputs connected together and fighting each others output stage.  I was under the impression that everything was isolated.

Jim,

 

I believe everything is isolated. I have a DPDT switch for the sole purpose of isolating the RXD and TXD for testing.

 

I have a schematic, but it is complex and has a lot of other distracting circuits. I will be pouring over it to see if I missed something.

KitCarlson wrote:
With power off, use multi-meter to verify continuity tx to rx1, and tx1 to rx. Also verify isolation rx to tx ... Use chip pins.

Kit,

 

I've already done that, and I'm going to do it again to be sure.

Simonetta wrote:
I can't visualize your configuration from the description.

 

Here is a diagram:

 

Each ATmega328 has firmware called "grbl" that is intended to control 3 stepper motors with g-code commands (I didn't include the motors in my diagram). G-code is ascii and is sent from the host to the ATmega328.

 

I am separating the systems so I can test each individually. The ONLY reason for the Arduino is to steal the ATmega16U2 and connect to a laptop to test the communication and to setup the grbl parameters (steps/mm, etc.).

 

Cris

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. Antoine de Saint-Exupery (1900 - 1944)

Last Edited: Thu. Dec 7, 2017 - 10:44 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Is it not a case of rx/tx swapped from the arduino?
Get yourself a Salaea Logic or clone. The clones are the cost of a MacMeal. It will save you far in excess of that.

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

Kartman,

 

If I'm essentially replacing the existing ATmaga328 that is on the Arduino, with the chip that in on my PCB, they shouldn't be swapped. Anyways, I tried it both ways.

 

I'll look at the Saleae Logic...

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. Antoine de Saint-Exupery (1900 - 1944)

Last Edited: Thu. Dec 7, 2017 - 10:49 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

SOLVED ! ! !

 

It's the FUSES!

 

I thought I selected the proper option for a 16 mHz xtal, but I forgot to click on PROGRAM !

 

Then it STILL didn't work. But I noticed a check mark next to divide by 8. Once I unchecked it... SUCCESS ! ! !

 

Thank you to all that made suggestions!

 

Sometimes I feel really stupid....

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. Antoine de Saint-Exupery (1900 - 1944)