Pi-WiringPi-Reference-SpiBus

De MCHobby - Wiki
Révision datée du 12 octobre 2013 à 20:52 par Admin (discussion | contributions) (Page créée avec « {{Pi-WiringPi-NAV}} == Librairie SPI == WiringPi includes a library which can make it easier to use the Raspberry Pi’s on-board SPI interface. Before you can use SPI int... »)
(diff) ← Version précédente | Voir la version actuelle (diff) | Version suivante → (diff)
Sauter à la navigation Sauter à la recherche


MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.

Librairie SPI

WiringPi includes a library which can make it easier to use the Raspberry Pi’s on-board SPI interface.

Before you can use SPI interface, you may need to use the gpio utility to load the SPI drivers into the kernel:

gpio load spi

If you need a buffer size of greater than 4KB, then you can specify the size (in KB) on the command line:

gpio load spi 100

will allocate a 100KB buffer. (You should rarely need this though, the default is more than enough for most applications).

To use the SPI library, you need to:

  1. include <wiringPiSPI.h>

in your program. Programs need to be linked with -lwiringPi as usual.

Fonctions

Une fois wiringPiSPI inclus, les fonctions suivantes sont disponibles:

wiringPiSPISetup

int wiringPiSPISetup(int channel, int speed);

This is the way to initialise a channel (The Pi has 2 channels; 0 and 1). The speed parameter is an integer in the range 500,000 through 32,000,000 and represents the SPI clock speed in Hz.

The returned value is the Linux file-descriptor for the device, or -1 on error. If an error has happened, you may use the standard errno global variable to see why.

wiringPiSPIDataRW

   int wiringPiSPIDataRW(int channel, unsigned char *data, int len);

This performs a simultaneous write/read transaction over the selected SPI bus. Data that was in your buffer is overwritten by data returned from the SPI bus.

That’s all there is in the helper library. It is possible to do simple read and writes over the SPI bus using the standard read() and write() system calls though – write() may be better to use for sending data to chains of shift registers, or those LED strings where you send RGB triplets of data. Devices such as A/D and D/A converters usually need to perform a concurrent write/read transaction to work.



Source: WiringPi.com. WiringPi est une libraire sous licence GPL écrite par Gordon Henderson. Crédit: wiringpi.com

Traduit de l'anglais par Meurisse D. pour MCHobby.be

Traduit avec l'accord de Gordon Henderson, créateur de wiringPi - Translated with authorization of Gordon Henderson, creator of wiringPi

Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : «  Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.

L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.