GithubHelp home page GithubHelp logo

ramizpolic / serial-atmega Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 1.0 41 KB

Serial communication with Atmega328p/Arduino Uno

C 81.60% Makefile 18.40%
serial-communication atmega328 interrupts usart atmel

serial-atmega's Introduction

AVR USART

Implements bidirectional serial communication via USART, and allows the data packages to be stored internally into non-volatile memory such as EEPROM. It supports all the basic AVR microcontrollers, but is mainly designed to work with Atmega128 and Atmega328/P.

References

Requirements

Board

  • Interrupts
  • USART Interface
  • EEPROM

Softwares and libraries

Configuration

Make sure to update the following data in order to make the program work with the other boards.

#define F_CPU           16000000    // clock speed
#define USART_BAUDRATE  9600        // baudrate
#define RX_BUFFER_SIZE  512         // buffer size
#define RX_LINE_SIZE    128         // word size

UCSR0C|=(1<<UCSZ01)|(1<<UCSZ01);  // no parity, 1 stop bit, 8-bit data

Build

On Windows

  • Clone repository
  • Open Atmel Studio 7.0
  • New Atmel project
  • Import main.c
  • Build project
  • Launch from project path
    avrdude -C "/path/to/avrdude.conf" -p atmega328p -c arduino -P {PORT} \
    -b 115200 -U flash:w:"$(ProjectDir)Debug\$(TargetName).hex":i 
    
  • Open and configure realterm
  • Start communication

On Linux

# install required packages
$ sudo apt install avrdude gcc-avr gcc gcc-multilib g++-multilib avr-libc gcc-avr

# open Makefile and configure data
$ nano Makefile

# build and flash
$ git clone https://github.com/fhivemind/serial-atmega.git
$ make
$ make flash

Demo

Once the program has been successfully flashed onto the controller, and the serial port opened, we can initiate the communication. When opening the realterm (or any other serial monitor), after properly configuring it first, you should see following:

Commands: 
 '/save' - save all results sent via UART to EEPROM
 '/load' - load saved results from EEPROM
 '/all' - show buffer data 
 '{DATA}' - send data

Tests

We will send following data in packages (\n indicates end of transmission):

hello world\n, Oh, hi Mark\n, all\n, save\n, load\n

And obtain the result as:

# input 1
-> input: hello world
# input 2
-> input: Oh, hi Mark
# command '/all'
-> all results: 
-> hello world
-> Oh, hi Mark
# command '/save'
-> Data saved to EEPROM.
-> ----- DATA -----
-> hello world
-> Oh, hi Mark
-> ----------------
# command '/load'
-> Data loaded from EEPROM.
-> ----- DATA -----
-> hello world
-> Oh, hi Mark
-> ----------------

Author: Ramiz Polic

serial-atmega's People

Contributors

ramizpolic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

j-p-f-f

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.