The Arduino Platform A “development module”

Slides:



Advertisements
Similar presentations
INPUT-OUTPUT ORGANIZATION
Advertisements

Serial Communications Interface (SCI) Michael LennardZachary PetersBao Nguyen.
Anurag Dwivedi Rudra Pratap Suman. Scope of Communica tion Telephones and Cell Phones.
Serial I/O - Programmable Communication Interface
Serial Interfaces, Part Deux -I 2 C and SPI December 4, 2002 Presented by Eugene Ho.
SPI Serial Peripheral Interface. SPI Serial Peripheral Interface is communication between two devices, one bit at a time sequential one bit at time over.
Lecture 8: Serial Interfaces
Hierarchy of I/O Control Devices
COMP3221: Microprocessors and Embedded Systems Lecture 22: Serial Input/Output (II) Lecturer: Hui Wu Session 1, 2005.
Better Debugging of Embedded via a Debug Port ECE152.
Serial Communication Buses: I 2 C and SPI By Brody Dunn.
Better Debugging of Embedded via a Debug Port ECE152.
USARTS CS423 Dick Steflik. USART ● Universal Synchronous Asynchronous Receiver Transmitter ● used to send and receive small packets over a serial line.
Serial Peripheral Interface (SPI)
USART and Asynchrono us Communica tion The USART is used for synchronous and asynchronous serial communication. USART = Universal Synchronous/Asynchronous.
7-1 Digital Serial Input/Output Two basic approaches  Synchronous shared common clock signal all devices synchronised with the shared clock signal data.
Aztec PC Oscilloscope Michael Mason Jed Brown Josh Price Andrew Youngs.
Input/Output and Communication
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 13.
INPUT-OUTPUT ORGANIZATION
1 EECS 373 Design of Microprocessor-Based Systems Prabal Dutta University of Michigan Lecture 10: Serial buses Oct 6, 2011.
Serial Peripheral Interface (SPI) Bus. SPI Bus There is no official specification for the SPI bus. It is necessary to consult the data sheets of the devices.
Serial Peripheral Interface Module MTT M SERIAL PERIPHERAL INTERFACE (SPI)
Serial Communication ETEC 6416.
4.0 rtos implementation part II
Arduino Josh Villbrandt February 4, Digital Circuits Analog versus digital – What’s the difference? – How to represent an analog signal in a computer?
SC200x Peripherals Broadband Entertainment Division DTV Source Applications July 2001.
Universal Synchronous/Asynchronous Receiver/Transmitter (USART)
Lecture 20: Communications Lecturers: Professor John Devlin Mr Robert Ross.
1 Microprocessor-based Systems Course 9 Design of the input/output interfaces (continue)
1 Neutron Monitor Workshop 3(B): Next Generation Readout Board Mahidol University January 6, 2010 Paul Evenson University of Delaware Bartol Research Institute.
Universal Asynchronous Receiver/Transmitter (UART)
ECE 353 Introduction to Microprocessor Systems Michael Schulte Week 13.
Embedded System Design Laboratory October 4, 2002Stanford University - EE281 Lecture #3#1 Lecture #3 Outline Announcements AVR Processor Resources –UART.
Scott Baker Will Cross Belinda Frieri March 9 th, 2005 Serial Communication Overview ME4447/6405.
DEVICES AND COMMUNICATION BUSES FOR DEVICES NETWORK
 8251A is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for serial data communication.  Programmable peripheral designed for synchronous.
Universal Asynchronous Receiver/Transmitter (UART)
CE-2810 Dr. Mark L. Hornick 1 Using the USART Configuration and Programming.
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
©2008 R. Gupta, UCSD COSMOS Summer 2008 Peripheral Interfaces Rajesh K. Gupta Computer Science and Engineering University of California, San Diego.
智慧電子應用設計導論(1/3) Arduino MEGA 2560
© 2009, Renesas Technology America, Inc., All Rights Reserved 1 Course Introduction  Purpose:  This course provides an overview of the serial communication.
Essentials of Communication This simple model requires many guarantees. Sender Receiver Communication Link Data.
Unit 1 Lecture 4.
Communicating. The ATmega16 communicates through one of the following ways: Serial Peripheral Interface (SPI) Universal Synchronous and Asynchronous serial.
CE-2810 Dr. Mark L. Hornick 1 Serial Communications Sending and receiving data between devices.
Embedded Communication Protocols Don Heer 10/18/10 1.
Chap.6.3 UART.
Networked Embedded Systems Sachin Katti & Pengyu Zhang EE107 Spring 2016 Lecture 9 Serial Buses – SPI, I2C.
Networked Embedded Systems Pengyu Zhang EE107 Spring 2016 Lecture 8 Serial Buses.
Tiva C TM4C123GH6PM UART Embedded Systems ECE 4437 Fall 2015 Team 2:
Digital Logic Design Alex Bronstein
EE 107 Fall 2017 Lecture 5 Serial Buses – UART & SPI
1 Input-Output Organization Computer Organization Computer Architectures Lab Peripheral Devices Input-Output Interface Asynchronous Data Transfer Modes.
Atmega32 Serial Programming Basics
EEPROM Comparison – Parallel or Serial
Computer Organization and Design
Asynchronous Serial Communications
Serial Communication Interface: Using 8251
UART Protocol Chapter 11 Sepehr Naimi
COMP3221: Microprocessors and Embedded Systems
Lecturer: Reza Arjmandi Autumn 2015
Преглед Начин функционисања Имплементације
Configuration and Programming
Debugging Debug environments Debug via serial
Programmable Data Communication Blocks
Serial Communication 19th Han Seung Uk.
AVR UART The UART, or Universal Asynchronous Receiver Transmitter, provides hardware support for a serial port on AVR processors Signaling is compatible.
Presentation transcript:

