Problem with using UART with multiple different FTDI cables but not with 16U2

Hi,

I am trying to view the output from an UNO in a terminal window from pins 0 & 1 connected to an FTDI cable.

When connected to the FTDI cable I essentially get garbage displayed in the Terminal window, now if I change the COM port to the UNO which is connected with the MEGA16U2 I see exactly what I want to see. I am not sure exactly what I am messing up right now.

I have Pin 0 (RX) connected to the TX line on the FTDI adapter.
I have Pin 1 (TX) connected to the RX line on the FTDI adapter.
I have the ground from the adapter tied to the ground from the UNO.

I have used 2 different cables.

I have attached the code below.

//Variables
unsigned long ULtime = 0;
unsigned long ULtemp = 0;
unsigned long ULcounts = 0;
unsigned int tovf1 = 0;



ISR(TIMER1_OVF_vect)
{
  tovf1++;
}

void setup() {
  
  //Set the UART baud rate to 9600/
  Serial.begin(9600);
  

  //Set pin PD3 as an input.
  pinMode(5, INPUT);

  //Set the counter
  TCCR1A = 0;
  TCCR1B = (1<<CS12) | (1<<CS11) | (1<<CS10);
  //Fclk_io is 16MHz
  TIMSK1 = (1<<TOIE1);

  //Storing the runtime of the MCU into ULtime.
  ULtime = millis();


}

void loop() {

  //after every 1 second, send out the number of counts then clear out the counter.
 if ((millis() - ULtime) >= 1000)
 {

  ULcounts = (TCNT1H<<8)|TCNT1L;
  ULcounts = (TCNT1H<<8)|TCNT1L;
  
  if (ULcounts > 40000000)
    ULcounts -= 4294900000;

  ULtemp = 65536*(unsigned long)tovf1;
  ULcounts += ULtemp;
  
  Serial.print(ULcounts);
  Serial.print("\r");
  ULtime = millis();

  //Reset counter variables
  TCNT1H = 0;
  TCNT1L = 0;
  tovf1 = 0;
 }

}

tovf1 is used in the interrupt service routine and in loop(), but is not volatile. Why isn't it?

What happens if an interrupt happens while tovf1 is being accessed in loop()? You will get the wrong value. tovf1 needs to be copied, and reset, while interrupts are disabled.

  if (ULcounts > 40000000)
    ULcounts -= 4294900000;

I would expect both of those magic numbers to have the same number of digits. Why don't they? Why are they not named constants, where the name might actually tell us something?

slowertech:
I am trying to view the output from an UNO in a terminal window from pins 0 & 1 connected to an FTDI cable.

When connected to the FTDI cable I essentially get garbage displayed in the Terminal window, now if I change the COM port to the UNO which is connected with the MEGA16U2 I see exactly what I want to see. I am not sure exactly what I am messing up right now.

Sorry, but I can't make sense of that.

The first part sounds like you have an FTDI cable connected to pins 0 and 1 on an Uno. But you don't say whether the Unos regular USB connection is also connected to a PC. If it is there is probably conflict between the two.

I have no idea what the second part means - are you referring to a different Arduino board with a 16U2 MCU rather than an Atmega 328? If so, please post a link to the board datasheet. If not, please explain in more detail.

On the Arduinos with a 32U4 MCU (Leonardo and Micro) Pins 0 and 1 are connected to a separate UART and are not used when the regular USB cable talks to a PC.

...R

I apologize for that, I did not do a good job explaining.

I only have 1 UNO that I am using right now.

The UNO itself was also connected to the PC. I disconnected the USB cable attached to it and have it powered from a bench top power supply. Unfortunately I still have the same issue.

I removed the Atmega 328 from the board and threw on a 16 MHz crystal with the caps and still have the issue.

slowertech:
I apologize for that, I did not do a good job explaining.

I only have 1 UNO that I am using right now.

The UNO itself was also connected to the PC. I disconnected the USB cable attached to it and have it powered from a bench top power supply. Unfortunately I still have the same issue.

I removed the Atmega 328 from the board and threw on a 16 MHz crystal with the caps and still have the issue.

It is still not very clear.

Where did you "throw" the stuff?

Are you trying to tell us that you have taken the Atmega 328 from the Uno and installed it on a breadboard using a 16MHz crystal etc to provide a clock signal?

I have never tried a breadboard Atmega328 at 16MHz - I always use the internal 8Mhz clock - but I have never had a problem communicating with mine using an FTDI cable.

Please make a pencil drawing showing how you have everything connected and post a photo of the drawing. It will eliminate the confusion.

...R

I have attached an image of the circuit.

Thank you.

Image from Reply #5 so we don’t have to download it. See this Image Guide

f90a27c03ed118c93a5758f22769d74fc2ed1ef9.png

…R

You did not say where the Atmega 328 is located.

And the DIP Atmega 328s don’t have Vcc on pins 4 and 6 etc etc.

And I thought the whole purpose of your question depends on what is connected to the DB9 connector - which is not shown.

I suspect that is a diagram you found somewhere rather than a drawing you made yourself of your own system. Don’t worry if you are not good at drawing - just do your best with a pencil and paper.

…R

Oh snap! Sorry that is my fault.
I just quickly grabbed that from something I had made in DipTrace, that is the TQFP package.
I can doodle it as soon as I get a chance.

I have 1 328P in a breadboard now and 1 328P on the UNO board.

They both are wired up to their own female DB9 which is connected to the correlating pins on the FTDI USB serial adapter.

I have 2 adapters and checked them by connecting the RX/TX together and sending something over terminal to be read back out over terminal with no problems.

slowertech:
They both are wired up to their own female DB9 which is connected to the correlating pins on the FTDI USB serial adapter.

When you mention DB9 and “FTDI USB serial” I wonder do you mean USB-RS232 or USB-TTL. The latter is what you need for an Arduino and I have not seen one with a DB9 connector. RS232 signal levels may damage an Arduino or Atmega 328.

…R

Well, this is embarrassing but that was my problem.

I found an an FTDI board I had stashed and it works fine.
The 2 cables I was attempting to use are RS232 to USB.

Thank you very much.

Thanks for the feedback. Glad to hear you have it working.

...R