56
SPI - Serial Peripheral Interface Pour aller lire le CAN et écrire dans le CNA

SPI - Serial Peripheral Interface

  • Upload
    una

  • View
    39

  • Download
    1

Embed Size (px)

DESCRIPTION

SPI - Serial Peripheral Interface. Pour aller lire le CAN et écrire dans le CNA. Schéma bloc. Chronogrammes. Mode 0. Mode 1. Chronogrammes. Mode 2. Mode 3. Chronogramme d’une transaction. Chronogramme d’une transaction. Registre des modes du SPI. Exemple initialisation du SPI. - PowerPoint PPT Presentation

Citation preview

Page 1: SPI - Serial  Peripheral  Interface

SPI - Serial Peripheral Interface

Pour aller lire le CAN et écrire dans le CNA

Page 2: SPI - Serial  Peripheral  Interface

2

Schéma bloc

Page 3: SPI - Serial  Peripheral  Interface

3

Page 4: SPI - Serial  Peripheral  Interface

4

Page 5: SPI - Serial  Peripheral  Interface

5

Page 6: SPI - Serial  Peripheral  Interface

6

Chronogrammes

Mode 0

Mode 1

Page 7: SPI - Serial  Peripheral  Interface

7

Chronogrammes

Mode 2

Mode 3

Page 8: SPI - Serial  Peripheral  Interface

8

Chronogramme d’une transaction

Page 9: SPI - Serial  Peripheral  Interface

9

Chronogramme d’une transaction

Page 10: SPI - Serial  Peripheral  Interface

10

Page 11: SPI - Serial  Peripheral  Interface

11

Page 12: SPI - Serial  Peripheral  Interface

12

Registre des modes du SPI

Page 13: SPI - Serial  Peripheral  Interface

13

Page 14: SPI - Serial  Peripheral  Interface

14

Page 15: SPI - Serial  Peripheral  Interface

15

Page 16: SPI - Serial  Peripheral  Interface

16

Page 17: SPI - Serial  Peripheral  Interface

17

Page 18: SPI - Serial  Peripheral  Interface

18

Page 19: SPI - Serial  Peripheral  Interface

19

Page 20: SPI - Serial  Peripheral  Interface

20

Page 21: SPI - Serial  Peripheral  Interface

21

Page 22: SPI - Serial  Peripheral  Interface

22

Page 23: SPI - Serial  Peripheral  Interface

23

Page 24: SPI - Serial  Peripheral  Interface

24

Exemple initialisation du SPI

Page 25: SPI - Serial  Peripheral  Interface

25

Exemple initialisation du SPI

Page 26: SPI - Serial  Peripheral  Interface

26

Configuration du SPI 1) Associer les broches au SPI:

Exemple SPI #1: PIO_Configure(pinsSPI1, PIO_LISTSIZE(pinsSPI1));

Page 27: SPI - Serial  Peripheral  Interface

27

Configuration du SPI 2) Configuration des registres SPI_CR et

SPI_MR: Structure:

config = (AT91C_SPI_DLYBCS & (0 << 24)) | (AT91C_SPI_PCS & (0xE << 16)) | (AT91C_SPI_LLB & (0 << 7)) | (AT91C_SPI_MODFDIS & (1 << 4)) | (AT91C_SPI_PCSDEC & (0 << 2)) | (AT91C_SPI_PS & (1 << 1)) | (AT91C_SPI_MSTR & (1 << 0));

SPI_Configure(AT91C_BASE_SPI1, AT91C_ID_SPI1, config);

Page 28: SPI - Serial  Peripheral  Interface

28

Configuration du SPI 2) Configuration des registres SPI_CR et SPI_MR

: Structure:

config = (AT91C_SPI_DLYBCS & (0 << 24)) | (AT91C_SPI_PCS & (0xE << 16)) | (AT91C_SPI_LLB & (0 << 7)) | (AT91C_SPI_MODFDIS & (1 << 4)) | (AT91C_SPI_PCSDEC & (0 << 2)) | (AT91C_SPI_PS & (1 << 1)) | (AT91C_SPI_MSTR & (1 << 0));

SPI_Configure(AT91C_BASE_SPI1, AT91C_ID_SPI1, config);

Maitre ou esclave

Sélection périphérique comm.

Décodage périphériqueDétection de fautes« Local loopback »

« Chip select » périphérique

Délais entre « chip select »

Page 29: SPI - Serial  Peripheral  Interface

29

Configuration du SPI 2) Configuration du registre SPI_CSR3:

Structure: config = (AT91C_SPI_DLYBCT & (0x01 << 24)) | (AT91C_SPI_DLYBS & (0x01 << 16)) | (AT91C_SPI_SCBR & (0x10 << 8)) | (AT91C_SPI_BITS & (AT91C_SPI_BITS_16)) | (AT91C_SPI_CSAAT & (0x0 << 3)) | (AT91C_SPI_NCPHA & (0x0 << 1)) | (AT91C_SPI_CPOL & (0x1 << 0));

SPI_ConfigureNPCS(AT91C_BASE_SPI1, 3, config);

Page 30: SPI - Serial  Peripheral  Interface

30

Configuration du SPI 2) Configuration du registre SPI_CSR3 :

