Chapter 8 Communication Introduction to serial communication interfaces. Examples of use of the SPI module.

Slides:



Advertisements
Similar presentations
8086 [2] Ahad. Internal! External? 8086 vs _bit Data Bus 20_bit Address 8_bit Data Bus 20_bit Address Only external bus of 8088 is.
Advertisements

Dr. Rabie A. Ramadan Al-Azhar University Lecture 3
ECE 2211 Microprocessor and Interfacing Chapter 8 The 8088/8086 Microprocessors and their memory and I/O interfaces Br. Athaur Rahman Bin Najeeb Room.
MICROPROCESSORS TWO TYPES OF MODELS ARE USED :  PROGRAMMER’S MODEL :- THIS MODEL SHOWS FEATURES, SUCH AS INTERNAL REGISTERS, ADDRESS,DATA & CONTROL BUSES.
The 8085 Microprocessor Architecture
Microprocessor and Microcontroller
I/O Unit.
Chapter 11 It’s an Analog World Learning to use the Analog to Digital Converter.
Introduction of Holtek HT-46 series MCU
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 2: Computer-System Structures Computer System Operation I/O Structure Storage.
Chapter 7 Interupts DMA Channels Context Switching.
Serial Peripheral Interface (SPI)
Recap – Our First Computer WR System Bus 8 ALU Carry output A B S C OUT F 8 8 To registers’ input/output and clock inputs Sequence of control signal combinations.
Midterm Tuesday October 23 Covers Chapters 3 through 6 - Buses, Clocks, Timing, Edge Triggering, Level Triggering - Cache Memory Systems - Internal Memory.
GURSHARAN SINGH TATLA PIN DIAGRAM OF 8085 GURSHARAN SINGH TATLA
Unit-5 CO-MPI autonomous
INTERRUPTS PROGRAMMING
Chapter 7 Synchronous Serial SPI and I2C interfaces.
NS Training Hardware. System Controller Module.
Chapter 10 Input/Output Interface Circuits and LSI Peripheral Devices
The 8051 Microcontroller architecture
Chapter 12 Capturing Input. Di Jasio - Programming 32-bit Microcontrollers in C Button Inputs.
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)
Khaled A. Al-Utaibi  Intel Peripheral Controller Chips  Basic Description of the 8255  Pin Configuration of the 8255  Block Diagram.
Computer System Overview Chapter 1. Operating System Exploits the hardware resources of one or more processors Provides a set of services to system users.
1 SERIAL PORT INTERFACE FOR MICROCONTROLLER EMBEDDED INTO INTEGRATED POWER METER Mr. Borisav Jovanović, Prof.dr Predrag Petković, Prof.dr. Milunka Damnjanović,
Chapter 2 A Loop in the Pattern Designing the Main Loop and Timing.
MICROPROCESSOR INPUT/OUTPUT
1. Introduction 2. Methods for I/O Operations 3. Buses 4. Liquid Crystal Displays 5. Other Types of Displays 6. Graphics Adapters 7. Optical Discs 10/01/20151Input/Output.
CHAPTER 2: COMPUTER-SYSTEM STRUCTURES Computer system operation Computer system operation I/O structure I/O structure Storage structure Storage structure.
I/O Interfacing A lot of handshaking is required between the CPU and most I/O devices. All I/O devices operate asynchronously with respect to the CPU.
8279 KEYBOARD AND DISPLAY INTERFACING
MICROCONTROLLER SYSTEMS Part 1. Figure 1.1Elements of a digital controller CPU Central Processing Unit Input Peripherals Output Peripherals ROM Read Only.
1 Synchronous Serial IO Send a separate clock line with data –SPI (serial peripheral interface) protocol –I 2 C (or I2C) protocol Encode a clock with data.
Chapter 2 Introducing the PIC Mid-Range Family and the 16F84A The aims of this chapter are to introduce: The PIC mid-range family, in overview The overall.
Accessing I/O Devices Processor Memory BUS I/O Device 1 I/O Device 2.
Chapter 7 - Performance Understanding the PIC32 Clock and learning to optimize the memory interface for maximum performance.
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
1 CS.217 Operating System By Ajarn..Sutapart Sappajak,METC,MSIT Chapter 2 Computer-System Structures Slide 1 Chapter 2 Computer-System Structures.
Architecture and instruction set. Microcontroller Core Features:  Operating speed: DC - 20 MHz clock input DC ns instruction cycle Up to 8K x.
8279 KEYBOARD AND DISPLAY INTERFACING
CE Operating Systems Lecture 2 Low level hardware support for operating systems.
I NTRODUCTION TO PIC PROGRAMMING By : S HERIF H ARHASH.
Chapter 5 - Interrupts.
Introduction to Microprocessors - chapter3 1 Chapter 3 The 8085 Microprocessor Architecture.
Presented by Sadhish Prabhu
بسم الله الرحمن الرحيم MEMORY AND I/O.
8085 INTERNAL ARCHITECTURE.  Upon completing this topic, you should be able to: State all the register available in the 8085 microprocessor and explain.
HJD Institute of Technical Education & Research- Kera(Kutch) The 8051 Microcontroller architecture PREPARED BY: RAYMA SOHIL( )
BIRLA VISHVAKARMA MAHAVIDYALAY SUBJECT: SPI PROTOCOL & MAX7221 DISPLAY INTERFACING SUBMITTED BY: KISHAN AVASTHI( ) MANSI CHANDEGARA( )
Gandhinagar Institute of Technology
DEPARTMENT OF ELECTRONICS ENGINEERING V-SEMESTER MICROPROCESSOR & MICROCONTROLLER 1 CHAPTER NO microcontroller & programming.
Memory Interface EEE 365 [FALL 2014] LECTURER 12 ATANU K SAHA BRAC UNIVERSITY.
Chapter 10 Interrupts. Basic Concepts in Interrupts  An interrupt is a communication process set up in a microprocessor or microcontroller in which:
Serial Sinkron SPI & I2C Interface
Chapter 2: Computer-System Structures
UNIT – Microcontroller.
Dr. Michael Nasief Lecture 2
DMA CONTROLLER 8257 Features: It is a 4-channel DMA.
Interrupt.
The Arduino Microcontroller: Atmel AVR Atmega 328
Serial EEPROM (Atmel 24C-512)
Module 2: Computer-System Structures
X1 & X2 These are also called Crystal Input Pins.
8051 Micro Controller.
Module 2: Computer-System Structures
8253 – PROGRAMMABLE INTERVAL TIMER (PIT). What is a Timer? Timer is a specialized type of device that is used to measure timing intervals. Timers can.
Module 2: Computer-System Structures
Module 2: Computer-System Structures
Presentation transcript:

