-3

i start making my own obd2 reader with stm32f303k8 and MCP2551 transciever CAN BUS . For that i start with CubeMX for configuration and Keil using Hal functions but i still trying to get data from car.. until i found stm32f10x code who remplace elm327 function and work with AT Command but creating with standard peripheral library ..

Here is the code https://github.com/ARoozitalab/ELM327-OBDII-STM32

now i want just to know how to replace this code with hal library of stm32f3 because ST delete the standard peripheral library for stm32f3

Can i merge between CMSIS libraries and Hal functions ?

i tried to rebuild the project with hal library and add copy OBD.C in my code but i think that i need to make some changes in Config.h

3 Answers3

1

i will help you with a sequence to learn OBDII protocols

at the first you should know about ECU of your car. maybe that ECU dont support CAN portocol(ISO 15765) and so you cant read your ecu with CAN

what is your ecu model?

i suggest you at first in the cube mx build a project , enable one serial and can

then enable your CAN protovcol interrupt

at the CAN interrupt handler use this example code:

    CanRxMsg RxMessage;
    CanTxMsg TxMessage;
  /* receive */
  CAN_Receive(CAN1, CAN_FIFO0, &RxMessage);
        printf("idv: %u ",RxMessage.IDE);
        printf("exID: %04X ",RxMessage.ExtId);
        printf("ID: %03X ",RxMessage.StdId);
        printf("DLC: %02X ",RxMessage.DLC);

        printf("DATA:");
  for(i=0;i<RxMessage.DLC;i++) 
     { 

        printf(" %02X ",RxMessage.Data[i]); 

     }

        printf("\r\n");

this code convert CAN received massage to serial (your serial baud rate should be 115200)(and your CAN baud rate must be 500k) then connect the board to a serial monitor on your PC you should see internal car send an receive massage like :

idv: 0 exID: 80012CC ID: 43F DLC: 08 DATA: 00  40  60  FF  68  48  09  00 
idv: 0 exID: 80012CC ID: 580 DLC: 08 DATA: 00  00  00  00  00  00  00  00 
idv: 0 exID: 80012CC ID: 440 DLC: 08 DATA: FF  00  00  00  FF  47  09  00 
idv: 0 exID: 80012CC ID: 580 DLC: 08 DATA: 00  00  00  00  00  00  00  00 
idv: 0 exID: 80012CC ID: 545 DLC: 08 DATA: 80  47  00  8B  00  00  00  00 
idv: 0 exID: 80012CC ID: 690 DLC: 08 DATA: 00  00  00  00  00  00  0C  00 
idv: 0 exID: 80012CC ID: 7DF DLC: 08 DATA: 02  01  0C  00  00  00  00  00 
idv: 0 exID: 80012CC ID: 7E8 DLC: 08 DATA: 04  41  0C  09  C8  00  00  00 
idv: 0 exID: 80012CC ID: 545 DLC: 08 DATA: 80  00  00  8A  00  00  00  00 
idv: 0 exID: 80012CC ID: 580 DLC: 08 DATA: 00  00  00  00  00  00  00  00 
idv: 0 exID: 80012CC ID: 440 DLC: 08 DATA: FF  00  00  00  FF  4D  09  00 
idv: 0 exID: 80012CC ID: 580 DLC: 08 DATA: 00  00  00  00  00  00  00  00 
idv: 0 exID: 80012CC ID: 545 DLC: 08 DATA: 80  00  00  8C  00  00  00  00 
idv: 0 exID: 80012CC ID: 440 DLC: 08 DATA: FF  00  00  00  FF  4F  09  00 
idv: 0 exID: 80012CC ID: 580 DLC: 08 DATA: 00  00  00  00  00  00  00  00 
idv: 0 exID: 80012CC ID: 440 DLC: 08 DATA: FF  00  00  00  FF  52  09  00 
idv: 0 exID: 80012CC ID: 545 DLC: 08 DATA: 80  00  00  8A  00  00  00  00 
idv: 0 exID: 80012CC ID: 580 DLC: 08 DATA: 00  00  00  00  00  00  00  00 
idv: 0 exID: 80012CC ID: 690 DLC: 08 DATA: 00  00  00  00  00  00  10  00 
idv: 0 exID: 80012CC ID: 7DF DLC: 08 DATA: 02  01  0C  00  00  00  00  00 
idv: 0 exID: 80012CC ID: 329 DLC: 08 DATA: 86  BD  6B  10  11  20  00  14 
idv: 0 exID: 80012CC ID: 7E8 DLC: 08 DATA: 04  41  0C  09  DC  00  00  00 
 ...
0

you can see CAN functions on OBDII.C at the first src detect OBDII protocols and init the port after that ,when you want send or receive OBDII data, src use the detected protocol to connect OBDII

so CAN functions are in the low level of OBDII.C

-1

thanks a lot for your response ! i am sure that my car have CAN-BUS .. i will try your exemple to see if there are data in the serial .. i want to know also why in your Main.C you call for bluetooth & K-Line Function .. but you dont call the CAN Function ?