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 :

Reseau CAN Probleme d'adresse et message


Sujet :

Arduino

  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Mars 2010
    Messages
    41
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2010
    Messages : 41
    Par défaut Reseau CAN Probleme d'adresse et message
    Bonjour,

    je travaille actuellement à lire des valeurs sur un réseau CAN J1939,
    J'utilise un arduino MEGA 2560 et une interface CAN à base de MCP2515,

    Je lis bien ce qui passe sur le réseau, cependant, l'afflux de données est impressionnant et le MEGA se plante ou les messages importants ne sont pas toujours lus.

    Donc, en regardant les exemples, j'ai vu (lib: MCP_CAN), que l'on pouvait filtrer les données à recevoir.

    Lorsque je capture les données, j'ai des ID qui ressemblent à cela:
    Nom : Page sniffer donnees binaires.png
Affichages : 705
Taille : 17,4 Ko

    Mais quand je regarde les exemples de Filtre et masque, les adresses n'ont rien à voir !
    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
     
    // MCP2515 Mask and Filter example for standard CAN message frames.
    // Written by Cory J. Fowler (20140717)
     
    /***********************************************************************************
    If you send the following standard IDs below to an Arduino loaded with this sketch
    you will find that 0x102 and 0x105 will not get in.
     
    ID in Hex  -   Two Data Bytes!   -  Filter/Mask in HEX
       0x100   + 0000 0000 0000 0000 =   0x01000000
       0x101   + 0000 0000 0000 0000 =   0x01010000
       0x102   + 0000 0000 0000 0000 =   0x01020000  This example will NOT be receiving this ID
       0x103   + 0000 0000 0000 0000 =   0x01030000
       0x104   + 0000 0000 0000 0000 =   0x01040000
       0x105   + 0000 0000 0000 0000 =   0x01050000  This example will NOT be receiving this ID
       0x106   + 0000 0000 0000 0000 =   0x01060000
       0x107   + 0000 0000 0000 0000 =   0x01070000
     
       This mask will check the filters against ID bit 8 and ID bits 3-0.   
        MASK   + 0000 0000 0000 0000 =   0x010F0000
       
       If there is an explicit filter match to those bits, the message will be passed to the
       receive buffer and the interrupt pin will be set.
       This example will NOT be exclusive to ONLY the above frame IDs, for that a mask such
       as the below would be used: 
        MASK   + 0000 0000 0000 0000 = 0x07FF0000
        
       This mask will check the filters against all ID bits and the first data byte:
        MASK   + 1111 1111 0000 0000 = 0x07FFFF00
       If you use this mask and do not touch the filters below, you will find that your first
       data byte must be 0x00 for the message to enter the receive buffer.
       
       At the moment, to disable a filter or mask, copy the value of a used filter or mask.
       
       Data bytes are ONLY checked when the MCP2515 is in 'MCP_STDEXT' mode via the begin
       function, otherwise ('MCP_STD') only the ID is checked.
    ***********************************************************************************/
     
     
    #include <mcp_can.h>
    #include <SPI.h>
     
    long unsigned int rxId;
    unsigned char len = 0;
    unsigned char rxBuf[8];
     
    MCP_CAN CAN0(10);                          // Set CS to pin 10
     
    void setup()
    {
      Serial.begin(115200);
      if(CAN0.begin(MCP_STDEXT, CAN_500KBPS, MCP_16MHZ) == CAN_OK) Serial.print("MCP2515 Init Okay!!\r\n");
      else Serial.print("MCP2515 Init Failed!!\r\n");
      pinMode(2, INPUT);                       // Setting pin 2 for /INT input
     
     
      CAN0.init_Mask(0,0,0x010F0000);                // Init first mask...
      CAN0.init_Filt(0,0,0x01000000);                // Init first filter...
      CAN0.init_Filt(1,0,0x01010000);                // Init second filter...
     
      CAN0.init_Mask(1,0,0x010F0000);                // Init second mask... 
      CAN0.init_Filt(2,0,0x01030000);                // Init third filter...
      CAN0.init_Filt(3,0,0x01040000);                // Init fouth filter...
      CAN0.init_Filt(4,0,0x01060000);                // Init fifth filter...
      CAN0.init_Filt(5,0,0x01070000);                // Init sixth filter...
     
      Serial.println("MCP2515 Library Mask & Filter Example...");
      CAN0.setMode(MCP_NORMAL);                // Change to normal mode to allow messages to be transmitted
    }
     
    void loop()
    {
        if(!digitalRead(2))                    // If pin 2 is low, read receive buffer
        {
          CAN0.readMsgBuf(&rxId, &len, rxBuf); // Read data: len = data length, buf = data byte(s)
          Serial.print("ID: ");
          Serial.print(rxId, HEX);
          Serial.print(" Data: ");
          for(int i = 0; i<len; i++)           // Print each byte of the data
          {
            if(rxBuf[i] < 0x10)                // If data byte is less than 0x10, add a leading zero
            {
              Serial.print("0");
            }
            Serial.print(rxBuf[i], HEX);
            Serial.print(" ");
          }
          Serial.println();
        }
    }
     
    /*********************************************************************************************************
    END FILE
    *********************************************************************************************************/
    Donc, j'en viens donc à la question:

    Comment puis adapter mes adresses pour qu'elles correspondent.

    Pour information, je souhaiterai filtrer la page: 10FF4E0B
    Et quelle forme doit avoir le filtre et le masque ?


    Merci à vous,

    Bonne journée,

  2. #2
    Expert confirmé

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

    Informations professionnelles :
    Activité : mad scientist :)

    Informations forums :
    Inscription : Septembre 2019
    Messages : 2 897
    Par défaut
    Bonjour

    Le MCP2515 possède trois buffers de transmission et deux en réception auxquels sont associés un masque d'acceptation chacun plus six filtres d'acceptation (en tout). Voir le chapitre 4 (MESSAGE RECEPTION) de la datasheet

    Peut-être cette vieille discussion peut vous aider

  3. #3
    Membre actif
    Profil pro
    Inscrit en
    Février 2010
    Messages
    87
    Détails du profil
    Informations personnelles :
    Localisation : Algérie

    Informations forums :
    Inscription : Février 2010
    Messages : 87
    Par défaut
    Slm

    pour recevoir uniquement l'id 10FF4E0B sont filtre est 1FE9C160 et le masque tous en FFFFFFFF ,

    bon chance

Discussions similaires

  1. Probleme d'adresse IP dans un réseau wifi
    Par CodeurNé dans le forum Réseau
    Réponses: 2
    Dernier message: 20/11/2006, 14h06
  2. [reseau] probleme d'adresse ip
    Par kornographie dans le forum Windows XP
    Réponses: 4
    Dernier message: 02/08/2006, 00h18
  3. Probleme d'adresse
    Par mael94420 dans le forum ASP
    Réponses: 11
    Dernier message: 14/06/2005, 11h13
  4. probleme iis - adresse ip
    Par roots_man dans le forum ASP
    Réponses: 2
    Dernier message: 04/11/2004, 13h32

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