UART USB APPLE

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

I need some help with UART communication problem. I bought SparkFun's Breakout Board for FT232RL USB to Serial and Logic Level Converter. I've set them up with an ATMega32 to communicate to my Apple. I use the 'screen' command in Terminal to communicate to the FT232RL board. I successfully preformed an echo test, shorting Rx and Tx at the furthest part in the hardware. So the hardware is functioning. When I connect my ATMega32, programmed with the code below, nothing comes up on the terminal screen, not even scrabbled characters. The Rx LED on the FT232RL board does blink at what appear to be 100 milliseconds and whenever I type the Tx LED on the board also lights up. I can't seem to find out what is happening, I think it is probably a timing error or the 'screen' function's arguments are incorrect. Could someone help me, or at least shed some light on this problem so that I might be able to solve it?

#define F_CPU 16000000
#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

#include 
#include 

int main (void) 
{
	DDRD = 0b00000010;
	UBRRL = BAUD_PRESCALE;
	UBRRH = (BAUD_PRESCALE >> 8);
	UCSRB |= (1 << RXEN) | (1 << TXEN); 
	UCSRC |= (1 << UCSZ0)| (1<<UCSZ1);
	
	while(1)
	{
		_delay_ms(100);
		while ((UCSRA & (1 << UDRE)) == 0); 
		UDR = 'H';
	}
}

Command in Terminal prompt:

screen /dev/tty.usbserial-A700eXoR 9600 8n1

Life Is Like A Bucket Of Chicken.

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

My money is on this:

#define F_CPU 16000000 

not reflecting reality. As you are trying for 9600 I'd transmit a sequence of "UUUUUUU..." and probe for a 104us bit width

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

The most advance piece of test-ware I have is a multimeter. So, debugging for me is close to just guessing. So, I can't run this test. I am running the ATMega32 with a 16 MHz crystal, and I am fairly sure I have the right fuses set. Could there possibly be something else going wrong here; or, maybe I am not understanding something happening with F_CPU?

Life Is Like A Bucket Of Chicken.

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