Chapter 8 Communication Introduction to serial communication interfaces. Examples of use of the SPI module

Di Jasio - Programming 32-bit Microcontrollers in C Synchronous Serial Interfaces

Di Jasio - Programming 32-bit Microcontrollers in C SPI bus

Di Jasio - Programming 32-bit Microcontrollers in C Asynchronous Serial Interfaces

Di Jasio - Programming 32-bit Microcontrollers in C Serial Interfaces Side by Side

Di Jasio - Programming 32-bit Microcontrollers in C SPI module figure 17-1 (DS61143)

Di Jasio - Programming 32-bit Microcontrollers in C SPIxCON

SPI module basic setup // peripheral configurations #define SPI_CONF 0x8120 // SPI on, 8-bit master,CKE=1,CKP=0 #define SPI_BAUD 15 // Fpb/(2 * (15+1)) = 1:32 Provides a clock of 9MHz / 32 = ~ 280kHz // configuration bit settings, Fcy=72MHz, Fpb=9MHz #pragma config POSCMOD=XT, FNOSC=PRIPLL #pragma config FPLLIDIV=DIV_2, FPLLMUL=MUL_18, FPLLODIV=DIV_1 #pragma config FPBDIV=DIV_8, FWDTEN=OFF, CP=OFF, BWP=OFF

Di Jasio - Programming 32-bit Microcontrollers in C Reading and Writing // I/O definitions #define CSEE _RD12 // select line for EEPROM #define TCSEE _TRISD12 // tris control for CSEE pin // 1. init the SPI peripheral TCSEE = 0; // make SSEE pin output CSEE = 1; // de-select the EEPROM SPI2CON = SPI_CONF; // select mode and enable SPI2SPI2BRG = SPI_BAUD; // select clock speed // send one byte of data and receive one back at the same time int writeSPI2( int i) { SPI2BUF = i; // write to buffer for TX while( !SPI2STATbits.SPIRBF); // wait for transfer complete return SPI2BUF; // read the received value }//writeSPI2

Di Jasio - Programming 32-bit Microcontrollers in C Serial EEPROM Commands // 25LC256 Serial EEPROM commands #define SEE_WRSR 1 // write status register #define SEE_WRITE 2 // write command #define SEE_READ 3 // read command #define SEE_WDI 4 // write disable #define SEE_STAT 5 // read status register #define SEE_WEN 6 // write enable

Di Jasio - Programming 32-bit Microcontrollers in C Serial EEPROM Status Register 25LC256 Status register detail (DS21822)

Di Jasio - Programming 32-bit Microcontrollers in C Writing Data to the EEPROM // send a Write command CSEE = 0; // select the Serial EEPROM writeSPI2( SEE_WRITE); // send command, ignore data writeSPI2( ADDR_MSB); // send MSB of memory address writeSPI2( ADDR_LSB); // send LSB of memory address writeSPI2( data); // send the actual data // send more data here to perform a page write CSEE = 1; // start actual EEPROM write cycle

Di Jasio - Programming 32-bit Microcontrollers in C Reading EEPROM Data // send a Read command CSEE = 0; // select the Serial EEPROM writeSPI2( SEE_READ); // send command, ignore data writeSPI2( ADDR_MSB); // send MSB of memory address writeSPI2( ADDR_LSB); // send LSB of memory address data = writeSPI2( 0); // send dummy, read data // read more data here sequentially incrementing the address... // terminate the read sequence CSEE = 1; // and return to low power

