Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CAN.getCanId() gets the ID of the TX MSG insted of the RX MSG #149

Closed
Damians99 opened this issue Dec 21, 2023 · 3 comments
Closed

CAN.getCanId() gets the ID of the TX MSG insted of the RX MSG #149

Damians99 opened this issue Dec 21, 2023 · 3 comments
Assignees
Labels
Seeed_Arduino_CAN Label for Seeed_Arduino_CAN UAY Unassigned yet

Comments

@Damians99
Copy link

I send a message periodically (100 Hz) with the CAN-SHIELD (MPC2515).
In parallel, I execute the following function:

while (CAN_MSGAVAIL == CAN.checkReceive())
    {
        CanRxInterrupt();
        //Serial.println("MSG detects on RX");
    }


void CanRxInterrupt() {

    unsigned int canId = CAN.getCanId();
    unsigned char len;
    unsigned char buf[8];
    CAN.readMsgBuf(&len, buf);

    Serial.println(canId, HEX);

CAN_MSGAVAIL == CAN.checkReceive()

works perfectly with an incoming message and CanRxInterrupt() is called when a MSG is incomming. However, the following line:

unsigned int canId = CAN.getCanId()

always returns the ID of the just periodically sent message and not that of the incoming message. Sommetimes when the incomming MSG ist sent with a verry high frequence i got the correct ID, but nearly never.

  • OS: Windows 11, Arduino, VS Code
@baorepo baorepo closed this as completed Sep 27, 2024
@baorepo baorepo reopened this Sep 27, 2024
@MatthewJeffson MatthewJeffson added UAY Unassigned yet Seeed_Arduino_CAN Label for Seeed_Arduino_CAN labels Oct 9, 2024
@Lesords Lesords self-assigned this Oct 14, 2024
@Lesords
Copy link

Lesords commented Oct 16, 2024

Hello,

I'm very sorry to have kept you waiting so long.

Do you still have this problem now?

@Damians99
Copy link
Author

Hii, thanks for responding.
No i was able to solve it by myself while checking the souce code. The Problem was caused by me.

Problem/Solution is:
CAN.readMsgBuf() has to be executed before I execute the CAN.getCanID()

Otherwise the stored Can ID will be the one i just sent and not the one i just recived(because i never read the RX Buffer)

Now it seems logical, but i didnt know that the stored ID want be updated with the execution of CAN.getCanID()

Thanks
Best Regards
Damian

@Lesords
Copy link

Lesords commented Oct 17, 2024

Okay, with that I'm going to close this issue, if you have any other questions you're welcome to reopen the issue.

@Lesords Lesords closed this as completed Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Seeed_Arduino_CAN Label for Seeed_Arduino_CAN UAY Unassigned yet
Projects
Status: Done
Development

No branches or pull requests

4 participants