At least wire up an LED, write a program to flash it at 0.1Hz based on the assumption of a 16MHz clock. Run the program - does the LED come on for 5s and then go off for 5s (easily measured with your watch). This should help to confirm that the chip is clocking as you think. (if it happens to be 1MHz rather than 16MHz the LED on/off periods will be 80s so be patient waiting to see it change state!

BTW in the above you don't mention an inverter on TXD/RXD? Normally you'd employ a MAX232 but as you are using a USB-RS232 they usually use TTL on the UART facing side so MAX232 level conversion is not required but TXD/RXD inversion (the other function of a MAX232) is.

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

clawson wrote:

BTW in the above you don't mention an inverter on TXD/RXD? Normally you'd employ a MAX232 but as you are using a USB-RS232 they usually use TTL on the UART facing side so MAX232 level conversion is not required but TXD/RXD inversion (the other function of a MAX232) is.

Hmmm .... As i read it it doesn't need the inverter , when connecting to a MCU pin , on the FTDI "uart" side.

See pg.26.
http://www.acroname.com/robotics...

You would normally only need to invert when using a "non inverting unit .. ie. no Max232" in one end (MCU) , and an "inverting Max232" in the other end (ie. PC with a Max232 build in).

Edit: I'd use

#define F_CPU 16000000UL

And blink a led as Cliff suggested , just to verify that you
are running 16Mhz

Edit2:
As you are running 16Mhz i assume your VCC is 5v.
Did you modify the USB board
http://www.sparkfun.com/commerce...

to output 5v ?

http://forum.sparkfun.com/viewto...

/Bingo

Last Edited: Mon. Aug 16, 2010 - 04:42 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bingo,

I've been reading FT232R datasheets recently. Their suggested circuit for a USB-RS232 converter cable even includes a MAX232 in the design. It will invert so if they are inverting already that would be a double inversion?

Cliff

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

Cliff

The USB-RS232 converter ref design is on pg. 23.

And the reason you'd need the Max232 (well inverter there) is :
That the PC or serial device , also have a Max232 that inverts ....
As you mention above ...

Max232 on PC = Inversion
Max232 on FDTI = Inversion

Inversion -> Inversion = No Inversion

So the uarts aren't inverting at all , but the Max232 does , and one in both ends means "No inversion" seen by the uarts. But it's still inverted when traveling through the cable.

Edit:
I mean ...
The signal is non inverted on the uarts. But is inverted by the (RS232 aka V24) driver , when making it into +/- 12 v on the "RS232 Cable".

/Bingo

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

Ah right, I get it - so if there's no actual RS232 involved you don't need the MAX232's:

Attachment(s): 

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

Thats right

It's the RS232/V24 standard that specifies inversion , and it's made in the drivers.

I think it is the way Mark/Space was defined on old Teletype terms , that dictated this inversion.

/Bingo

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

I hooked up a two pin bi-polar LED(green and red) to pins 2 and 3 of PORT D. With the code below, the LED turns red for two seconds and green for another two seconds for a total of 4 second cycle. So, the ATMega32 is clocked and running at 16MHz, but the uart still isn't working. I don't understand?

#define F_CPU 1600000UL

#include 

int main (void) 
{
	DDRD = 0b11111111;
	TCCR1B |= (1 << CS10) | (1 << CS12);
	
	while(1)
	{
		if (TCNT1 >= 31250)
		{
			PORTD = 0b00000100;
		}
		if (TCNT1 >= 62500)
		{
			PORTD = 0b00001000;
			TCNT1 = 0;
		}
	}
}

Life Is Like A Bucket Of Chicken.

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

Bingo,

I was thinking about this some more and surely a true USB-RS232 cable has both an FTDI and a MAX232 so the situation is going to be this isn't it? ...

Attachment(s): 

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

Bingo600 wrote:
Edit2:
As you are running 16Mhz i assume your VCC is 5v.
Did you modify the USB board
http://www.sparkfun.com/commerce...

to output 5v ?

http://forum.sparkfun.com/viewto...

/Bingo

I did not modify the board but I am running the UART though SF's logic converter:
http://www.sparkfun.com/commerce/product_info.php?products_id=8745

I did the echo test through the converter though. So I think that part is working.

Life Is Like A Bucket Of Chicken.

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

clawson wrote:
Bingo,

I was thinking about this some more and surely a true USB-RS232 cable has both an FTDI and a MAX232 so the situation is going to be this isn't it? ...

@Cliff

Yes i's expect a USB-RS232 converter to contain inverting RS232 drivers.
So that setup would prob "kill your AVR" , as the Max232 would output (inverted) +/- 12v to your avr pins.

Edit:
But the SF USB board doesn't contain a Max232 , it has TTL output (3v/5v selectable) directly from the FTDI chip.

/Bingo

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

Taco_Bell wrote:

I did the echo test through the converter though. So I think that part is working.

Well i'd expect the converter's rx/tx levels to be equal , meaning that you have verified that there is comming bits through , is the level suitable for a 5v avr ?

/Bingo

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

I tested the logic converter. On the AVR side of converter the voltage is 5VDC and on other side, USB side, the voltage is 3VDC.

Is the talk about the USB to RS232 converter people seem to be building relevant to me?

Life Is Like A Bucket Of Chicken.

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

Taco_Bell wrote:

Is the talk about the USB to RS232 converter people seem to be building relevant to me?

Well in the beginning it was , but it took a "driver twist".

So i guess : Not anymore

/Bingo

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

I probably should have added this in the beginning. I was able the to get a GPS working with the USB board. I used the same 'screen' command as in the original post.
http://www.cutedigi.com/product_info.php?cPath=248&products_id=4289&osCsid=1fd397629731ce1b31f69a715ad648f9

Also, does anyone think modifying the USB board for 5VDC(removing the logic level converter from the equation) would increase the odds of getting the communication to work?
http://forum.sparkfun.com/viewtopic.php?f=15&t=21234

Life Is Like A Bucket Of Chicken.

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

You really need the I/O logic level of the FT232 to be the same as the micro's Vcc.

I seem to remember that there is a terminal on the FT232 that you can connect to the local Vcc so that the two logic levels will be the same. There is a schematic in the FT232 spec sheet that shows how to do this.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

To connect a USB terminal to an avr with the FTDI you DON'T need no stinking MAX232. Example, PC USB(running hyper term) to FTDI chip to usart on AVR works! BUT watch what RX and TX means at both ends. Does the RX on the FTDI mean "connect rx from avr here" (OUTPUT) or "I receive here" (INPUT)? On the AVR it's the latter. Similar logic for pins labeled TX.

Also make sure on PC side to set the baud rate (of the FTDI via the PC-USB driver) to the same as on the AVR. Use AVRcalc to get the baud parameters right!