EEE305 Microcontroller Systems Lecture 7: Embedded C using PIC microcontrollers Serial i/o with the XC8 Teaching resources are at www.eej.ulst.ac.ukwww.eej.ulst.ac.uk.

Slides:



Advertisements
Similar presentations
Serial Interface Dr. Esam Al_Qaralleh CE Department
Advertisements

EUSART Serial Communication.
Review: Interrupts & Timers
ECT 357 Ch 18 UART. Today’s Quote: Be careful that your marriage doesn’t become a duel instead of a duet. Be careful that your marriage doesn’t become.
DATA COMMUNICATIONS Some organisations concerned with standards: EIA - Electroonic Industries Association (RS standards including RS-232) IEEE - Institute.
Serial I/O - Programmable Communication Interface
Lecture 8: Serial Interfaces
COMP3221: Microprocessors and Embedded Systems Lecture 22: Serial Input/Output (II) Lecturer: Hui Wu Session 1, 2005.
Starting with serial Chapter Ten 10.1, 10.2,
COE 342: Data & Computer Communications (T042) Dr. Marwan Abu-Amara Chapter 6: Digital Data Communications Techniques.
Eng. Husam Alzaq The Islamic Uni. Of Gaza
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.
Chapter 6 Serial Communications Objectives Introduce the RS232 standard and position it within the crowded field of serial communications standards. Configure.
Serial Communications Standards (Partly Excerpted from Simpl Primer) Cabling Configuration Protocol.
ECE 371- Unit 11 Introduction to Serial I/O. TWO MAJOR CLASSES OF SERIAL DATA INTERFACES ASYNCHRONOUS SERIAL I/O - USES “FRAMING BITS” (START BIT AND.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 13.
Chapter 6 Serial Communications Objectives Introduce the RS232 standard and position it within the crowded field of serial communications standards. Configure.
1 SCI Serial Communication Interface Gerrit Becker James McClearen Charlie Hagadorn October 21, 2004.
Embedded Systems Design
University of Tehran 1 Interface Design Serial Communications Omid Fatemi.
Technology Training that Works Hands of Data Communications, Networking & TCP/IP Troubleshooting.
Serial Communication ETEC 6416.
Computers in Surveying SVY2301 / E4006 Automated Surveying.
USART interrupt.
LSU 10/22/2004Serial I/O1 Programming Unit, Lecture 5.
The 8051 Microcontroller and Embedded Systems
Serial Port I/O Serial port sends and receives data one bit at a time. Serial communication devices are divided into: Data Communications Equipment (DCE),
S4525A Peripherals & Enhanced FLASH 1 © 1999 Microchip Technology Incorporated. All Rights Reserved. S4525A Peripherals & Enhanced FLASH 1 Peripherals.
Universal Synchronous/Asynchronous Receiver/Transmitter (USART)
“Describe the overview of hardware interfacing and the serial communication interface. Describe the PIC18 connections to RS232. Explain the serial port.
Universal Asynchronous Receiver/Transmitter (UART)
ECE 353 Introduction to Microprocessor Systems Michael Schulte Week 13.
Microprocessors 2 lesson Subjects lesson 7 Planning Interrupts Serial communication /USART Questions.
CHAPTER SERIAL PORT PROGRAMMING. Basics of Serial Communication Computers transfer data in two ways: ◦ Parallel  Often 8 or more lines (wire conductors)
Serial Communications
Example. SBUF Register SCON Register(1) SCON Register(2)
 8251A is a USART (Universal Synchronous Asynchronous Receiver Transmitter) for serial data communication.  Programmable peripheral designed for synchronous.
Universal Asynchronous Receiver/Transmitter (UART)
ATtiny23131 A SEMINAR ON AVR MICROCONTROLLER ATtiny2313.
Serial Communications Interface Module Slide #1 of 19 MC68HC908GP20 Training PURPOSE -To explain how to configure and use the Serial Communications Interface.
8051SERIAL PORT PROGRAMMING
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.
Networked Embedded Systems Pengyu Zhang EE107 Spring 2016 Lecture 8 Serial Buses.
8251 USART.
BASICS OF SERIAL COMMUNICATIONS BIRLA VISHWKARMA MAHAVIDYALAYA ELECTRONICS & TELECOMMUNICATION DEPARTMENT PRESENTING BY: ABHISHEK SINGH AMANDEEP.
Criteria for choosing a microcontroller A microcontroller must meet the task at hand efficiency and cost effectively. Speed. What is highest speed of.
Tiva C TM4C123GH6PM UART Embedded Systems ECE 4437 Fall 2015 Team 2:
The HCS12 SCI Subsystem A HCS12 device may have one or two serial communication interface. These two SCI interfaces are referred to as SCI0 and SCI1. The.
Chapter 6 Serial Communications
Serial mode of data transfer
RS-232 Communications.
INT. TO EMBEDDED SYSTEMS DEVELOPMENT
EE 107 Fall 2017 Lecture 5 Serial Buses – UART & SPI
Chapter 10 PIC18 Serial Port Programming in Assembly
SERIAL PORT PROGRAMMING
Serial Communications
May 2006 Saeid Nooshabadi ELEC2041 Microprocessors and Interfacing Lectures 29: I/O Interfacing Examples
Serial Communication: RS-232 (IEEE Standard)
Computer Organization and Design
USART Universal Synchronous Asynchronous Receiver Transmitter
Serial Communication Interface: Using 8251
Serial Communication Interface
CHAPTER SERIAL PORT PROGRAMMING. Basics of Serial Communication Computers transfer data in two ways: ◦ Parallel  Often 8 or more lines (wire.
EUSART Serial Communication.
PIC Serial Port Interfacing
8051SERIAL PORT PROGRAMMING
Figure Serial versus Parallel Data Transfer
PIC Serial Port Interfacing
Presentation transcript:

EEE305 Microcontroller Systems Lecture 7: Embedded C using PIC microcontrollers Serial i/o with the XC8 Teaching resources are at My office 5B18, telephone My 1/

Normal serial transmission of the ASCII character set uses the RS232 PORT found on PCs RS232 is an old interface; it uses +/-12 Volts and therefore needs line drivers and line receivers to convert from the normal 0 and +5 volt logic signals of the microcontroller In the old days “bit” timing was imprecise, RS232 sends each character with its own timing synchronisation, the intercharacter delay is an asynchronous one. All timing is done from the leading (falling) edge of the start bit and is valid for one character. This means that the line has to idle in a ‘1’ state and the start bit has to be a ‘0’ Two characters could be transmitted back to back, we have to finish each with a ‘1’ stop bit So to send 8 data bits requires sending at least 10 bits. The logic is upside down, a ‘0’ is +12 Volts and a ‘1’ is -12 volts, the line driver/receivers invert There are standard bit rates; sending one change of state for each data bit this is the BAUD rate e.G 1200 Baud, 2400 Baud, 4800 baud, 9600 baud etc., There are variations; you can send 7 or 8 data bits, one or two stop bits, and an extra bit just before the stop bits known as the parity bit. The format 8N1 is typical

RS232 has standard connectors The transmit and receive wires are uni-directional, hence we have DTE and DCE when data TERMINAL equipment is wired to a data COMMUNICATION equipment such as a modem. The PC is given a DTE port – male pins, transmitting on PIN 3, labelled TxD A receiving device (using a 1:1 cable) should have a female 9 pin D-type connector, it receives on PIN 3, still (confusingly) labelled TxD – take care! Use Hyperterminal on the PC if XP Use REALTERM if windows 7 Use TERMINAL.EXE if windows 8 (by Use minicom in Linux

The serial port on the PIC Is a Superset of an RS232 port known as the Addressable Universal Synchronous Asynchronous Receiver Transmitter (USART) Some texts just call it a Serial Communications Interface or SCI ( there is also a SPI and IIC interface – these are different) The USART has three important registers TXSTA, RCSTA, SPBRG as well as data registers and interrupt registers

So a good guess to configure this might be; CSRC = x, TX9=0 TXEN = 1,SYNC=0 BRGH= ? Probably ‘1’ We read TRMT, put a ‘1’ in it to make it empty TX9D = X or 0 i.e 0b

Guess; SPEN = 1, RX9 = 0 CREN = 1, ADDEN=0 FERR and OERR are read to see if errors have occurred RX9D is read if using 9 bit mode (stick to 8 bits!)

Baud rate Generator Depends on PIC crystal, and TXSTA (BRGH) But there are lookup tables on page 98 of the datasheet for common baud rates and clock frequencies, for both BRGH= 0 or 1

Use the lookup tables in Page 98 of datasheet

Understanding the USART

void serial_setup(void) { /* * Comms setup: */ #define BAUD #define DIVIDER 25 // lookup from table – 4MHz and we want 9600 #define HIGH_SPEED 1 SPBRG=DIVIDER; BRGH=HIGH_SPEED;//data rate for sending SYNC=0;//asynchronous SPEN=1;//enable serial port pins CREN=1;//enable reception SREN=0;//no effect TXIE=0;//disable tx interrupts RCIE=0;//disable rx interrupts TX9=0;//8-bit transmission RX9=0;//8-bit reception TXEN=0;//reset transmitter TXEN=1;//enable the transmitter }

//writes a character to the serial port void putch(unsigned char c) { while(!TXIF) //set when register is empty { clear_usart_errors_inline; CLRWDT(); } TXREG=c; // send data to USART DelayUs(60); } //gets a character from the serial port without timeout unsigned char getch(void) { while(!RCIF) { CLRWDT(); clear_usart_errors_inline; } return RCREG; } unsigned char dummy; #define clear_usart_errors_inline \ if (OERR) \ { \ TXEN=0; \ TXEN=1; \ CREN=0; \ CREN=1; \ } \ if (FERR) \ { \ dummy=RCREG; \ TXEN=0; \ TXEN=1; \ } Most examples omit the reference to errors, it is only needed if running comms for more than 24 hours and an interruption occurs, such as a source of RS232 powering off half way through a transfer.

The SPI and IIC peripherals