arduino com SPI

Submitted by gautama on Thu, 02/13/2020 - 15:22


debutant en arduino qui pourrait m'indiquer si le codage de la com SPI est correcte, merci pour votre aide.

#include <SPI.h>         //lien pour fair appel a la bibliothéque SPI
SPISettings settingA (20000000, MSBFIRST, SPI_MODE0);  //parametre de communication vitesse, lecture du bits le plus fort au plus faible, mode de transmission

const int pin_Esclave_Spi = 9;       //broche que le maitre utilise pour activer le peripherique souhaiter en l'occurance le CNA 
int Serial_Clock_SPI = 13;           //les impulsions de l'horloge qui synchronisent la transsmission de donnée générée par le maitre
int Mosi_Conv_SPI = 11;              //envoie de donnée au péripherique
int Miso = 12;                       //envoie de donnée au maitre

void setup() {

pinMode(pin_Esclave_Spi, OUTPUT);
  SPI.begin();   // lancer la bibliotheque SPI

void loop() { 

 digitalWrite(Relai_NC_5V_Jauge, HIGH);           //si vrai, alors j'envoie une impulsion sur le relai NC pour couper l'alimentation de la jauge et je coupe la communication SPI (superflue ?)
    SPI.end ();

digitalWrite(Relai_NC_5V_Jauge, LOW);
  SPI.beginTransaction (SPISettings(settingA));

SPI.beginTransaction (SPISettings(settingA));
                     //PARAMETRE COM SPI     
  digitalWrite (pin_Esclave_Spi , LOW ) ;                 // envoie la valeur via SPI:
  delay ( 100 ) ; 
  SPI.transfer ( valeur_Sortie[Index] ) ; 
 delay ( 100 ) ; 
                                                               //couper la communication
  digitalWrite (pin_Esclave_Spi , HIGH ) ; 
  delay ( 1000 );  





Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by microcontrollers for communicating with one or more peripheral devices quickly over short distances. It can also be used for communication between two microcontrollers.

With an SPI connection there is always one master device (usually a microcontroller) which controls the peripheral devices. Typically there are three lines common to all the devices.
The SPI standard is loose and each device implements it a little differently. This means you have to pay special attention to the device's datasheet when writing your code.

Generally speaking, there are four modes of transmission. These modes control whether data is shifted in and out on the rising or falling edge of the data clock signal, and whether the clock is idle when high or low (called the clock polarity). The four modes combine polarity and phase according to this table.

  Joined November 07, 2019      124
Thursday at 04:25 PM