• AVR Freaks

Hot!PIC18F4580 CAN Test

Author
newbie_pic
Starting Member
  • Total Posts : 39
  • Reward points : 0
  • Joined: 2019/07/05 19:39:30
  • Location: India
  • Status: offline
2020/03/10 06:33:36 (permalink)
0

PIC18F4580 CAN Test

Hi, I am working on CAN communication. I wrote a test code to test the same. I am using two nodes Node-1 and Node-2. The standard ID is used for communication. Node-1 is given ID = 10 and Node-2 is given ID = 20. Using Mode 0 (Legacy Mode) for communication. The problem is, both the nodes will send/receive data but received data is some junk. To check values of each register for better understanding I had displayed registers like COMSTAT, TXB0CON, TXERRCNT, RXB0CON and RXERRCNT.
 
I am using acceptance filter 0 on both the nodes. But when displayed RXB0CON its showing 0x01 instead of 0x00 i.e data is received from filter 1 to buffer. Hence displaying some junk. How to solve this issue?
#1

11 Replies Related Threads

    crosland
    Super Member
    • Total Posts : 1886
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: PIC18F4580 CAN Test 2020/03/10 06:48:57 (permalink)
    +1 (3)
    Do you want answers here, or here: https://www.microchip.com/forums/m1130708.aspx
     
    Posting the same question in different places will not get you a better answer.
     
    #2
    newbie_pic
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2019/07/05 19:39:30
    • Location: India
    • Status: offline
    Re: PIC18F4580 CAN Test 2020/03/10 06:58:56 (permalink)
    0 (2)
    So, How can I ? Not able to move forward got stuck.
     
    while (1)
    {
         got_stuck();
    }

    post edited by newbie_pic - 2020/03/10 07:04:24
    #3
    orlandocarvalho
    New Member
    • Total Posts : 9
    • Reward points : 0
    • Joined: 2020/03/09 07:14:40
    • Location: 0
    • Status: offline
    Re: PIC18F4580 CAN Test 2020/03/10 08:51:15 (permalink)
    -1 (1)
    Hey, i have the same problem, i want to use a button connected to node 1 to turn on a led into a node 2.
    I need some suggestions :)
     
    #4
    pcbbc
    Super Member
    • Total Posts : 1649
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: PIC18F4580 CAN Test 2020/03/10 10:00:45 (permalink)
    0 (2)
    CANBUS is not easy.  First you need more than just PIC18F4580.  You'll also need a transceiver chip to drive the CAN_H and CAN_L signal lines to the required logic levels, for example MCP2551.  Are you using a specific development board, or building a circuit from scratch?
     
    I would suggest starting with a simpler protocol.  TTL UART for example.  Once you have mastered that you can move to more complex protocols, such as CANBUS.
    #5
    crosland
    Super Member
    • Total Posts : 1886
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: PIC18F4580 CAN Test 2020/03/10 10:34:00 (permalink)
    0 (4)
    newbie_pic
    So, How can I ? Not able to move forward got stuck.
     
    while (1)
    {
         got_stuck();
    }






    do until (you answer my questions in your other thread) {
          nothing();
    }

    #6
    newbie_pic
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2019/07/05 19:39:30
    • Location: India
    • Status: offline
    Re: PIC18F4580 CAN Test 2020/03/10 20:20:10 (permalink)
    0
    pcbbc
    Are you using a specific development board, or building a circuit from scratch?

     
    Yes I am using Rhydolabz CAN development board.
     
    pcbbc
    I would suggest starting with a simpler protocol.  TTL UART for example.  Once you have mastered that you can move to more complex protocols, such as CANBUS.

     
    Sir, I already worked on UART, I2C and SPI now started to work on CAN. I had a sample code for CAN Test in which Node1 sends Time to Node2 on a button press. That is working fine in the development board.
    post edited by newbie_pic - 2020/03/10 20:33:53
    #7
    pcbbc
    Super Member
    • Total Posts : 1649
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: PIC18F4580 CAN Test 2020/03/11 02:18:15 (permalink)
    +1 (1)
    newbie_picSir, I already worked on UART, I2C and SPI now started to work on CAN. I had a sample code for CAN Test in which Node1 sends Time to Node2 on a button press. That is working fine in the development board.

    I thought you were receiving junk?
    So it is working now, or not?
    What are you trying to achieve?

    If it is not working, post the code and tell us...
    1. What you expected to see
    2. What you actually saw
    3. How you tested the above
    These are the minimum requirements to get any constructive help on a forum like this when you have an issue. Otherwise we are even more stumbling around in the dark than you are...
    #8
    newbie_pic
    Starting Member
    • Total Posts : 39
    • Reward points : 0
    • Joined: 2019/07/05 19:39:30
    • Location: India
    • Status: offline
    Re: PIC18F4580 CAN Test 2020/03/11 07:03:25 (permalink)
    0
    @pcbbc, Thanks for taking interest in this post
     
    pcbbc
    I thought you were receiving junk?

     
    Yes. I am receiving junk data as mentioned in previous post
     
    pcbbc
    So it is working now, or not?

     
    When I started first I am not able to send and receive data, because I had not set acceptance filters correctly. Then I corrected it. Now both the Nodes will send and receive but received data is something junk.
     
    pcbbc
    What are you trying to achieve?

     
    I am trying to send and receive data from both the nodes. In the sample code given below (CAN_working.zip) Node1 sending Time whenever a KEY is pressed to Node2 and displayed on LCD in Node2 its working fine.
     
    In the code given below (CAN_notworking.zip), I am trying to display registers (For debug purpose only) like COMSTAT, TXB0CON, TXERRCNT, RXB0CON and RXERRCNT then sending data from one node to the other on KEY press (on both the nodes).
     
    Actually when received in one of the nodes, RXB0CON is 0x01 i.e it received data from filter 1 to the buffer. But I set filter 0 for reception so it should be 0x00 as of my understanding (If mistaken please correct me).
     
    And received data along with ID and Length (DLC) is as in the image.
     https://drive.google.com/...yNG4M/view?usp=sharing
    post edited by newbie_pic - 2020/03/11 07:07:47
    #9
    pcbbc
    Super Member
    • Total Posts : 1649
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: PIC18F4580 CAN Test 2020/03/11 08:01:55 (permalink)
    +1 (1)
        if (canReceive(&id, (uchar_t*)&len, rec))

    Define len correctly so you do not need to cast.
     
    str[7 - i] = '0' + (RXERRCNT & (1 << i));

    Assuming you are trying to convert to binary, this is wrong.  That will give you:
    "0" + (n & (1 << 1)) ---> "0" or "1"
    "0" + (n & (1 << 2)) ---> "0" or "2"
    "0" + (n & (1 << 3)) ---> "0" or "4"
    "0" + (n & (1 << 4)) ---> "0" or "8"

    etc.

    Try:
    str[7 - i] = '0' + ((RXERRCNT >> i) & 1);


    This can only handle IDs 0-99:
            clcd_putch ('0' + (id / 10), LINE1(14));
            clcd_putch ('0' + (id % 10), LINE1(15));

    12-bit CAN IDs are usually shown in hex as 3 hex digits.
     
    post edited by pcbbc - 2020/03/11 08:03:41
    #10
    orlandocarvalho
    New Member
    • Total Posts : 9
    • Reward points : 0
    • Joined: 2020/03/09 07:14:40
    • Location: 0
    • Status: offline
    Re: PIC18F4580 CAN Test 2020/03/26 10:26:21 (permalink)
    -1 (1)
    hey, can you post your code here ?
     
    #11
    pcbbc
    Super Member
    • Total Posts : 1649
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: PIC18F4580 CAN Test 2020/03/27 08:19:27 (permalink)
    0
    orlandocarvalho
    hey, can you post your code here ?

    Err, post #9?
    I don't have any code, I was helping the OP.
    #12
    Jump to:
    © 2020 APG vNext Commercial Version 4.5