jkeating
Posts: 11
Joined: Thu Aug 01, 2013 5:05 am

ATMega328p & UART

Wed Sep 18, 2013 3:50 am

I'm working on a project with a GPS device that communicates over UART. I have sucessfully conntected the GPS device directly to RPI uart and was able to read GPS data. I have now connected the GPS to the atemega on the gertboard. The RX pin of the atmega goes to the tx pin of the GPS. The tx pin of the atmega goes to the rx of the RPI.

What I'm trying to set up is a very basic test where the atmega reads data from the gps and sends it to the RPI. I'm using minicom on the rpi to see output. I'm using peter fluery's libarary for UART on the atmega. No matter what settings I try for baud all i see in my minicom window on the PI is garbage characters. I know data is being sent sucessfully, however it appears baud is not set correctly.

What clock speed does the atmega on the gertboard run at? Based on the fuse readings I've done high is 0xd9 and low is 0xe7 which means its using an external full swing crystal from what I have found. I'm still kinda new to clocking and oscialltion so I'm wondering what i need to set my F_CPU to in order to get correct data.

As a debugging measure I've even put a _delay_ms(30000) after the intial uart_puts("blah blah"); first line in peter's library. I see garbage characters, then 30s delay, then it starts sending all the data from the GPS, again, all garbage chars. So I know its communicating correctly just my baud/clock is not set correctly.

Any help is greatly appreciated.

Thanks,

bprats99
Posts: 30
Joined: Thu Apr 04, 2013 4:54 am
Location: Southern California USA

Re: ATMega328p & UART

Wed Sep 18, 2013 4:38 am

Check if the ATMega library is set for normal or inverted TTL serial logic. If your GPS worked with the Pi serial console directly it is apparently 3.3 volt TTL serial, the mark/space polarity is the opposite of normal RS-232. The ATMega library command might be looking for the opposite polarity. This is a situation I have found using various serial displays, PICAXE BASIC allows normal or inverted serial so I assume the Arduino library has the same programming feature.

If that isn't the answer then output from minicom and scope the duration of the bits and compare to the gps output, same baud rate of course. Most GPS I have worked with are 4800 baud. Good luck ...

jkeating
Posts: 11
Joined: Thu Aug 01, 2013 5:05 am

Re: ATMega328p & UART

Wed Sep 18, 2013 4:48 am

Any tips on what to look for as far as polarity in the library? Meaning I'm unfamiliar with serial polarity, what would setting it look like?

bprats99
Posts: 30
Joined: Thu Apr 04, 2013 4:54 am
Location: Southern California USA

Re: ATMega328p & UART

Wed Sep 18, 2013 11:11 pm

It would be an option in the serial out/print command. Refer to the command detail, something like 'normal' or 'inverted'. Sounds like a scope is your best bet right now.

User avatar
Gert van Loo
Posts: 2487
Joined: Tue Aug 02, 2011 7:27 am
Contact: Website

Re: ATMega328p & UART

Thu Sep 19, 2013 11:42 am

The input pins on the Atmega and the Pi chip have the same polarity!
I have sucessfully conntected the GPS device directly to RPI uart
It your GPS system works when you connect it directly to the GPIO pins of the PI
it is likely to be a format or baud problem.
I vaguely remember always having a factor-2 error when using the baudtables in the Atmega datasheet.

Return to “HATs and other add-ons”