42
GELE5343 Chapitre 4 : Bus et interface Gabriel Cormier, Ph.D., ing. Universit´ e de Moncton Hiver 2013 Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 1 / 42

Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

GELE5343 Chapitre 4 :Bus et interface

Gabriel Cormier, Ph.D., ing.

Universite de Moncton

Hiver 2013

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 1 / 42

Page 2: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

Introduction

Contenu

1 Introduction

2 GPIB

3 Bus I2C

4 SPI

5 UART

6 SMBus

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 2 / 42

Page 3: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

GPIB

GPIB

GPIB : General Purpose Interface Bus

Standard IEEE-488

Protocole de communication pour instruments de mesure

Initialement appele HP-IB (developpe par HP, fin des annees 60)

Permet la communication entre differents instruments

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 3 / 42

Page 4: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

GPIB

Permet de brancher jusqu’a 31appareil en chaıne (theorique)mais 20 en pratique.

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 4 / 42

Page 5: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

GPIB

Dispositifs : roles

Controleur : controle les dispositifs. Seul 1 controleur peut etre actif ala fois.

Ecouteur (listener) : Peut recevoir des donnees lorsqu’indique par lecontroleur

Transmetteur (talker) : transmet des donnees sur le bus lorsqu’indiquepar le controleur

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 5 / 42

Page 6: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

GPIB

Pins

Pin Nom Fonction1 DIO1 Bit Entree/Sortie2 DIO2 Bit Entree/Sortie3 DIO3 Bit Entree/Sortie4 DIO4 Bit Entree/Sortie5 EOI End-or-Identity6 DAV Data Valid7 NRFD Not ready for data8 NDAC Not data accepted9 IFC Interface clear10 SRQ Service request11 ATN Attention12 SHIELD

Pin Nom Fonction13 DIO5 Bit Entree/Sortie14 DIO6 Bit Entree/Sortie15 DIO7 Bit Entree/Sortie16 DIO8 Bit Entree/Sortie17 REN Remote Enable18 GND Pour DAV19 GND Pour NFRD20 GND Pour NDAC21 GND Pour IFC22 GND Pour SRQ23 GND Pour ATN24 GND Logic Ground

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 6 / 42

Page 7: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

GPIB

Pins

16 pins pour signaux et 8 pins pour ground :

8 pins entree - sortie

3 pins handshake

5 pins interface

Normalement, low < 0.8V et high > 2V.

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 7 / 42

Page 8: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

GPIB

Donnees

DOI1 a DOI8 :

Permettent de transferer les adresses, controle et donnees

Adresses et controle : format definit dans IEEE-488

Donnees : pas definit par le standard ; souvent chaınes de caracteresASCII.

DOI1 est le LSB

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 8 / 42

Page 9: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

GPIB

Handshake

Controlent le transfert de messages

Permet d’accuser reception des donnees

Garanti la reception sans erreurs

NRFD (vient d’un ecouteur) : tous les dispositifs doivent etre pretavant d’envoyer donnees

NDAC (vient d’un ecouteur) : pas encore accepte les donnees. Tousles dispositifs doivent remettre a zero avant la prochaine operation.

DAV : donnees pretes a etre lues

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 9 / 42

Page 10: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

GPIB

Transmission de donnees

Quand un controleur ou transmetteur veut transmettre des donnees :

DAV = high (data not valid)

Verifier NRFD = low

Verifier NDAC = low

Si tout correct, placer donnees sur le bus

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 10 / 42

Page 11: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

GPIB

Transmission de donnees (suite...)

Les dispositifs qui recoivent des donnees vont :

Relacher NRFD

Quand tous ont relache, NRFD = high

Quand NRFD = high, controleur applique DAV = low (donneesvalides)

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 11 / 42

Page 12: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

GPIB

Transmission de donnees (suite...)

Ensuite, les receveurs vont :

NRFD = low (occupe)

Relacher NDAC lorsque les donnees sont recues

Quand le dernier relache NDAC, le controleur peut replacer DAV =high pour transmettre le prochain byte.

La vitesse depend du dispositif le plus lent.

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 12 / 42

Page 13: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

GPIB

Gestion d’interface

5 lignes de controle :

ATN (Attention) : Controle indique qu’il va placer une adresse oubyte de controle sur la ligne.