The Arduino Platform A “development module” A board with a microcontroller and USB interface to a PC Large open source community

Arduino Environment A development board - 8-bit microcontroller - programming hardware - USB programming interface - I/O pins A software environment - cross-compiler - debugger - simulator - programmer Special-purpose “shields” - daughter boards - unique functionalities - easy to attach - good libraries provided

Arduino Hardware Typical of an 8-bit processor - low speed, low memory Microcontroller ATmega328 Operating Voltage 5V Input Voltage (recommended) 7-12V Input Voltage (limits) 6-20V Digital I/O Pins 14 (of which 6 provide PWM output) Analog Input Pins 6 DC Current per I/O Pin 40 mA DC Current for 3.3V Pin 50 mA Flash Memory 32 KB (ATmega328) of which 0.5 KB used by bootloader SRAM 2 KB (ATmega328) EEPROM 1 KB (ATmega328) Clock Speed 16 MHz Typical of an 8-bit processor - low speed, low memory - low cost ($1.50 for the microcontroller, $40 for the board)

Raspberry Pi 32-bit processor Broadcom BCM2838 SoC, ARM11 700 MHz clock 512 MB RAM Broadcom VideoCore IV GPU SD card slot, no flash built-in Ports: USB (2), HDMI, RCA audio/video, SD, Ethernet, 2x13 pins MIPI Camera Interface Size of a credit card $35

Raspberry Pi Software 32-bit machine, can support an operating system Arch linux, Debian, Fedora, Slackware, etc. A bit slow for development Hard to run GUI, IDE Cross compile with crosstool-ng toolchain or gcc-linaro-arm-linux Easy Python programming interface is available

BeagleBone Black TI Sitara AM3359 ARM Cortex-A8 32-bit processor 1 GHz clock 512 MB RAM 2GB on-board flash 3D graphics accelerator Ports: USB, Ethernet, HDMI, 2x46 pins $45 cost, almost the same as an Arduino

Beagle Software Environment Several versions of linux are ported Ubuntu, Angstrom, Android … A bit slow for development Hard to run GUI, IDE Cross compile with gcc-arm toolchain BoneScript (JavaScript) library is provided for simplicity Uses an interpreter

BeagleBone “Capes” Application-specific, stackable, daughter boards VGA Cape Camera Cape DVI-D Cape Application-specific, stackable, daughter boards Just like Arduino shields Come with libraries

UART/USART Universal Asynchronous Receiver/Transmitter Used for serial communication between devices UART is asynchronous, no shared clock Asynchronous allows longer distance communication Clock skew is not a problem USART is the synchronous version of UART Common clock is needed NVIDIA® Tegra™ 250 NVIDIA® Tegra™ 250 Slides created by: Professor Ian G. Harris

Serial Protocols Data is transmitted serially Only 1 bit needed (plus common ground) Parallel data transmitted serially Original bytes/words regrouped by the receiver Many protocols are serial to reduce pin usage Pins are precious Slides created by: Professor Ian G. Harris

UART Applications Used by modems to communicate with network Computers used to have an RS232 port, standard Not well used anymore, outside of embedded systems Replaced by USB, ethernet, I2C, SPI Simple, low HW overhead Built into most microcontrollers Slides created by: Professor Ian G. Harris

Simple UART Structure Tx Rx Serial Out Serial In Parallel In Parallel Out status Data is serialized by Tx, deserialized by Rx Status indicates the state of the transmit/receive buffers Used for flow control Slides created by: Professor Ian G. Harris

UART Timing Diagram First bit is the Start Bit, initiates the transfer 8 bits First bit is the Start Bit, initiates the transfer Next bits are the data Last are the Stop Bits Slides created by: Professor Ian G. Harris

