IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Arduino Discussion :

Mesurer l'état du bus de communication


Sujet :

Arduino

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Avril 2020
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Marne (Champagne Ardenne)

    Informations professionnelles :
    Activité : Technicien maintenance

    Informations forums :
    Inscription : Avril 2020
    Messages : 1
    Par défaut Mesurer l'état du bus de communication
    Bonjour,

    Je viens vers vous pour avoir de l'aide, je souhaiterai pouvoir décoder les trames qui passent sur un bus d'interphonie de ma maison afin de me notifier lorsque l'on a sonner.
    Pour se faire j'ai commencé à faire des essais avec un arduino, en utilisant un comparateur pour mesurer les temps des états haut et bas afin de pouvoir convertir en 0 et 1.
    Ce bus de communication alimente en même temps le combiné intérieur avec une tension permanente de 18V.
    J'arrive bien à récupérer des temps lors des changements d'état mais il me manque beaucoup d'informations je n'arrive pas à savoir pourquoi.

    Ci-joint les copies d'écran de oscilloscope

    Nom : Oscillo.jpg
Affichages : 190
Taille : 93,6 KoNom : Oscillo2.jpg
Affichages : 177
Taille : 99,4 Ko

    les valeurs des tenions sont à multiplier par 10

    Nom : PulseView.jpg
Affichages : 171
Taille : 57,1 Ko

    Concernant le schéma :

    Nom : IMG_6239.jpg
