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.
Revision 1:8a9ac822aab7, committed 2018-06-18
- Comitter:
- open4416
- Date:
- Mon Jun 18 06:50:24 2018 +0000
- Parent:
- 0:c4747ebbe0b4
- Child:
- 2:c7a3a8c1aeed
- Commit message:
- Add auxiliary control to cooling system
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat May 26 16:03:33 2018 +0000
+++ b/main.cpp Mon Jun 18 06:50:24 2018 +0000
@@ -1,47 +1,54 @@
#include "mbed.h"
-Ticker ticker;
-CAN can1(PB_5, PB_13, 1000000);
-CAN can2(PA_11, PA_12, 1000000);
+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 CAN1_RX(void);
-void CAN2_RX(void);
+void CAN_RX1(void);
+void CAN_RX2(void);
int main()
{
CAN_flag_1 = 0;
CAN_flag_2 = 0;
-
- can1.attach(&CAN1_RX, CAN::RxIrq); //CAN1 Recieve Irq
- can2.attach(&CAN2_RX, CAN::RxIrq); //CAN2 Recieve Irq
+
+ can1.attach(&CAN_RX1, CAN::RxIrq); //CAN1 Recieve Irq
+ can2.attach(&CAN_RX2, CAN::RxIrq); //CAN2 Recieve Irq
while(1) {
- while(CAN_flag_1 == 1) {
- can2.write(can_msg_1);
+ if(CAN_flag_1) {
+// Led = RTD_State;
+ Cool = RTD_State;
+ pc.printf("%d\r", RTD_State);
CAN_flag_1 = 0;
}
- while(CAN_flag_2 == 1) {
- can1.write(can_msg_2);
- CAN_flag_2 = 0;
- }
}
}
-void CAN1_RX(void)
+void CAN_RX1(void)
{
if(can1.read(can_msg_1)) {
- CAN_flag_1 = 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 CAN2_RX(void)
+
+void CAN_RX2(void)
{
if(can2.read(can_msg_2)) {
- CAN_flag_2 = 1;
}
}
\ No newline at end of file