Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of testCAN2 by
main.cpp
00001 #include "mbed.h" 00002 #include "C12832.h" 00003 // LR 10/02/18 00004 // 00005 // bus CAN generateur de trames 00006 // 00007 // Emission d'une trame parmi 4 selection à l'aide du pot1 00008 // eviter les positions intermédaires du pot1 ! 00009 // !! emission sur CAN2 p30Rx p29Tx 00010 // Attention si pas d'ACK faire reset après chaque changement 00011 // J'ai constaté des comportements bizarre dans cette situation 00012 // Des infos sur la liaison série 00013 // La trame est envoyée aussi sur LCD 00014 // 00015 // testé à l'analyseur logique = OK !! 00016 // 00017 // 00018 00019 00020 DigitalOut led1(LED1); 00021 DigitalOut led2(LED2); 00022 CAN can1(p9, p10,1000000);// on definit pin et debit 00023 CAN can2(p30, p29, 1000000); 00024 Serial pc(USBTX, USBRX); 00025 AnalogIn pot_1(p19); // potard pour selection 00026 C12832 lcd(p5, p7, p6, p8, p11); // lcd 00027 00028 00029 void send(int id, char octet_emis[], char RouD, char longueur ) 00030 { 00031 int emis_ok = 0 ; 00032 CANMessage msg; 00033 if (RouD == 'D') 00034 { emis_ok = can2.write(CANMessage(id, octet_emis, longueur, CANData, CANStandard )) ; 00035 pc.printf("id: %x, %c L = %d, \nData : %x:%x:%x:%x ... \n", id,RouD,longueur,octet_emis[0],octet_emis[1], octet_emis[2], octet_emis[3] ); 00036 }// c'ets la valeur retournée par la fonction write 00037 else 00038 { emis_ok = can2.write(CANMessage(id, octet_emis, longueur, CANRemote, CANStandard )); 00039 pc.printf("id: %x, %c L = %d, \nData : %x:%x:%x:%x ... \n", id,RouD,longueur,octet_emis[0],octet_emis[1], octet_emis[2], octet_emis[3] ); 00040 } 00041 lcd.locate(0,10); 00042 lcd.printf("id: %x, %c L = %d, \nData : %x:%x:%x:%x ... \n", id,RouD,longueur,octet_emis[0],octet_emis[1], octet_emis[2], octet_emis[3] ); 00043 if(emis_ok) { 00044 // ici octet emis n'a pas de sens car trame remote ! 00045 pc.printf("j'emets bien !!! \n"); 00046 } 00047 led1 = !led1; 00048 } 00049 00050 00051 00052 00053 int main() { 00054 int choix = 0 ; 00055 int i = 0 ; 00056 00057 char octet_send[9] = "DDDDDDDD"; // valeurs par defaut D=44 00058 int identif = 0x123 ; // par défaut 00059 char RemoteData = 'D' ; 00060 char length = 2 ; 00061 00062 00063 printf("main()\n"); 00064 lcd.cls(); 00065 00066 00067 while(1) { 00068 choix= 5*pot_1.read(); 00069 lcd.locate(0,0); 00070 lcd. printf("Trame %d \n", choix); 00071 switch (choix) 00072 { // debut sw 00073 case (0): // Trame qui passe le noeud 15 en Operationnal state 00074 { identif = 0x00 ; 00075 octet_send[0] = 0x01 ; 00076 octet_send[1] = 0x15 ; 00077 RemoteData = 'D'; 00078 length = 2 ; 00079 break ; 00080 } // fin case 0 00081 case (1): // Trame qui passe le noeud 20 en Operationnal state 00082 { identif = 0x00 ; 00083 octet_send[0] = 0x01 ; 00084 octet_send[1] = 0x20 ; 00085 RemoteData = 'D'; 00086 length = 2 ; 00087 break ; 00088 } // fin case 1 00089 case (2): // trame qui ping le noeud 15 00090 { identif = 0x715 ; 00091 for(i=0;i<9;i++) 00092 { octet_send[i]='D';} // 44 en hexa par defaut 00093 RemoteData = 'R'; 00094 length = 0 ; 00095 break ; 00096 } // fin case 2 00097 case (3): // trame qui ping le noeud 20 00098 { identif = 0x720 ; 00099 for(i=0;i<9;i++) 00100 { octet_send[i]='D';} // 44 en hexa par defaut 00101 RemoteData = 'R'; 00102 length = 0 ; 00103 break ; 00104 } // fin case 3 00105 00106 default : // 4 ou 5 00107 { identif = 0x123 ; 00108 for(i=0;i<9;i++) 00109 { octet_send[i]='D';} // 44 en hexa par defaut 00110 RemoteData = 'D'; 00111 length = 8 ; 00112 break ; 00113 } // fin default 00114 00115 } // fin switch 00116 00117 send(identif, octet_send, RemoteData, length ); 00118 wait(1); 00119 }// fin while(1) 00120 00121 } // fin main 00122 00123 /* 00124 00125 printf("loop()\n"); 00126 if(can2.read(msg)) { 00127 printf("Message received: %d\n", msg.data[0]); 00128 led2 = !led2; 00129 } 00130 wait(0.2); 00131 } 00132 } */ 00133
Generated on Thu Jul 28 2022 23:47:42 by
1.7.2
