Paul Paterson / CanNucleoF0_example

Dependencies:   mbed-src-CanNucleoF0

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

Go to the documentation of this file.
00001 
00002 /** @file
00003  *  @brief main program entry
00004  */
00005  
00006 #include "mbed.h"
00007 
00008 DigitalOut boardLed (LED1);
00009 Ticker inputScanner;
00010 int volatile input;
00011 
00012 void InputScan ()
00013 {
00014     boardLed = !boardLed;
00015 }
00016 
00017 int main()
00018 {
00019     printf ("\r\n----- MAIN -----\r\n");
00020     
00021     /* blinker task*/
00022     boardLed = 0;
00023     input = 0;
00024     inputScanner.attach_us (&InputScan, 50000);
00025 
00026     /*=========================================================================
00027      * test echo
00028      *=========================================================================
00029      */
00030     CAN can (PA_11, PA_12);
00031     
00032     char counter = 255;
00033     if (! (can.write (CANMessage (1337, &counter, 1)))) {
00034         printf ("can.write FAILURE!\r\n");
00035     }
00036     counter = 0;
00037     
00038     CANMessage msgRx;
00039     
00040     printf ("----- READY -----\r\n");
00041     while (1) {
00042         if (can.read (msgRx)) {
00043             
00044             printf("Message received: %d ", msgRx.data[0]);
00045             wait (0.4); printf(".");
00046             wait (0.4); printf(".");
00047             wait (0.4); printf(". \r\n");
00048             
00049             counter++;            
00050             if (! (can.write (CANMessage (1337, &counter, 1)))) {
00051                 printf ("can.write FAILURE!\r\n");
00052             }
00053         }
00054         
00055         wait (0.05);
00056     }
00057 }