Comunication rs232 between atmega328p and computer

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

Hi to all

I have to communicate my atemega328p with my computer using the rs232 protocol and... I don't know how to do it. 
If any of you know something about this work, please, tell Where do i have to start? or How do i have to start?
Regards,
Joseph Peña

Joseph Peña,
Student of Electrical Engineering

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

Hello Joseph.

 

Firstly, RS232 defines the engineering aspects of serial communications; voltage levels, etc.... but cannot be called a protocol (which defines the language aspects, eg what the bits represent in the transfer of information between devices).

 

At the PC end of a serial link you could use one of the many free terminal software eg Bray's Terminal. This allows you to send and receive messages to/from your atmega328. Eventually you may write your own software to process the messages sent by your ATMega328.

 

However, the PC's hardware (if you have a true RS232 facility) will expect the signal to swing between + and - 12 volts (or a little lower voltage for laptops). For this you will need a converter chip between your ATMega328 and the cable to the PC. A commonly used chip is the MAX232. However you could also assemble a (roughly) equivalent with a couple of transistors and Rs & Cs. (one example is in this article http://www.uchobby.com/index.php... )

 

In your reading you will come across the term "baud" which broadly means the speed of data transfer. For success both ends of the serial cable must operate at the same baud rate. So your ATMega328 must operate at the same baud rate as the software on the PC. If you use Bray's Terminal software you can easily adjust the baud rate and other transfer parameters (bits, parity, stop bits).

 

That might get you started in your reading/study.

 

Cheers,

 

Ross

 

Ross McKenzie ValuSoft Melbourne Australia

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

Hello, Ross
Thank you very much.
 

Joseph Peña,
Student of Electrical Engineering

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

valusoft wrote:
However you could also assemble a (roughly) equivalent with a couple of transistors and Rs & Cs. (one example is in this article ...
Another example is the AVR Butterfly :

AVR Butterfly Evaluation Kit

User Guide

http://ww1.microchip.com/downloads/en/devicedoc/doc4271.pdf

(page 36 for the RS232 schematic)

Though not to RS232 levels the AVR Butterfly should be functional with a short cable from the PC.

valusoft wrote:
So your ATMega328 must operate at the same baud rate as the software on the PC.
There appear to be some threads here on autobaud (Automatic Baud rate detection)

Another concern is AVR clock error; how to calibrate the AVR's RC clock given UART SOF (Start Of Frame) :

Microchip Technology Inc

Microchip

AN_2563

http://www.microchip.com//wwwAppNotes/AppNotes.aspx?appnote=en591004

AVR054: Run-time calibration of the internal RC oscillator via the UART

...

(AVR054 source code is missing)

For AVR054 source code :

http://www.atmel.com/products/microcontrollers/avr/default.aspx?tab=documents

(Document Type pull-down menu, Application Notes)

...

 

AVR054: Run-time calibration of the internal RC oscillator via the UART

AVR054: Run-time calibration of the internal RC oscillator via the UART

AVR054: Run-time calibration of the internal RC oscillator via the UART
(file size: 167781, 17 pages, revision C, updated: 04/2008)

This application note describes how to calibrate the internal RC oscillator via the UART. In the method used a slave node is synchronized to a master node at the beginning of every message frame.

...

 

"Dare to be naïve." - Buckminster Fuller

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

Joseph.Pena wrote:

I have to communicate my atemega328p with my computer using the rs232 protocol and... I don't know how to do it. 

 

As mentioned above, RS232 refers to specific voltage levels used for serial communications.

Now a days it is more common to use a USB to TTL Serial Adapter (something like this) to

connect a uC to a PC.  With logic level inputs and outputs you don't need the RS232 level shifter.

(Connect the Tx on the adapter to Rx on the uC, and Rx on the adapter to Tx on the uC.)

 

The USART in the uC is used for serial communications.

Dean Camera (abcminiuser) wrote two tutorials on using the USART:

   Using the USART in AVR-GCC and Interrupt Driven USART in AVR-GCC, both can be found here.

 

This should get you started.

 

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

If this is simply about linking a 328 and a PC then simply get one of these:

 

https://www.ebay.co.uk/sch/i.htm...

 

(for more just search "usb ttl" in your local version of ebay).

 

This cable plugs into your PC USB at one end and will appear to be a "COM port" that can be accessed from any standard terminal program. At the PC end the two active signal wires just connect to the TXD and RXD pins of the 328 (you also connect power)

 

This makes an end-to-end serial connection with nothing else involved.

 

What this will not be doing is using RS232. As others have said it is simply a form of +12V/-12V signalling - to use that with an AVR you would need a device that converts the 328 TXD/RXD from 0/%V (or maybe 0/3.3V) into this +12/-12 signalling then at the "other end" (which may actually be very close to the AVR in fact) a second device would be involved to convert back down from +12/-12 to USB level signals. That is the way it used to be done and the device you put close to the AVR was a MAX232. Then some bright spark noticed that if you dropped the MAX232 from the AVR end you could also drop the one in the USb cable and simply make one of those $2 cables I just linked to - so that's the way we all connect AVRs to PCs these days.

 

Has someone really told you that it MUST be RS232 level signals?