Affichages : 184
Taille : 743,0 Ko

    Le code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    #define outputPin 5
     
    #define startBit 6//ms
    #define oneBit 4//ms
    #define zeroBit 2//ms
     
    volatile uint32_t CMD = 0;
    volatile uint8_t lengthCMD = 0;
    volatile bool cmdReady;
     
    ISR(ANALOG_COMP_vect ) {
     
      static uint32_t curCMD;
      static uint32_t usLast;
      static byte curCRC;
      static byte calCRC;
      static byte curLength;
      static byte cmdIntReady;
      static byte curPos;
      uint32_t usNow = micros();
      uint32_t timeInUS = usNow - usLast;
      usLast = usNow;
      byte curBit = 4;
       Serial.println(timeInUS);
      if (timeInUS < 1000) {
        curBit = 5; // invalid glitches typical 29ms
      } else if (timeInUS >= 1000 && timeInUS <= 2999) {
        curBit = 0;
      } else if (timeInUS >= 3000 && timeInUS <= 4999) {
        curBit = 1;
      } else if (timeInUS >= 5000 && timeInUS <= 6999) {
        curBit = 2;
      } else if (timeInUS >= 7000 && timeInUS <= 24000) {
        curBit = 3;
        curPos = 0;
      }
     
      if (curBit != 5) { // skip processing for glitches
        if (curPos == 0) {
          if (curBit == 2) {
            curPos++;
          }
          curCMD = 0;
          curCRC = 0;
          calCRC = 1;
          curLength = 0;
        } else if (curBit == 0 || curBit == 1) {
          if (curPos == 1) {
            curLength = curBit;
            curPos++;
          } else if (curPos >= 2 && curPos <= 17) {
            if (curBit)bitSet(curCMD, (curLength ? 33 : 17) - curPos);
            calCRC ^= curBit;
            curPos++;
          } else if (curPos == 18) {
            if (curLength) {
              if (curBit)bitSet(curCMD, 33 - curPos);
              calCRC ^= curBit;
              curPos++;
            } else {
              curCRC = curBit;
              cmdIntReady = 1;
            }
          } else if (curPos >= 19 && curPos <= 33) {
            if (curBit)bitSet(curCMD, 33 - curPos);
            calCRC ^= curBit;
            curPos++;
          } else if (curPos == 34) {
            curCRC = curBit;
            cmdIntReady = 1;
          }
        } else {
          curPos = 0;
        }
        if (cmdIntReady) {
          cmdIntReady = 0;
          curPos = 0;
          if (curCRC == calCRC) {
            cmdReady = 1;
            lengthCMD = curLength;
            CMD = curCMD;
          }
          curCMD = 0;
        }
      }
    }
     
    void setup() {
      Serial.begin(9600);
      pinMode(outputPin, OUTPUT);
     ACSR =
       (0 << ACD) |    // Analog Comparator: Enabled
       (0 << ACBG) |   // Analog Comparator Bandgap Select: AIN0 is applied to the positive input
       (0 << ACO) |    // Analog Comparator Output: Off
       (1 << ACI) |    // Analog Comparator Interrupt Flag: Clear Pending Interrupt
       (1 << ACIE) |   // Analog Comparator Interrupt: Enabled
       (0 << ACIC) |   // Analog Comparator Input Capture: Disabled
       (0 << ACIS1) | (0 << ACIS0);   // Analog Comparator Interrupt Mode: Comparator Interrupt on changing Edge
    }
     
    String inData;
    void loop()
    {
      while (Serial.available() > 0)
      {
        char aChar = Serial.read();
        if (aChar == 0x04)
        {
          analyzeInString(inData);
        }
        else if (aChar == 0x01)
        {
          inData = "";
        } else {
          inData += aChar;
        }
      }
      if (cmdReady) {
        cmdReady = 0;
        Serial.write(0x01);
        Serial.print("$");
        printHEX(CMD);
        Serial.write(0x04);
        Serial.println();
      }
    }
     
    void analyzeInString(String inString) {
      if (inString.length() > 0) {
        if (inString == "(01") {
          SendeSerCMD("#");
        } else if (inString == ".3F") {
          SendeSerCMD(".222222222");
        } else if (inString.substring(0, 1) == " ") {
          sendeProtokollHEX((uint32_t)strtoul(&inString[1], NULL, 16));
        }
      }
    }
     
    void SendeSerCMD(String outString) {
      Serial.write(0x01);
      Serial.print(outString);
      Serial.write(0x04);
    }
     
    //it is better to also give an arg with the length because it 
    //is possible that there is a 4Byte protokoll smaller than 0xFFFF
    //something like void sendeProtokollHEX(uint32_t protokoll,byte firstBit) {
    //  int length = 16;
    //  byte checksm = 1;
    //  if (firstBit) length = 32;
    //and so on...
    void sendeProtokollHEX(uint32_t protokoll) {
      int length = 16;
      byte checksm = 1;
      byte firstBit = 0;
      if (protokoll > 0xFFFF) {
        length = 32;
        firstBit = 1;
      }
      digitalWrite(outputPin, HIGH);
      delay(startBit);
      digitalWrite(outputPin, !digitalRead(outputPin));
      delay(firstBit ? oneBit : zeroBit);
      int curBit = 0;
      for (byte i = length; i > 0; i--) {
        curBit = bitRead(protokoll, i - 1);
        digitalWrite(outputPin, !digitalRead(outputPin));
        delay(curBit ? oneBit : zeroBit);
        checksm ^= curBit;
      }
      digitalWrite(outputPin, !digitalRead(outputPin));
      delay(checksm ? oneBit : zeroBit);
      digitalWrite(outputPin, LOW);
    }
     
    void printHEX(uint32_t DATA) {
      uint8_t numChars = lengthCMD ? 8 :4;
      uint32_t mask  = 0x0000000F;
      mask = mask << 4 * (numChars - 1);
      for (uint32_t i = numChars; i > 0; --i) {
        Serial.print(((DATA & mask) >> (i - 1) * 4), HEX);
        mask = mask >> 4;
      }
    }

    Le résultat :

    Nom : Sans titre.jpg
Affichages : 173
Taille : 19,5 Ko

    Si vous avez des idées ou si jamais une personne à déjà travailler sur ce sujet je suis preneur
    Merci par avance

  2. #2
    Expert confirmé

    Homme Profil pro
    mad scientist :)
    Inscrit en
    Septembre 2019
    Messages
    2 899
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Etats-Unis

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 899
    Par défaut
    si c'est un protocole connu, un outil d'analyse de trame comme https://www.saleae.com/fr/ pourrait vous aider

Discussions similaires

  1. communication entre [tsx3721] [tsx3705]par bus [unitelway]?
    Par sukhoimk dans le forum Automation
    Réponses: 0
    Dernier message: 23/04/2012, 20h25
  2. Serveur RED5-communication état de connexion
    Par javass dans le forum Dynamique
    Réponses: 0
    Dernier message: 20/02/2009, 12h19
  3. Communication via bus pc/104
    Par Benzebuth dans le forum Matériel
    Réponses: 5
    Dernier message: 17/02/2009, 17h03
  4. Bus USB : Communication
    Par snoopy69 dans le forum VB 6 et antérieur
    Réponses: 6
    Dernier message: 02/02/2009, 12h54
  5. Etat avec sous-état et variable commune
    Par Alain6121967 dans le forum IHM
    Réponses: 1
    Dernier message: 30/03/2007, 11h46

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo