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.
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 00004 DigitalOut led1(LED1); 00005 DigitalOut led2(LED2); 00006 CAN can1(p9, p10); 00007 CAN can2(p30, p29); 00008 00009 00010 //Premier message CAN à envoyer 00011 void sendCan1(void const *args) 00012 { 00013 00014 char counter1 = 80; 00015 00016 while(1) { 00017 00018 00019 printf("send()\n"); 00020 if(can1.write(CANMessage(0x0480, &counter1, 1))) { 00021 printf("wloop()\n"); 00022 00023 printf("Message sent: %d\n", counter1); 00024 counter1++; 00025 } 00026 if (counter1 >89) { 00027 counter1 = 80; 00028 } 00029 led1 = !led1; 00030 Thread::wait(1842); 00031 } 00032 } 00033 00034 00035 //Deuxième message CAN à envoyer 00036 void sendCan2(void const *args) 00037 { 00038 00039 char counter2 = 180; 00040 00041 while(1) { 00042 printf("send()\n"); 00043 if(can1.write(CANMessage(0x0580,&counter2,1))) { 00044 printf("wloop()\n"); 00045 00046 printf("Message sent: %d\n", counter2); 00047 counter2++; 00048 } 00049 if (counter2 >189) { 00050 counter2 = 180; 00051 } 00052 led1 = !led1; 00053 Thread::wait(2351); 00054 } 00055 } 00056 00057 //Réception du message 00058 void receptionMsg(void const *args) 00059 { 00060 00061 CANMessage msg; 00062 00063 while(1) { 00064 printf("reception()\n"); 00065 if(can2.read(msg)) 00066 printf("Message received: %x\n", msg.id); 00067 if (msg.id == 1234) //Filtre pour recevoir le message voulu et le bon data 00068 printf("Message received: %d\n", msg.data[0]); 00069 Thread::wait(958); 00070 led2 = !led2; 00071 } 00072 } 00073 00074 int main() 00075 { 00076 // Fonction principale qui prend en loop les 3 thread 00077 printf("main()\n"); 00078 00079 Thread thread1(sendCan1); 00080 Thread thread2(sendCan2); 00081 Thread thread3(receptionMsg); 00082 while(true); 00083 00084 }
Generated on Wed Jul 20 2022 23:27:01 by
1.7.2