Gerardo Antonio
/
CANnucleo_Hello3
CAN a enviar_TLMoto
Fork of CANnucleo_Hello by
main.cpp
- Committer:
- Crazyaboutmachines
- Date:
- 2016-06-26
- Revision:
- 14:ff9c77b97bad
- Parent:
- 13:77261ea62081
- Child:
- 15:b1d0bf2626ed
File content as of revision 14:ff9c77b97bad:
#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; Serial pc(SERIAL_TX, SERIAL_RX); int main() { can1.frequency(100000); // set bit rate to 1Mbps can2.frequency(100000); // set bit rate to 1Mbps led = 1; // turn LED on pc.printf("pcprintf check"); 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)) { // pc.printf("Message received: %d\n", rxMsg.data[0]); pc.printf("Message received: %d\n"); led = !led; } } }