Nemanja Neskovic
/
canrxamk
can amk
Revision 2:306861df19f5, committed 2019-04-11
- Comitter:
- nemanja1994
- Date:
- Thu Apr 11 08:23:20 2019 +0000
- Parent:
- 1:41d392ac86e9
- Commit message:
- can amk
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
mbed.bld | Show annotated file Show diff for this revision Revisions of this file |
diff -r 41d392ac86e9 -r 306861df19f5 main.cpp --- a/main.cpp Fri Apr 05 08:02:30 2019 +0000 +++ b/main.cpp Thu Apr 11 08:23:20 2019 +0000 @@ -1,16 +1,97 @@ #include "mbed.h" -CAN can1(PA_11, PA_12, 100000); +CAN can(PA_11, PA_12, 500000); Serial pc(PC_10,PC_11,19200); CANMessage msg; +int flag; +int counter=1; +char sen[8]={0x00,0x07,0x00,0x00,0x00,0x00,0x00,0x00}; +char reset[8]={0x00,0x08,0x00,0x00,0x00,0x00,0x00,0x00}; +char niz[8]={0x00,0x07,0x1e,0x00,0xE8,0x03,0x00,0x00}; + +CANMessage can283; +CANMessage can285; + +Ticker ticker; + +Ticker ticker2; + +Ticker ticker3; + +void CANMsgReceive(){ // CAN RX Interrupt Function + CANMessage tmpMsg; + if (can.read(tmpMsg)) { //Detect message + //pc.printf("%x\n",tmpMsg.id); + if(tmpMsg.id==0x283) { + can283=tmpMsg; + //pc.printf("id: %x %x %x \n",tmpMsg.id,tmpMsg.data[0],tmpMsg.data[1]); + } + else if (tmpMsg.id==0x285) can285=tmpMsg; + //pc.printf("%x %x \n",can283.data[0],can283.data[1]); + } +}; + +void send_reset() { + //printf("send()\n"); + if(can.write(CANMessage(0x184, reset, 8))) { + //pc.printf("wloop()\n"); + //counter++; + pc.printf("Message sent: %d\n", 1); + } +} +void send_en() { + //printf("send()\n"); + if(can.write(CANMessage(0x184, sen, 8))) { + //pc.printf("wloop()\n"); + //counter++; + pc.printf("Message sent: %d\n", 2); + } +} +void send_setpoint() { + //printf("send()\n"); + if(can.write(CANMessage(0x184, niz, 8))) { + //pc.printf("wloop()\n"); + //counter++; + pc.printf("Message sent: %d\n", 3); + } +} + int main() { - pc.printf("PILETINA SE ZA PRSTE LEPI!\n"); + can.attach(&CANMsgReceive,CAN::RxIrq); + + //ticker.attach_us(send_reset,5000); + while(1){ + can.write(CANMessage(0x184,reset,8)); + wait_ms(10); + pc.printf("cao\n"); + pc.printf("id:%x %x %x \n",can283.id,can283.data[0],can283.data[1]); + if((can283.data[1])==1){ + //pc.printf("%x %x \n",can283.data[0],can283.data[1]); + //ticker.detach(); + //ticker.attach_us(send_en,5000); + break; + } + } + while(1){ + can.write(CANMessage(0x184,sen,8)); + wait_ms(10); + pc.printf("ej\n"); + pc.printf("id:%x %x %x \n",can283.id,can283.data[0],can283.data[1]); + if((can283.data[1])==0x79){ + //ticker.detach(); + //ticker.attach_us(send_setpoint,5000); + break; + } + } + + while(1) { - //printf("loop()\n"); - if(can1.read(msg)) { - pc.printf("Mmmmmm, jarac kazes?"); - pc.printf(" Id: %d\n",msg.data[0]); - }; + can.write(CANMessage(0x184,niz,8)); + wait_ms(10); + pc.printf("ooj\n"); + pc.printf("id:%x %x %x \n",can283.id,can283.data[2],can283.data[3]); + pc.printf("id:%x %x %x \n",can283.id,can283.data[4],can283.data[5]); + pc.printf("id:%x %x %x \n",can283.id,can283.data[6],can283.data[7]); }; }; \ No newline at end of file
diff -r 41d392ac86e9 -r 306861df19f5 mbed.bld --- a/mbed.bld Fri Apr 05 08:02:30 2019 +0000 +++ b/mbed.bld Thu Apr 11 08:23:20 2019 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/users/mbed_official/code/mbed/builds/5571c4ff569f \ No newline at end of file +https://os.mbed.com/users/mbed_official/code/mbed/builds/ff21514d8981 \ No newline at end of file