Structure: config = (AT91C_SPI_DLYBCT & (0x01 << 24)) | (AT91C_SPI_DLYBS & (0x01 << 16)) | (AT91C_SPI_SCBR & (0x10 << 8)) | (AT91C_SPI_BITS & (AT91C_SPI_BITS_16)) | (AT91C_SPI_CSAAT & (0x0 << 3)) | (AT91C_SPI_NCPHA & (0x0 << 1)) | (AT91C_SPI_CPOL & (0x1 << 0));

SPI_ConfigureNPCS(AT91C_BASE_SPI1, 3, config);

Polarité de l’horloge du SPI

Phase de l’horloge

Chip select actif après trans. ?

Taille du transfert (16 bits)

Vitesse communicationDélai avant SPCK

Délai entre 2 transactions

CNA

Page 31: SPI - Serial  Peripheral  Interface

31

Configuration du SPI 2b) Configuration du registre SPI_CSR2 :

… SPI_ConfigureNPCS(AT91C_BASE_SPI1, 2, config);

3) Activation du SPI: Directement (pour le SPI #1):

SPI_Enable(AT91C_BASE_SPI1);

Tout cela peut se regrouper dans une fonction que nous pouvons nommer: void initSPI(void){ … }

CAN

Page 32: SPI - Serial  Peripheral  Interface

32

MAX5322Convertisseur numérique analogique

Page 33: SPI - Serial  Peripheral  Interface

33

Montage de laboratoire

Page 34: SPI - Serial  Peripheral  Interface

34

MAX5322 – Schéma bloc

Page 35: SPI - Serial  Peripheral  Interface

35

CNA MAX5322 – Conversion R-2R

Page 36: SPI - Serial  Peripheral  Interface

36

Page 37: SPI - Serial  Peripheral  Interface

37

Page 38: SPI - Serial  Peripheral  Interface

38

Page 39: SPI - Serial  Peripheral  Interface

39

Tensions en sortie

Page 40: SPI - Serial  Peripheral  Interface

40

Configuration du CNA

Page 41: SPI - Serial  Peripheral  Interface

41

Configuration broches MAX5322SetupDAC()

Déclaration

variables

Board

.h

Page 42: SPI - Serial  Peripheral  Interface

42

Suite

Broche LDAC mise à 1

Broche CLR mise à 1

Broche UNI/BIP A mise à 0

Broche UNI/BIP B mise à 1

Broche SHDN mise à 1

Page 43: SPI - Serial  Peripheral  Interface

43

Transactions du SPI avec le CNA Initialisation du CNA

SPI_Write(AT91C_BASE_SPI1, 3, 0xE000); SPI_Read(AT91C_BASE_SPI1); Wait(1000);

SPI_Write(AT91C_BASE_SPI1, 3, (0x4000 | 0x07FF));

SPI_Read(AT91C_BASE_SPI1);

Activations des canaux du CNA

Canal A – DAC_OUT

0 volt

Page 44: SPI - Serial  Peripheral  Interface

44

Transactions du SPI avec le CNA Initialisation du CNA

SPI_Write(AT91C_BASE_SPI1, 3, 0xE000); SPI_Read(AT91C_BASE_SPI1); Wait(1000);

SPI_Write(AT91C_BASE_SPI1, 3, (0x4000 | 0x07FF)); SPI_Read(AT91C_BASE_SPI1);

SPI_Write(AT91C_BASE_SPI1, 3, (0x5000 | 0x0000)); SPI_Read(AT91C_BASE_SPI1);

Activations des canaux du CNA

Canal A – DAC_OUT

0 volt

Canal B - VSHIFT0 volt

Page 45: SPI - Serial  Peripheral  Interface

45

MAX1270Convertisseur analogique numérique

Page 46: SPI - Serial  Peripheral  Interface

46

Montage de laboratoire

Page 47: SPI - Serial  Peripheral  Interface

47

MAX1270 – Schéma de la puce

Page 48: SPI - Serial  Peripheral  Interface

48

MAX1270 – Schéma bloc interne

Page 49: SPI - Serial  Peripheral  Interface

49

CAN MAX1270

Page 50: SPI - Serial  Peripheral  Interface

50

Page 51: SPI - Serial  Peripheral  Interface

51

Page 52: SPI - Serial  Peripheral  Interface

52

Étendues et polarités

Page 53: SPI - Serial  Peripheral  Interface

53

Transaction avec le CAN

Page 54: SPI - Serial  Peripheral  Interface

54

Transaction avec le CAN

Pour une lecture du CAN, il faut faire deux transactions. La première envoie le numéro du canal à lire; Exemple: 0x9100

START = 1 Canal choisi: 0x001 – Canal 1 RNG = 1 et BIP = 0: Sortie monopolaire; PD1 = 0 et PD0 = 0: Opération normale, horloge

interne.

Réponse du convertisseur: les 3 premiers bits du CAN.

Page 55: SPI - Serial  Peripheral  Interface

55

Transaction avec le CAN

Pour une lecture du CAN, il faut faire deux transactions. La deuxième est pour permettre de recevoir le reste; Réponse du convertisseur: les 9 derniers bits du CAN.

Canaux: Canal 0 : 0x8D00 -> Borne J6 Canal 1: 0x9100 -> Vshift Canal 2: 0xA100 -> Thermocouple Canal 3: 0xB100 -> Puce LM35

Page 56: SPI - Serial  Peripheral  Interface

56

Initialisation du CAN Faite lors de l’initialisation du SPI #1.

Associer les broches du SPI #1 pour le CAN