Bit Duration Each bit is transmitted for a fixed duration The duration must be known to Tx and Rx Baud Rate (f) determines the duration (T) Baud Rate is the number of transitions per second Typically measured in “bits per second (bps)” T = 1/f Ex. F = 9600 baud, T = ~104 microsec Transmission rate is less than baud rate Need start bit, stop bits, parity bit Slides created by: Professor Ian G. Harris

UART Synchronization Receiver must know the exact start time Imprecise start time corrupts data 1 stop bit 7 bit 8 Expected Bit, correct Expected Bit, incorrect Slides created by: Professor Ian G. Harris

Start Bit, Synchronization Detection of the start bit is used to synchronize Synchronization based on falling edge of start bit Start bit is a falling edge Following 0 must be long duration to screen out noise Receiver samples faster than baud rate (16x typical) Start bit is indicated by a 0 of at least half period Just a glitch Start bit detected Slides created by: Professor Ian G. Harris

Parity Bit Transmission medium is assumed to be error-prone E-M radiation noise, synchronization accuracy Parity bit may be transmitted to check for errors Even Parity: Number of 1’s is even Odd Parity: Number of 1’s is odd Parity bit is added to ensure even/odd parity After data, before stop bit(s) Ex. Assume Odd Parity, Data = 011011010 Parity bit = 0, total parity is odd Slides created by: Professor Ian G. Harris

Stop Bit Receiver expects a 1 after all data bits and parity bits If 1 is not received, error has occurred Slides created by: Professor Ian G. Harris

Data Throughput vs. Baud Every transmission involves sending signaling bits Stop, start, parity Data throughput rate is lower than baud rate Signaling bits must be sent Ex. 8 data bits, 1 parity bit, baud rate = 9600 Send 11 bits to send 8 data bits Transmission efficiency = 8/11 = 73% Data throughput rate = 9600 * 0.73 = 6981.8 bps Slides created by: Professor Ian G. Harris

USART HW in ATmega Clock Pin For synchronous transfers Output (input) for master (slave) Transmit Pin Receive Pin Slides created by: Professor Ian G. Harris

Clock Generation Two (or 3) clocks may be needed Internal Clock – Two internal clocks High speed clock used by receiver to sample incoming signal Slower baud rate clock used by transmitter to time transmission External Clock – Only used in synchronous mode Baud rate clock used to synchronize master and slave Generated by master, read by slave Slides created by: Professor Ian G. Harris

Clock Generation Logic Internal Tx Clk Internal Rx Clk Rx clk in generated from internal fosc UBRRn – Prescalar value used to generate Rx clk UBRRn is two 8-bit registers, UBRRH and UBRRL Slides created by: Professor Ian G. Harris

Clock Operation Modes Normal Asynchronous Double Speed Asynchronous Rx/Tx clk rate is 16x baud rate Accurate sampling of signal, good synchronization Double Speed Asynchronous Rx/Tx clk rate is 8x baud rate Double speed transmission, less accurate synchronization Master Synchronous Synchronous communication, generate clk Slave Synchronous Synchronous communication, receive clk Slides created by: Professor Ian G. Harris

Setting Clocks High Speed Internal Clock Internal Rate = fosc / (UBRRn + 1) Baud Rate Clk, Normal Asynchronous Baud = fosc / 16 (UBRRn + 1) Baud Rate Clk, Double Speed Asynchronous Baud = fosc / 8 (UBRRn + 1) Slides created by: Professor Ian G. Harris

Frame Formats USART has several communication options to define how many bits are transmitted Start bit: 1 Data bits: 5 – 9 Parity bit: none, even, odd Stop bits: 1 or 2 Set using bits in the UCSRnB and UCSRnC registers Format must match on both transmitter and receiver Slides created by: Professor Ian G. Harris

USART Register Summary UBBR is the prescalar used to determine the clocks Determines the BAUD rate UCSRA indicates the status of communications Transmit/Receive complete, errors, etc. UCSRB enables interrupts and communications Interrupt enable, Tx/Rx enable, data size, etc. UCSRC sets parity bits, stop bits, USART mode, ... UDR holds transmit data and received data Slides created by: Professor Ian G. Harris

UCSRA Bit 7 – RXCn: USART Receive Complete Bit 6 – TXCn: USART Transmit Complete Bit 5 – UDREn: USART Data Register Empty Bit 4 – FEn: Frame Error Bit 3 – DORn: Data OverRun Bit 2 – UPEn: USART Parity Error Slides created by: Professor Ian G. Harris

