SHENG-HEN HSIEH
/
VDU_2021
Just a regular publish
main.cpp
- Committer:
- open4416
- Date:
- 2018-06-18
- Revision:
- 1:8a9ac822aab7
- Parent:
- 0:c4747ebbe0b4
- Child:
- 2:c7a3a8c1aeed
File content as of revision 1:8a9ac822aab7:
#include "mbed.h" DigitalOut Cool(PA_15,0); //DigitalOut Led(D13,0); CAN can1(PA_11, PA_12, 1000000); //(Inverter, PadalBox, DashBoard) 1Mbps, contain critical torque command message CAN can2(PB_5, PB_13, 500000); //(BMS1, BMS2) 500kbps, contain battery status Serial pc(USBTX, USBRX, 115200); CANMessage can_msg_1; CANMessage can_msg_2; uint8_t CAN_flag_1 = 0; uint8_t CAN_flag_2 = 0; uint8_t RTD_State = 0; // use as bool void CAN_RX1(void); void CAN_RX2(void); int main() { CAN_flag_1 = 0; CAN_flag_2 = 0; can1.attach(&CAN_RX1, CAN::RxIrq); //CAN1 Recieve Irq can2.attach(&CAN_RX2, CAN::RxIrq); //CAN2 Recieve Irq while(1) { if(CAN_flag_1) { // Led = RTD_State; Cool = RTD_State; pc.printf("%d\r", RTD_State); CAN_flag_1 = 0; } } } void CAN_RX1(void) { if(can1.read(can_msg_1)) { switch(can_msg_1.id) { //Filtered the input message and do corresponding action case 0xAA: //Internal state address RTD_State = can_msg_1.data[6] & 0x01; //get bit "0", result ( 1 = RTD, 0 = OFF ) CAN_flag_1 = 1; break; } } } void CAN_RX2(void) { if(can2.read(can_msg_2)) { } }