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.
Diff: main.cpp
- Revision:
- 1:6f8bf5bdc70f
- Parent:
- 0:bcbc14441ee8
- Child:
- 2:654aafc318bf
- Child:
- 3:35151308f847
diff -r bcbc14441ee8 -r 6f8bf5bdc70f main.cpp --- a/main.cpp Wed May 17 09:53:25 2017 +0000 +++ b/main.cpp Wed May 17 10:12:31 2017 +0000 @@ -1,12 +1,94 @@ #include "mbed.h" +#include "rtos.h" + +#define SIG_RX_CAN 0x01 + + +DigitalOut led1(LED1); +DigitalOut led2(LED2); -DigitalOut myled(LED1); +Thread threadA; +Thread threadB; + + +CAN CanPort(p30, p29); +CANMessage MessageRx; +CANMessage MessageTx; + +unsigned int Id; -int main() { - while(1) { - myled = 1; - wait(0.2); - myled = 0; - wait(0.2); + +void canReader(void) +{ + + + if (CanPort.read(MessageRx)) + { + led1 = !led1; + threadA.signal_set(SIG_RX_CAN); + } + +} + + +void thA() +{ + while(true) + { + Thread::signal_wait(SIG_RX_CAN); + led2 = !led2; + printf("RX FRAME ID = %X\n\r",MessageRx.id); + } } + +void thB() +{ + while (true) + { + led1 = !led1; + printf("TIC3s\n\r"); + MessageTx.id=Id; + CanPort.write(MessageTx); + + if (Id < 0x3FF) Id++; + else Id = 0x000; + + wait(3); + } +} + + + +int main() +{ + CanPort.frequency(20000); + + Id = 0x1A5; + MessageTx.len=2; + MessageTx.data[0] = 0x55; + MessageTx.data[1] = 0xAA; + + MessageTx.format = CANStandard; + //MessageTx.format = CANExtended; + + MessageTx.type = CANData; + //MessageTx.type = CANRemote; + + CanPort.attach(canReader,CAN::RxIrq); + + threadA.start(thA); + threadB.start(thB); + + led1 = 0; + printf("Start OK\n\r"); + LocalFileSystem local("local"); + FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing + fprintf(fp, "Hello World!"); + fclose(fp); + + while (true) + { + + } +}