EOI (End or Identify) : Transmetteur devrait l’utiliser pour indiquer lafin de la transmission de donnees.

IFC (Interface Clear) : Pour initialisation des dispositifs

REN (Remote Enable) : Seulement pour le controleur : indique audispositif d’ignorer le panneau

SRQ (Service Request) : Comme une interruption. Le dispositifindique au controleur qu’une action est necessaire. Le controleurdetermine le dispositif par polling.

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 13 / 42

Page 14: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

GPIB

Adresses

Jusqu’a 15 dispositifs sur un bus

Adresses de 0 a 30, reglees sur le dispositif (software ou hardware)

Adresses secondaires possibles, de 0 a 30 aussi

Adresses secondaires dependent du dispositif

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 14 / 42

Page 15: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

GPIB

Transmission de donnees

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 15 / 42

Page 16: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

GPIB

Programmation

La programmation des dispositifs varie selon le manufacturier

Il y a un manuel de programmation pour chaque dispositif

Le standard GPIB n’impose pas de modele de programmation

Les commandes sont des sequences de caracteres

Ex : CH1:VOLTS 1.0E-1 regle l’affichage a 100mV/division sur lecanal 1 de l’oscilloscope Tektronics TDS 340

Ex : CH1:VOLTS? demande a l’oscilloscope quel est l’affichage ducanal 1 (reponse : 1.0E-1)

Ex : MEASure:VOLTage:AC? 20, 0.001 Indique a un multimetre demesurer la tension AC, sur une echelle de 20V, avec une resolution de0.001V, et de retourner la valeur

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 16 / 42

Page 17: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

Bus I2C

Bus I2C

Developpe par Phillips

Bus bidirectionnel a 2 fils : SDA (serial data line) et SCL (serial clockline)

Chaque dispositif sur le bus a une adresse unique

Serie, 8 bit, 100kbit/s (mode normal) ou 400kbit/s (mode rapide)

Filtre de protection sur le dispositif

Capacitance max sur la ligne de 400pF (limite le nombre dedispositifs)

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 17 / 42

Page 18: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

Bus I2C

Diagramme

174 Day 8

The Exploration The PIC32MX family offers seven communication peripherals that are designed to assist in all common embedded-control applications. As many as six of them are serialcommunication peripherals; they transmit and receive a single bit of information at a time. They are:

● 2 � the Universal Asynchronous Receiver and Transmitters (UARTs)

● 2 � the SPI synchronous serial interfaces

● 2 � the I 2 C synchronous serial interfaces

The main difference between a synchronous interface (like the SPI or I 2 C) and an asynchronous one (like the UART) is in the way the timing information is passed from transmitter to receiver. Synchronous communication peripherals need a physical line (a wire) to be dedicated to the clock signal, providing synchronization between the two devices. The device(s) that originates the clock signal is typically referred to as the master , as opposed to the device(s) that synchronizes with it, called the slave(s) .

Synchronous Serial Interfaces The I 2 C interface (see Figure 8.1 ), for example, uses two wires and therefore two pins of the microcontroller: one for the clock (SCL) and one bidirectional for the data (SDA).

PIC32I2C interface

I2C PeripheralClock (SCL)

Data (SDA) (Master) (Slave)

Figure 8.1 : I 2 C interface block diagram.

The SPI interface (see Figure 8.2 ) instead separates the data line in two, one for the input (SDI) and one for the output (SDO), requiring one extra wire but allowing simultaneous (faster) data transfer in both directions.

To connect multiple devices to the same serial communication interfaces (a bus configuration), the I 2 C interface requires a 10-bit address to be sent over the data line

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 18 / 42

Page 19: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

Bus I2C

PIC32 : Registre de controle I2C

I2CxCON :

7 : 0 GCEN STREN ACKDT ACKEN RCEN PEN RSEN SEN

15 : 8 ON FRZ SIDL SCLREL STRICT MA10M DISSLW SMEN

Bit15/7

Bit14/6

Bit13/5

Bit12/4

Bit11/3

Bit10/2

Bit9/1

Bit8/0

Les bits 16 a 31 ne sont pas utilises

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 19 / 42

Page 20: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

Bus I2C

PIC32 : I2CxCON

