![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
CAN a enviar_TLMoto
Fork of CANnucleo_Hello by
main.cpp
- Committer:
- Crazyaboutmachines
- Date:
- 2016-06-26
- Revision:
- 13:77261ea62081
- Parent:
- 12:4f5cec652e77
- Child:
- 14:ff9c77b97bad
File content as of revision 13:77261ea62081:
#include "mbed.h" #include "CAN.h" // const unsigned int TX_ID = 0x101; const unsigned int TX_ID = 0x155; //em binario: 101010101 DigitalOut led(PA_5); int ledState; CAN can1(PA_11, PA_12); // CAN Rx pin name, CAN Tx pin name CAN can2(PB_12, PB_13); // CAN Rx pin name, CAN Tx pin name CANMessage txMsg; CANMessage rxMsg; int counter = 0; int main() { can1.frequency(100000); // set bit rate to 1Mbps can2.frequency(100000); // set bit rate to 1Mbps led = 1; // turn LED on while(1) { wait(10); counter++; // increment counter // ledState = led.read(); // get led state ledState = 1; txMsg.clear(); // clear Tx message storage txMsg.id = TX_ID; // set ID (9 bits) txMsg << counter; // append first data item (32? bits?=4bytes) txMsg << ledState; // append second data item (total data lenght must be <= 8 bytes!) (=4bytes) can1.write(txMsg); // if(can1.write(txMsg)) // transmit message // led = 1; // turn LED on // else // led = 0; // turn LED off if(can2.read(rxMsg)) { //printf("Message received: %d\n", msg.data[0]); led = !led; } } }