Interrupts and Serial Communication on the PIC18F8520

Similar documents
ELCT 912: Advanced Embedded Systems

EET203 MICROCONTROLLER SYSTEMS DESIGN Serial Port Interfacing

MCS-51 Serial Port A T 8 9 C 5 2 1

Chapter 10 Sections 1,2,9,10 Dr. Iyad Jafar

Interrupts on PIC18F252 Part 2. Interrupts Programming in C Language

Interrupts & Interrupt Service Routines (ISRs)

Serial Communications

FULL DUPLEX BIDIRECTIONAL UART COMMUNICATION BETWEEN PIC MICROCONTROLLERS

Lab 6 RS-232 Communication The following routines are provided for devices with a single USART peripheral:

Serial Communication

Asynchronous Transmission. Asynchronous Serial Communications & UARTS

Microcontroller basics

8051 Timers and Serial Port

Hi Hsiao-Lung Chan Dept Electrical Engineering Chang Gung University, Taiwan

Section 21. Addressable USART

Maxim > Design Support > Technical Documents > Application Notes > Microcontrollers > APP 4465

Design and development of embedded systems for the Internet of Things (IoT) Fabio Angeletti Fabrizio Gattuso

Embedded Systems and Software

Embedded Systems Programming and Architectures

Newbie s Guide to AVR Interrupts

Embedded Systems and Software. Serial Communication

8051 Serial Port. EE4380 Fall02 Class 10. Pari vallal Kannan. Center for Integrated Circuits and Systems University of Texas at Dallas

ATmega Interrupts. Reading. The AVR Microcontroller and Embedded Systems using Assembly and C) by Muhammad Ali Mazidi, Sarmad Naimi, and Sepehr Naimi

Parallel IO. Serial IO. Parallel vs. Serial IO. simplex vs half-duplex vs full-duplex. Wires: Full Duplex. Wires: Simplex, Half-duplex.

CN310 Microprocessor Systems Design

Serial Communication with PIC16F877A

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

By the end of Class. Outline. Homework 5. C8051F020 Block Diagram (pg 18) Pseudo-code for Lab 1-2 due as part of prelab

EEE394 Microprocessor and Microcontroller Laboratory Lab #6

Microprocessors B (17.384) Spring Lecture Outline

INTERRUPTS in microprocessor systems

ECE 354 Introduction to Lab 2. February 23 rd, 2003

Interrupts. Embedded Systems Interfacing. 08 September 2011

2.996/6.971 Biomedical Devices Design Laboratory Lecture 6: Microprocessors II

More PIC Programming. Serial and parallel data transfer External busses Analog to digital conversion

ECE 354 Introduction to Lab 1. February 5 th, 2003

ECE 354 Computer Systems Lab II. Interrupts, Strings, and Busses

TKT-3500 Microcontroller systems

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Section 31. DMA Controller

Example of Asyncronous Serial Comms on a PIC16F877

Embedded systems. Exercise session 3. Microcontroller Programming Lab Preparation

SYLLABUS UNIT - I 8086/8088 ARCHITECTURE AND INSTRUCTION SET

12.1. Unit 12. Exceptions & Interrupts

Network Embedded Systems Sensor Networks Fall Hardware. Marcus Chang,

ECE251: Thursday November 8

Short Term Courses (Including Project Work)

PIC Microcontroller Introduction

Experiment 7:The USART

GPS Reader. Figure 1: RMC NEMA Tag Definition

Grundlagen Microcontroller Interrupts. Günther Gridling Bettina Weiss

Release Bugs solved

Universal Asynchronous Receiver / Transmitter (UART)

The University of Texas at Arlington Lecture 21_Review

Using Direct Memory Access to Improve Performance

SquareWear Programming Reference 1.0 Oct 10, 2012

8051 Serial Communication

Embedded System Curriculum

Single thread Scheduler All processes called once each sample

EMBEDDED Systems. Functions. MODULE- 1 C programming with data Structure Introduction to C. Array and String. Control Flow Statements In C

MPLAB SIM. MPLAB IDE Software Simulation Engine Microchip Technology Incorporated MPLAB SIM Software Simulation Engine

Embedded Software TI2726 B. 4. Interrupts. Koen Langendoen. Embedded Software Group

8051 Microcontroller

CoE3DJ4 Digital Systems Design. Chapter 5: Serial Port Operation

Interrupts on PIC18F252 Part 2

Emulating an asynchronous serial interface (USART) via software routines

Interrupts and timers

Hello, and welcome to this presentation of the STM32 Universal Synchronous/Asynchronous Receiver/Transmitter Interface. It covers the main features

Introduction to Embedded Systems

UART: Universal Asynchronous Receiver & Transmitter

Hello, and welcome to this presentation of the STM32 Low Power Universal Asynchronous Receiver/Transmitter interface. It covers the main features of

FINAL EXAM. last name first name