ON : Activation I2C : 1 = ON, 0 = OFF

FRZ : Debug : 1 = arreter execution lors de debug, 0 = continuer

SIDL : Mode IDLE : 1 = arreter si CPU en mode IDLE, 0 = continuer

SCLREL : Controle du SCL : 1 = relache horloge, 0 = force oumaintien horloge a low

STRICT : Adressage stricte : 1 = active, 0 = desactive

A10M : Adresses 10bit : 1 = adresses 10bit, 0 = adresses 7bit

DISSLW : Slew-rate : 1 = desactive, 0 = active

SMEN : Compatibilite SMBus : 1 = active, 0 = desactive

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 20 / 42

Page 21: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

Bus I2C

PIC32 : I2CxCON

GCEN : Activation Call Enable : 1 = ON, 0 = OFF

STREN : Horloge modifiee ; mode secondaire : 1 = ON, 0 = OFF

ACKDT : Acknowledge ; mode primaire : 1 = NACK, 0 = ACK

ACKEN : Acknowledge sequence : 1 = envoie bit ACKDT, 0 = OFF

RCEN : Receive enable : 1 = active, 0 = desactive

PEN : Stop enable : 1 = active, 0 = desactive

RSEN : Restart enable : 1 = active, 0 = desactive

SEN : Start enable : 1 = active, 0 = desactive

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 21 / 42

Page 22: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

Bus I2C

Connexion

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 22 / 42

Page 23: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

Bus I2C

Transfert de bit

Horloge doit etre haute pour avoir des donnees valides

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 23 / 42

Page 24: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

Bus I2C

Transfert de bits

Conditions de debut et d’arret (genere par le maıtre).Microcontroleurs doivent echantillonner a 2x l’horloge pour detecter latransition

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 24 / 42

Page 25: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

Bus I2C

Transfert de donnees

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 25 / 42

Page 26: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

Bus I2C

Transfert de donnees

Transfert complet de donnees : adresses a 7 bits, et donnees.

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 26 / 42

Page 27: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

Bus I2C

Caracteristiques electriques

−0.5 < VIL < 1.5

3 < VIH < VDD + 0.5

Tension sur la ligne typique est 5V

Courant typique de sortie : 3mA

Capacitance max de sortie 10pF par dispositif

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 27 / 42

Page 28: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

SPI

Bus SPI

SPI : Serial Peripheral Bus

Bus bidirectionnel a 4 fils :

SCK : horlogeSDO : sortie des donneesSDI : entree des donneesSS : choix du peripherique

Quelques variations possibles (nombres de fils, protocole, etc)

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 28 / 42

Page 29: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

SPI

Diagramme

Communication 175

before any actual data is transferred. This slows the communication but allows the same two wires (SCL and SDA) to be used for as many as (theoretically) 1,000 devices. Also, the I 2 C interface allows multiple devices to act as masters and share the bus using a simple arbitration protocol.

The SPI interface (see Figure 8.3 ), on the other side, requires an additional physical line, the slave select (SS), to be connected to each device. In practice this means that in using an SPI bus, as the number of connected devices grows, the number of I/O pins required on the PIC32 grows proportionally with them.

Clock

DataSDO

SDO

SDI

SDI

SCKSCK

PIC32SPI interface

SPI Peripheral

Figure 8.2 : SPI interface block diagram.

PIC32SPI interface

SPIPeripheral

