[SOLVED] CAN ID receive issue in PIC18F46K80

Status
Not open for further replies.

desgin

Full Member level 1
Joined
Apr 7, 2017
Messages
96
Helped
1
Reputation
2
Reaction score
1
Trophy points
8
Activity points
813
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!
 

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
 
Reactions: desgin

    desgin

    Points: 2
    Helpful Answer Positive Rating
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:

Hi,

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

Result should be 0xFF44

Klaus
 
Reactions: desgin

    desgin

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…