JAVA BYTE IPC: PART 1 DERIVING NIO FROM I/O. Instructor: Prasun Dewan (FB 150,

ELE492 Embedded System Design

EE 308: Microcontrollers

UNIT V MICRO CONTROLLER PROGRAMMING & APPLICATIONS TWO MARKS. 3.Give any two differences between microprocessor and micro controller.

To be familiar with the USART (RS-232) protocol. To be familiar with one type of internal storage system in PIC (EEPROM).

YOU WILL NOT BE ALLOWED INTO YOUR LAB SECTION WITHOUT THE REQUIRED PRE-LAB.

Nano RK And Zigduino. wnfa ta course hikaru4

Embedded Systems. 3. Hardware Software Interface. Lothar Thiele. Computer Engineering and Networks Laboratory

Introduction USART & AVR EVK1100

A. This Errata sheet represents the known bugs, anomalies and work-arounds for the ADuC812 MicroConverter.

UNIVERSITY OF BOLTON SCHOOL OF ENGINEERING. BEng(Hons) Electrical and Electronics Engineering SEMESTER 1 EXAMINATION 2016/2017

Learn how to communicate

Embedded Real-Time Systems

Understanding the basic building blocks of a microcontroller device in general. Knows the terminologies like embedded and external memory devices,

Operating Systems 2010/2011

Software Documentation

e-pg Pathshala Subject: Computer Science Paper: Embedded System Module: Interrupt Programming in Embedded C Module No: CS/ES/20 Quadrant 1 e-text

I Introduction to Real-time Applications By Prawat Nagvajara

EE 354 November 13, 2017 ARM UART Notes

EE458 - Embedded Systems Exceptions and Interrupts

Fundamental concept in computation Interrupt execution of a program to handle an event

Interrupts, timers and counters

Unit 4 Part 2: Communications - Asynchronous Serial Protocols

PIC-I/O Multifunction I/O Controller

Emulating an asynchronous serial interface (ASC0) via software routines

CSCE 236 Embedded Systems, Fall 2017 Homework 5

University of Texas at El Paso Electrical and Computer Engineering Department. EE 3176 Laboratory for Microprocessors I.

OUTLINE. SPI Theory SPI Implementation STM32F0 SPI Resources System Overview Registers SPI Application Initialization Interface Examples

Transcription:

Interrupts and Serial Communication on the PIC18F8520 Kyle Persohn COEN 4720 Fall 2011 Marquette University 6 October 2011

Outline 1 Background Serial Communication PIC18 Interrupt System 2 Customizing the OpenVex ISR Enabling Interrupt Sources Interrupt Flags 3 Common Pitfalls Concurrency Issues Troubleshooting 4 Sending Data to the Netbook

Serial Communication Synchronous vs Asynchronous Hardware Synchronous Master/Slave using clock timing (half-duplex) Ex. MSSP (SPI, I 2 C) Asynchronous Framing bits identify data payloads Ex. UART/RS-232 Software Synchronous Polling (blocking) read/write Ex. Xinu kprintf() Asynchronous Interrupt/message driven Ex. Xinu printf()

Serial Communication Vex Controller Asynchronous (Hardware) Full-Duplex Baud Rate: 115200 bps 8 data bits No parity 1 stop bit Abbreviated 115200/8N1 Make sure your netbook software (picocom, etc) agrees!

Serial Communication What does this look like?

PIC18 Interrupt System Interrupt Sources UART RX/TX Timer Overflow External Rising/Falling Edge Digital I/O Port Changes State Analog to Digital Converter (ADC) Completes Conversion Capture/Compare Timer Match Many more (see datasheet)

PIC18 Interrupt System What happens when an interrupt is triggered? 1 Processor immediately jumps to interrupt vector (high or low priority, based on source) 2 Interrupt Service Routine (ISR) determines source of interrupt (see datasheet for flag registers) You (the programmer) can use pre-mapped constants in the SDCC platform header file(s) 3 Do something useful (ex. update motor speed) 4 Acknowledge interrupt (clear flag) 5 Return from interrupt

Enabling Interrupt Sources Changes to Lib/vex usart.c void usart init(void) { usart open(usart TX INT OFF & USART RX INT ON & USART BRGH HIGH & USART ASYNCH MODE & USART EIGHT BIT, BAUD 115200); delay1ktcy(50); stdout = STREAM USART; }

Interrupt Flags Changes to Lib/interrupts.c void InterruptHandlerLow(void) INTERRUPT {...blah blah blah... /* Timer 3 overflow interrupt */ if ( PIR2bits.TMR3IF ) { PIR2bits.TMR3IF = 0; ++Timer3_overflows; } } if ( PIR1bits.RCIF ) { rxbyte = RCREG; /* your code to do something with a RX char */ }

Interrupt Flags Clearing the Interrupt Flag Check the datasheet to see how the flag gets cleared... Hardware logic might clear the flag for you. Example: Reading from the USART receive buffer The user might need to manually clear the flag in software. Example: Timer overflow

Concurrency Issues Sharing Data Global variables might be necessary for sharing information between main() and an ISR. Remember: There s no test and set registers, semaphores, etc. Declare shared memory with the keyword volatile.

Concurrency Issues Atomicity Once you turn on interrupts, your main() code may be preempted! Definition An atomic operation is a sequence of one or more machine instructions that are executed sequentially, without interruption. Example Incrementing a variable (i+=2) compiles to many instructions: load, add, store Disable interrupts around code blocks that might leave the system in an inconsistent state if it were to be interrupted.

Troubleshooting Ask Yourself... Did you enable the peripheral? Check configuration register. Did you enable the peripheral interrupt? Check PIRXbits. Are global interrupts enabled? Check INTCON register. Did you recompile the OpenVex library after making changes to the interrupt vector? The library code has a separate makefile than your user-space program.

Transmitting Characters Check out debug.h for handy macros. OpenVex maps stdout to the serial port. Use printf() Manaully assign a character to the memory-mapped USART transmit buffer: TXREG = a ;

Resources PIC18F8520 Datasheet. Microchip Technology. 2004. POSIX Serial Programming Guide. http://www.easysw.com/~mike/serial/serial.html. SDCC User Guide. http://sdcc.sourceforge.net/doc/sdccman.html/