(Slave #1)

SPIPeripheral

(Slave #2)

SDOSDI

SCK

SS SSSDOSDI

SCK

SDISDO

SCK

CS1

CS2

CSN

. . .

Figure 8.3 : SPI bus block diagram.

Sharing an SPI bus among multiple masters is theoretically possible but practically very rare. The main advantages of the SPI interface are truly its simplicity and the speed that can be one order of magnitude higher than that of the fastest I 2 C bus (even without taking into consideration the details of the protocol-specific overhead).

Source : Newnes

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 29 / 42

Page 30: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

SPI

Diagramme

Communication 175

before any actual data is transferred. This slows the communication but allows the same two wires (SCL and SDA) to be used for as many as (theoretically) 1,000 devices. Also, the I 2 C interface allows multiple devices to act as masters and share the bus using a simple arbitration protocol.

The SPI interface (see Figure 8.3 ), on the other side, requires an additional physical line, the slave select (SS), to be connected to each device. In practice this means that in using an SPI bus, as the number of connected devices grows, the number of I/O pins required on the PIC32 grows proportionally with them.

Clock

DataSDO

SDO

SDI

SDI

SCKSCK

PIC32SPI interface

SPI Peripheral

Figure 8.2 : SPI interface block diagram.

PIC32SPI interface

SPIPeripheral

(Slave #1)

SPIPeripheral

(Slave #2)

SDOSDI

SCK

SS SSSDOSDI

SCK

SDISDO

SCK

CS1

CS2

CSN

. . .

Figure 8.3 : SPI bus block diagram.

Sharing an SPI bus among multiple masters is theoretically possible but practically very rare. The main advantages of the SPI interface are truly its simplicity and the speed that can be one order of magnitude higher than that of the fastest I 2 C bus (even without taking into consideration the details of the protocol-specific overhead).

Source : Newnes

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 30 / 42

Page 31: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

SPI

PIC32 : Diagramme

178 Day 8

Synchronous Communication Using the SPI Modules The SPI interface is perhaps the simplest of all the available interfaces, although the PIC32 implementation is particularly rich in options and interesting features.

The SPI interface (see Figure 8.5 ) is essentially composed of a shift register. Bits are simultaneously shifted in, most significant bit (MSb) first, from the SDI line and shifted out from the SDO line in synch with the clock on the SCK pin. The size of the shift register can vary from 8, 16, or 32 bits.

InternalData Bus

SPIxBUF

SPIxTXB

Transmit

Receive

SPIxSR

bit 0SDIx

SDOx

SSx

ClockControl

ShiftControl

EdgeSelect

Baud RateGenerator

PBCLK

Enable Master ClockNote: Acces SPIxTXB and SPIxRXB registers via SPIxBUF register.

SCKx

SPIxRXB

Registers share address SPIxBUF

Slave Selectand Frame

Sync Control

Figure 8.5 : The SPI module block diagram.

If the device is configured as a bus master, the clock is generated internally, derived from the peripheral bus clock (Fpb) by a baud rate generator, and output on the SCK pin. Otherwise, the device is a bus slave and the clock is received from the SCK pin.

Source : NewnesGabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 31 / 42

Page 32: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

SPI

PIC32 : Bus SPI

Fonctionne comme un registre a decalage

Bit le plus significatif est le premier

Decalage de 8 bit, 16 bit ou 32 bit

Horloge utilise l’horloge de peripherique (Fpb)

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 32 / 42

Page 33: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

SPI

PIC32 : Registre SPI

SPIxCON :

7 : 0 SSEN CKP MSTEN — — — — —

15 : 8 ON FRZ SIDL DISSDO MODE < 1 : 0 > SMP CKE

23 : 16 — — — — — — SPIFE —

31 : 24 FRMEN FRMSYNC FRMPOL — — — — —

Bit31/23/15/7

Bit30/22/14/6

Bit29/21/13/5

Bit28/20/12/4

Bit27/19/11/3

Bit26/18/10/2

Bit25/17/9/1

Bit24/16/8/0

Les bits 0 a 15 sont suffisants pour le fonctionnement (compatibilite avecPIC16)

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 33 / 42

Page 34: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

SPI

PIC32 : SPIxCON

Bits 29–31 et 17 : Controle de cadres (mode avance)

ON : Activation SPI : 1 = ON, 0 = OFF

FRZ : Debug : 1 = arreter execution lors de debug, 0 = continuer

SIDL : Mode IDLE : 1 = arreter si CPU en mode IDLE, 0 = continuer

DISSDO : Desactiver pin SDOx : 1 = pin controlee par PORT, 0 =controle par module

MODE : Trame : 1x = 32 bits, 01 = 16 bits, 00 = 8 bits

SMP : Phase : 1 = echantillonnage a la fin de la periode, 0 =echantillonnage au milieu

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 34 / 42

Page 35: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

SPI

PIC32 : SPIxCON

CKE : Clock Edge Select : 1 = Sortie change a la transition d’horlogeactive a idle, 0 = contraire

SSEN : Choix secondaire : 1 = SSx utilise en mode secondaire, 0 =pin controlee par port

CKP : Polarite de l’horloge : 1 = idle est high, active est low ; 0 =contraire

MSTEN : Mode primaire : 1 = primaire, 0 = secondaire

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 35 / 42

Page 36: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

SPI

PIC32 : Baud rate

Registre SPIxBRG

Utilise l’horloge de peripherique Fpb

Horloge SPI :

FSCK =FPB

2(SPIxBRG+ 1)

SPIxBRG : 9 bits pour le diviseur

Ex : CPU a 80 MHz, FPBDIV=DIV 8, SPI1BRG=15 ; l’horloge SPI1 =312.5 kHz

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 36 / 42

Page 37: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

UART

Bus UART

UART : Universal Asynchronous Receiver and Transmitter

Bus asynchrone : pas d’horloge

2 fils pour transmission et reception (TX et RX)

Optionnel : 2 fils pour handshake (etablissement de liaison)

Quelques variations possibles (nombres de fils, protocole, etc)

Bits de debut et d’arret, et format de donnees fixe

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 37 / 42

Page 38: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

UART

Diagramme

176 Day 8

Asynchronous Serial Interfaces In asynchronous communication interfaces (see Figure 8.4 ), there is no clock line, whereas typically two data lines—TX and RX, respectively—are used for input and output, and optionally two more lines can be used to provide a hardware handshake. The synchronization between transmitter and receiver is obtained by extracting timing information from the data stream itself. Start and stop bits are added to the data, and precise formatting (with a fixed baud rate) must be set to allow reliable data transfers.

PIC32UART interface

AsynchronousPeripheral

Optional Handshake RTS

RTS

CTS

CTS

DataTX

TX

RX

RX

Figure 8.4 : Asynchronous serial interface block diagram.

Several asynchronous serial interface standards dictate the use of special transceivers to improve the noise immunity, extending the physical connection distance up to several thousand feet.

Each serial communication interface has its advantages and disadvantages. Table 8.1 summarizes the most important ones as well as the most common applications.

(continued)

Table 8.1 : Serial interfaces comparison table.

Synchronous Asynchronous

Peripheral SPI I2C UART

Max bit rate 20 Mbit/s 1 Mbit/s 500 kbit/s

Max bus size Limited by number of pins

128 devices Point to point (RS232), 256 devices (RS485)

Number of pins 3 � n � CS 2 2(�2)

Source : Newnes

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 38 / 42

Page 39: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

UART

Comparaison

Synchrone AsynchronePeripherique SPI I2C UART

Taux binaire max 20 Mbit/s 1 Mbit/s 500 kbit/s

Bus max Nombre de pins 128 dispositifs 256 dispositifs

Nombre de pins 3 + n×CS 2 2 (+2)

Avantages Simplefaible coutvitesse elevee

Peu de pins,permet plusieursprimaires

Longues distances

Desavantages Un primairecourte distance

Lentdistance courte

Necessite horlogeprecise

Application typique Connexion di-recte a plusieursperipheriques surle meme bus

Connexion enbus a plusieursperipheriques

Interface avecordinateurs, ter-minaux, systemesd’acquisition

Source : Newnes

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 39 / 42

Page 40: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

SMBus

SMBus

System Management Bus

Base sur I2C

Bus de controle pour systeme et controle de puissance

Originalement pour le controle de chargeurs de batterie

2 lignes : SMBCLK et SMBDAT

VDD de 3 a 5V

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 40 / 42

Page 41: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

SMBus

Differences entre I2C et SMBus

Caracteristiques electriques :

SMBus necessite la meme tension pour les dispositifs ; I2C est plusflexible

SMBus a une frequence min : 10kHz

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 41 / 42

Page 42: Gabriel Cormier, Ph.D., ing....The SPI interf ace (see Figure 8.2 ) instead separates the data line in tw o, one for the input (SDI) and one for the output (SDO), requiring one extra

SMBus

Differences entre I2C et SMBus

Minuterie :

SMBus : 50µs entre relache du maıtre et demande d’etre maıtre anouveau

I2C : pas de delai min

SMBus : 2ms temps max pour SCL bas ; I2C : pas de contrainte

Protocole de communication plus strict pour SMBus

Gabriel Cormier (UdeM) GELE5343 Chapitre 4 Hiver 2013 42 / 42