for HTTP-3A

Dependencies:   mbed TextLCD

Committer:
thomasya
Date:
Thu Jul 11 09:03:23 2019 +0000
Revision:
3:043e5e06f325
Parent:
1:ec61ea9f67de
Child:
4:c1438ffd88dd
CAN OK

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thomasya 3:043e5e06f325 1 #include "mbed.h"
thomasya 3:043e5e06f325 2
thomasya 3:043e5e06f325 3 CAN can1(PB_8, PB_9);
thomasya 3:043e5e06f325 4 Serial pc(USBTX, USBRX, 115200);
thomasya 3:043e5e06f325 5 AnalogIn res(PA_0);
group-ST 0:6e8275981824 6
thomasya 3:043e5e06f325 7 Ticker ticker1;
thomasya 3:043e5e06f325 8
thomasya 3:043e5e06f325 9 CANMessage can_msg_1;
thomasya 3:043e5e06f325 10 CANMessage can_msg_send;
thomasya 3:043e5e06f325 11 char data_msg[3] = {0x11,0x22,0x33};
thomasya 3:043e5e06f325 12 bool armed = false;
group-ST 0:6e8275981824 13
thomasya 3:043e5e06f325 14
thomasya 3:043e5e06f325 15
thomasya 3:043e5e06f325 16 void CAN_RX1(void);
group-ST 0:6e8275981824 17
thomasya 3:043e5e06f325 18 void sendCMD(void)
thomasya 3:043e5e06f325 19 {
thomasya 3:043e5e06f325 20 //if(armed)
thomasya 3:043e5e06f325 21
thomasya 3:043e5e06f325 22 can_msg_send = CANMessage(0x111,data_msg,3,CANData,CANStandard);
thomasya 3:043e5e06f325 23 can1.write(can_msg_send);
thomasya 3:043e5e06f325 24
thomasya 3:043e5e06f325 25 //printf("res: %f\n", res.read());
thomasya 3:043e5e06f325 26 }
group-ST 0:6e8275981824 27
group-ST 0:6e8275981824 28 int main()
group-ST 0:6e8275981824 29 {
thomasya 3:043e5e06f325 30
thomasya 3:043e5e06f325 31
thomasya 3:043e5e06f325 32 can1.attach(&CAN_RX1, CAN::RxIrq); //CAN1 Recieve Irq
thomasya 3:043e5e06f325 33 ticker1.attach(&sendCMD, 1); //1sec
thomasya 3:043e5e06f325 34 pc.printf("start\n");
thomasya 3:043e5e06f325 35
thomasya 3:043e5e06f325 36 can1.frequency(500000);
thomasya 3:043e5e06f325 37 while(1)
thomasya 3:043e5e06f325 38 {
thomasya 3:043e5e06f325 39
thomasya 3:043e5e06f325 40 /*if(can1.read(can_msg_1))
thomasya 3:043e5e06f325 41 {
thomasya 3:043e5e06f325 42 printf("Message received: %d\n", can_msg_1.data[1]);
thomasya 3:043e5e06f325 43 }
thomasya 3:043e5e06f325 44 */
thomasya 3:043e5e06f325 45
thomasya 3:043e5e06f325 46
thomasya 3:043e5e06f325 47 }
thomasya 3:043e5e06f325 48
thomasya 3:043e5e06f325 49 }
thomasya 3:043e5e06f325 50
thomasya 3:043e5e06f325 51
thomasya 3:043e5e06f325 52
thomasya 3:043e5e06f325 53 void CAN_RX1(void)
thomasya 3:043e5e06f325 54 {
thomasya 3:043e5e06f325 55 if(can1.read(can_msg_1))
thomasya 3:043e5e06f325 56 {
thomasya 3:043e5e06f325 57 pc.printf("CAN RX %d\n", can_msg_1.id);
thomasya 3:043e5e06f325 58
group-ST 0:6e8275981824 59 }
group-ST 0:6e8275981824 60 }