Di Jasio - Programming 32-bit Microcontrollers in C 32-bit Serial EEPROM Lib /* ** SEE Access Library */ #include "p32xxxx.h" #include "see.h" // I/O definitions #define CSEE _RD12 // select line for Serial EEPROM #define TCSEE _TRISD12 // tris control for CSEE pin // peripheral configurations #define SPI_CONF 0x8120 // SPI on, 8-bit master,CKE=1,CKP=0 #define SPI_BAUD 15 // clock divider Fpb/(2 * (15+1)) // 25LC256 Serial EEPROM commands #define SEE_WRSR 1 // write status register #define SEE_WRITE 2 // write command #define SEE_READ 3 // read command #define SEE_WDI 4 // write disable #define SEE_STAT 5 // read status register #define SEE_WEN 6 // write enable // send one byte of data and receive one back at the same time int writeSPI2( int i) { SPI2BUF = i; // write to buffer for TX while( !SPI2STATbits.SPIRBF); // wait for transfer complete return SPI2BUF; // read the received value }//writeSPI2 void initSEE( void) { // init the SPI2 peripheral CSEE = 1; // de-select the Serial EEPROM TCSEE = 0; // make SSEE pin output SPI2CON = SPI_CONF; // enable the peripheral SPI2BRG = SPI_BAUD; // select clock speed }// initSEE

Di Jasio - Programming 32-bit Microcontrollers in C 32-bit Serial EEPROM Lib (cont.) int readStatus( void) { // Check the Serial EEPROM status register int i; CSEE = 0; // select the Serial EEPROM writeSPI2( SEE_STAT); // send a READ STATUS COMMAND i = writeSPI2( 0); // send/receive CSEE = 1; // deselect terminate command return i; } // readStatus int readSEE( int address) { // read a 32-bit value starting at an even address int i; // wait until any work in progress is completed while ( readStatus() & 0x1);// check WIP // perform a 32-bit read sequence, four byte sequential read CSEE = 0; // select the Serial EEPROM writeSPI2( SEE_READ); // read command writeSPI2( address >>8); // address MSB first writeSPI2( address & 0xfc); // address LSB (word aligned) i = writeSPI2( 0); // send dummy, read msb i = (i<<8)+ writeSPI2( 0); // send dummy, read lsb CSEE = 1; return ( i); }// readSEE

Di Jasio - Programming 32-bit Microcontrollers in C 32-bit Serial EEPROM Lib (cont.) void writeEnable( void) { // send a Write Enable command CSEE = 0; // select the Serial EEPROM writeSPI2( SEE_WEN); // write enable command CSEE = 1; // deselect to complete the command }// writeEnable void writeSEE( int address, int data) { // write a 32-bit value starting at an even address // wait until any work in progress is completed while ( readStatus() & 0x1) // check the WIP flag // Set the Write Enable Latch writeEnable(); // perform a 32-bit write sequence (4 byte page write) CSEE = 0; // select the Serial EEPROM writeSPI2( SEE_WRITE); // write command writeSPI2( address>>8); // address MSB first writeSPI2( address & 0xfc); // address LSB (word aligned) writeSPI2( data >>24); // send msb writeSPI2( data >>16); // send msb writeSPI2( data >>8); // send msb writeSPI2( data); // send lsb CSEE = 1; }// writeSEE

Di Jasio - Programming 32-bit Microcontrollers in C Tips and Tricks If you store important data in an external non volatile memory (SEE), you might want to put some additional safety measures in place (both hardware and software). From a hardware perspective make sure that: Adequate power supply decoupling (capacitor) is provided close to the device. A pull up resistor (10k Ohm) is provided on the Chip Select line, to avoid floating during the microcontroller power up and reset. An additional pull down resistor (10k Ohm) can be provided on the SCK clock line to avoid clocking of the peripheral during power up when the PIC32 I/Os might be floating (tri-state). Verify clean and fast power-up and down slopes are provided to the microcontroller to guarantee reliable Power-On Reset (POR) operation. If necessary add an external voltage supervisor (see MCP809 devices for example).

Di Jasio - Programming 32-bit Microcontrollers in C Tips and Tricks A number of software methods can then be employed to prevent even the most remote possibility that a program bug or the proverbial cosmic ray might trigger the write routine. Here are some suggestions: Avoid reading and especially updating the SEE content right after power up. Allow a few milliseconds for the power supply to stabilize (this is going to be heavily application dependent). Add a software write-enable flag, and demand that the calling application set the flag before calling the write routine, possibly after verifying some application specific entry condition. Add a stack level counter; each function in the stack of calls implemented by the library should increment the counter upon entry and decrement it on exit. The write routine should refuse to perform if the counter is not at the expected level. Some users refuse to use the SEE memory locations corresponding to the first address (0x0000) and/or the last address (0xffff) believing they could be statistically more likely to be subject to corruption. More seriously, store two copies of each essential piece of data, performing two separate calls to the write routine. If each copy contains a checksum or simply by comparison, when reading it back, it will be easy to identify a memory corruption problem and possibly recover.