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@0:a291f7cc08f8, 2017-05-15 (annotated)
- Committer:
- alexis66
- Date:
- Mon May 15 09:37:02 2017 +0000
- Revision:
- 0:a291f7cc08f8
- Child:
- 1:d940df294833
Programme de test Connectivit? noeud CAN 2017.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
alexis66 | 0:a291f7cc08f8 | 1 | #include "mbed.h" |
alexis66 | 0:a291f7cc08f8 | 2 | #include "rtos.h" |
alexis66 | 0:a291f7cc08f8 | 3 | |
alexis66 | 0:a291f7cc08f8 | 4 | #define SIG_RX_CAN 0x01 |
alexis66 | 0:a291f7cc08f8 | 5 | |
alexis66 | 0:a291f7cc08f8 | 6 | |
alexis66 | 0:a291f7cc08f8 | 7 | DigitalOut led1(LED1); |
alexis66 | 0:a291f7cc08f8 | 8 | DigitalOut led2(LED2); |
alexis66 | 0:a291f7cc08f8 | 9 | |
alexis66 | 0:a291f7cc08f8 | 10 | Thread threadA; |
alexis66 | 0:a291f7cc08f8 | 11 | Thread threadB; |
alexis66 | 0:a291f7cc08f8 | 12 | |
alexis66 | 0:a291f7cc08f8 | 13 | |
alexis66 | 0:a291f7cc08f8 | 14 | CAN CanPort(p30, p29); |
alexis66 | 0:a291f7cc08f8 | 15 | CANMessage MessageRx; |
alexis66 | 0:a291f7cc08f8 | 16 | CANMessage MessageTx; |
alexis66 | 0:a291f7cc08f8 | 17 | |
alexis66 | 0:a291f7cc08f8 | 18 | unsigned int Id; |
alexis66 | 0:a291f7cc08f8 | 19 | |
alexis66 | 0:a291f7cc08f8 | 20 | |
alexis66 | 0:a291f7cc08f8 | 21 | void canReader(void) |
alexis66 | 0:a291f7cc08f8 | 22 | { |
alexis66 | 0:a291f7cc08f8 | 23 | |
alexis66 | 0:a291f7cc08f8 | 24 | |
alexis66 | 0:a291f7cc08f8 | 25 | if (CanPort.read(MessageRx)) |
alexis66 | 0:a291f7cc08f8 | 26 | { |
alexis66 | 0:a291f7cc08f8 | 27 | led1 = !led1; |
alexis66 | 0:a291f7cc08f8 | 28 | threadA.signal_set(SIG_RX_CAN); |
alexis66 | 0:a291f7cc08f8 | 29 | } |
alexis66 | 0:a291f7cc08f8 | 30 | |
alexis66 | 0:a291f7cc08f8 | 31 | } |
alexis66 | 0:a291f7cc08f8 | 32 | |
alexis66 | 0:a291f7cc08f8 | 33 | |
alexis66 | 0:a291f7cc08f8 | 34 | void thA() |
alexis66 | 0:a291f7cc08f8 | 35 | { |
alexis66 | 0:a291f7cc08f8 | 36 | while(true) |
alexis66 | 0:a291f7cc08f8 | 37 | { |
alexis66 | 0:a291f7cc08f8 | 38 | Thread::signal_wait(SIG_RX_CAN); |
alexis66 | 0:a291f7cc08f8 | 39 | led2 = !led2; |
alexis66 | 0:a291f7cc08f8 | 40 | printf("RX FRAME ID = %X\n",MessageRx.id); |
alexis66 | 0:a291f7cc08f8 | 41 | |
alexis66 | 0:a291f7cc08f8 | 42 | } |
alexis66 | 0:a291f7cc08f8 | 43 | } |
alexis66 | 0:a291f7cc08f8 | 44 | |
alexis66 | 0:a291f7cc08f8 | 45 | void thB() |
alexis66 | 0:a291f7cc08f8 | 46 | { |
alexis66 | 0:a291f7cc08f8 | 47 | while (true) |
alexis66 | 0:a291f7cc08f8 | 48 | { |
alexis66 | 0:a291f7cc08f8 | 49 | led1 = !led1; |
alexis66 | 0:a291f7cc08f8 | 50 | printf("TIC3s\n"); |
alexis66 | 0:a291f7cc08f8 | 51 | MessageTx.id=Id; |
alexis66 | 0:a291f7cc08f8 | 52 | CanPort.write(MessageTx); |
alexis66 | 0:a291f7cc08f8 | 53 | |
alexis66 | 0:a291f7cc08f8 | 54 | if (Id < 0x3FF) Id++; |
alexis66 | 0:a291f7cc08f8 | 55 | else Id = 0x000; |
alexis66 | 0:a291f7cc08f8 | 56 | |
alexis66 | 0:a291f7cc08f8 | 57 | wait(3); |
alexis66 | 0:a291f7cc08f8 | 58 | } |
alexis66 | 0:a291f7cc08f8 | 59 | } |
alexis66 | 0:a291f7cc08f8 | 60 | |
alexis66 | 0:a291f7cc08f8 | 61 | |
alexis66 | 0:a291f7cc08f8 | 62 | |
alexis66 | 0:a291f7cc08f8 | 63 | int main() |
alexis66 | 0:a291f7cc08f8 | 64 | { |
alexis66 | 0:a291f7cc08f8 | 65 | CanPort.frequency(20000); |
alexis66 | 0:a291f7cc08f8 | 66 | |
alexis66 | 0:a291f7cc08f8 | 67 | Id = 0x1A5; |
alexis66 | 0:a291f7cc08f8 | 68 | MessageTx.len=2; |
alexis66 | 0:a291f7cc08f8 | 69 | MessageTx.data[0] = 0x55; |
alexis66 | 0:a291f7cc08f8 | 70 | MessageTx.data[1] = 0xAA; |
alexis66 | 0:a291f7cc08f8 | 71 | |
alexis66 | 0:a291f7cc08f8 | 72 | MessageTx.format = CANStandard; |
alexis66 | 0:a291f7cc08f8 | 73 | //MessageTx.format = CANExtended; |
alexis66 | 0:a291f7cc08f8 | 74 | |
alexis66 | 0:a291f7cc08f8 | 75 | MessageTx.type = CANData; |
alexis66 | 0:a291f7cc08f8 | 76 | //MessageTx.type = CANRemote; |
alexis66 | 0:a291f7cc08f8 | 77 | |
alexis66 | 0:a291f7cc08f8 | 78 | CanPort.attach(canReader,CAN::RxIrq); |
alexis66 | 0:a291f7cc08f8 | 79 | |
alexis66 | 0:a291f7cc08f8 | 80 | threadA.start(thA); |
alexis66 | 0:a291f7cc08f8 | 81 | threadB.start(thB); |
alexis66 | 0:a291f7cc08f8 | 82 | |
alexis66 | 0:a291f7cc08f8 | 83 | led1 = 0; |
alexis66 | 0:a291f7cc08f8 | 84 | printf("Start OK\n"); |
alexis66 | 0:a291f7cc08f8 | 85 | |
alexis66 | 0:a291f7cc08f8 | 86 | while (true) |
alexis66 | 0:a291f7cc08f8 | 87 | { |
alexis66 | 0:a291f7cc08f8 | 88 | |
alexis66 | 0:a291f7cc08f8 | 89 | } |
alexis66 | 0:a291f7cc08f8 | 90 | } |