Typical USART Initialization #define FOSC 1843200// Clock Speed #define BAUD 9600 #define MYUBRR FOSC/(16*BAUD)-1 void main( void ) { USART_Init ( MYUBRR ); } void USART_Init( unsigned int ubrr){ /* Set baud rate */ UBRRH = (unsigned char)(ubrr>>8); UBRRL = (unsigned char)ubrr; /* Enable receiver and transmitter */ UCSRB = (1<<RXEN)|(1<<TXEN); /* Set frame format: 8data, 2stop bit */ UCSRC = (1<<USBS)|(3<<UCSZ0); } // USART_Init Slides created by: Professor Ian G. Harris

Transmitting Data void USART_Transmit( unsigned char data ) { // Wait for empty transmit buffer while ( !( UCSRA & (1<<UDRE)) ); // Put data into buffer, sends the data UDR = data; } Data is transmitted by placing it in the UDR register Data Register Empty (UDRE) bit of the UCSRA register Set to 0 while a transfer is going on Need to wait for it before sending new data Slides created by: Professor Ian G. Harris

Receiving Data Data is received by reading it from the UDRn register void USART_Receive( void ) { // Wait for data to be received while ( !( UCSRA & (1<<RXC)) ); // Read data from UDRn buffer return ( UDR ); } Data is received by reading it from the UDRn register Different from transmit UDRn register Receive Complete flag (RXC) bit of the UCSRA register Set to 1 when new data is received Slides created by: Professor Ian G. Harris

Communicating with a PC Need a Terminal Emulator program which “speaks” UART (serial) There are many free terminal emulators Hyperterm (used to come with Windows) Termite Putty (which I use) Need to select a COM port to find the USB-to-serial adapter Need to match frame format to the ATmega Slides created by: Professor Ian G. Harris

Putty Terminal Emulator Can communicate in several protocols Select “Serial” Fill in baud rate Adjust settings by selecting “Serial” in left column Slides created by: Professor Ian G. Harris

Putty Serial Settings Flow control Atmega does not seem to support any Slides created by: Professor Ian G. Harris

UART Uses UART may be an extra (slow) communication channel Useful if communication speed is not a problem Debugging Make a “print” statement Note: will alter performance, but not much Simple User Interface Humans are slow, interface can be as well Slides created by: Professor Ian G. Harris

Synchronous Communication Synchronous protocols share a common clock More accurate, faster than asynchronous protocols Sampling time is accurately known Restricted to short range communication Clock edge and data must have identical timing Clock edge must arrive at all receivers simultaneously Slides created by: Professor Ian G. Harris

Synchronous Protocols USART Limited to communication between two devices (or broadcast) Serial Peripheral Interface (SPI) Multi-Drop Bus protocol, more than two devices Single master, many slaves Inter-Integrated Circuit (I2C) Multi-drop, multi-master Slides created by: Professor Ian G. Harris

SPI a.k.a Four Wire Interface MOSI MISO SCLK SS’ CS’ Master Slave Master Out Slave In (MOSI) –From Master to Slave Master In Slave Out (MISO) –From Slave to Master SCLK – Clock generated by Master Slave Select (SS’) – Indicates communication w/ selected slave Chip Select (CS’) – Alerts slave to communication Slides created by: Professor Ian G. Harris

SPI Data Transmission Serial transmission synchronized by the clock Many bytes may be sent in a single transfer 8-bits is what we will use Bi-directional data transmission MOSI transmits concurrently with MISO Internal shift register may be used to hold both transmitted and received data Shift in a received bit, shift out a transmitted bit Slides created by: Professor Ian G. Harris

Clock Polarity and Phase Clock polarity and phase determine when data is made valid wrt the clock Polarity = 0 or 1, Phase = 0 or 1 Data is valid on each clk rising edge or each clk falling edge Data valid edge (V) = PHASE XOR POLARITY Polarity = 0, Phase = 0: Rising edge sampling Polarity = 1, Phase = 1: Rising edge sampling Polarity = 0, Phase = 1: Falling edge sampling Polarity = 1, Phase = 0: Falling edge sampling Slides created by: Professor Ian G. Harris

SPI Timing Diagrams Polarity, Phase = 0, 0 or 1, 1 bit1 bit2 bit3 SCLK MOSI SS’/CS’ Polarity, Phase = 0, 0 or 1, 1 bit1 bit2 bit3 SCLK MOSI SS’/CS’ Polarity, Phase = 0, 1 or 1, 0 Slides created by: Professor Ian G. Harris

Multiple Independent Slaves Need a unique SS’ for each slave Slave MOSI MISO SCLK SS1’ SS2’ SS3’ CS’ Master Slides created by: Professor Ian G. Harris

SPI on the ATmega Only one SS’ line SPDR Reading accesses last received transmission Writing automatically sends a the data Do not directly access the SPI pins Handled in hardware Slides created by: Professor Ian G. Harris