+ Post New Thread
Results 1 to 4 of 4
  1. #1
    Member level 4
    Points: 770, Level: 6

    Join Date
    Apr 2017
    Posts
    68
    Helped
    1 / 1
    Points
    770
    Level
    6

    CAN ID receive issue in PIC18F46K80

    Hello All,

    i Am working on J1939 Project where i am getting extended ID(Length is 6 byte - for ex: 14FF4431) from CAN but where i am receiving to my controler i don't wanted first 2 bytes and last 2 bytes, i required center 4 bytes(FF44).
    i am using Mikroc Library & PIC46k80 Controller.

    my CAN ID is "long" in data type.

    Please help me to solve
    -- Expecting answer in C language/Embedded C
    - Thanks in advance!

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 77,800, Level: 68
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,765
    Helped
    3590 / 3590
    Points
    77,800
    Level
    68

    Re: CAN ID receive issue in PIC18F46K80

    Hi,

    Length is 6 byte - for ex: 14FF4431
    14FF4431 ....
    * if HEX, then this are 4 bytes
    * if ASCII, then this us 8 bytes
    I don't see 6 bytes

    , i required center 4 bytes(FF44).
    FF44 ... as HEX are just 2 bytes.

    Klaus
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.


    1 members found this post helpful.

    •   AltAdvertisement

        
       

  3. #3
    Member level 4
    Points: 770, Level: 6

    Join Date
    Apr 2017
    Posts
    68
    Helped
    1 / 1
    Points
    770
    Level
    6

    Re: CAN ID receive issue in PIC18F46K80

    Quote Originally Posted by KlausST View Post
    Hi,


    14FF4431 ....
    * if HEX, then this are 4 bytes
    * if ASCII, then this us 8 bytes
    I don't see 6 bytes


    FF44 ... as HEX are just 2 bytes.

    Klaus
    Yeah, i mean its in HEX. Ya its 4 Bytes.
    I want to remove first byte(14) and Last byte (31).
    How its is possible ?

    Please help me out.

    - - - Updated - - -

    This is working in C:


    #include <stdio.h>

    int main()
    {
    long Rx_ID = 0x14FF4431;
    long Rx_ID1,Rx_ID2;


    Rx_ID2 = ((Rx_ID>>8)&0xFF);
    Rx_ID1 = ((Rx_ID>>16)&0xFF);
    Rx_ID = (Rx_ID1<<8)|(Rx_ID2);

    printf("%x",Rx_ID);

    return 0;
    }

    Output:
    FF44

    But, When i am using in mikroC i am not getting correct value, see below
    converting long to string, to check data at UART:

    Rx_ID2 = ((Rx_ID>>8)&0xFF);
    Rx_ID1 = ((Rx_ID>>16)&0xFF);
    Rx_ID = (Rx_ID1<<8)|(Rx_ID2);
    LongToStr(Rx_ID, Ch_Rx_ID);
    UART1_Write_Text(Ch_Rx_ID);
    Last edited by desgin; 10th August 2019 at 07:18.



    •   AltAdvertisement

        
       

  4. #4
    Super Moderator
    Points: 77,800, Level: 68
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,765
    Helped
    3590 / 3590
    Points
    77,800
    Level
    68

    Re: CAN ID receive issue in PIC18F46K80

    Hi,

    Pseudo code:
    long Rx_ID = 0x14FF4431;
    Rx_ID = ((Rx_ID AND 0x00FFFF00) >>8)

    Result should be 0xFF44

    Klaus
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.


    1 members found this post helpful.

--[[ ]]--