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

Determining baud rate with no traffic #68

Open
fbwarren opened this issue Sep 10, 2024 · 0 comments
Open

Determining baud rate with no traffic #68

fbwarren opened this issue Sep 10, 2024 · 0 comments

Comments

@fbwarren
Copy link

I am trying to determine the baud rate of a network, but there's no traffic to listen to. I think this is because newer cars have a sort of gateway preventing listening in on traffic. Is there a way to try sending messages at various rates and listening for errors/responses to determine the correct speed? Here's what I've tried:

uint32_t beginAutoSpeedActive(MCP2517FD *network)
{
  uint32_t canspeed = 0;
  uint32_t bauds [2] = {125,500};

  CAN_FRAME msg;
  msg.id = 0x7ff;
  msg.length = 8;
  msg.extended = false;
  msg.rtr = false;
  msg.data.byte[0] = 0x01;
  msg.data.byte[1] = 0x02;
  msg.data.byte[2] = 0x03;
  msg.data.byte[3] = 0x04;
  msg.data.byte[4] = 0x05;
  msg.data.byte[5] = 0x06;
  msg.data.byte[6] = 0x07;
  msg.data.byte[7] = 0x08;

  for (int i = 0; i < 2; i++)
  {
    canspeed = bauds[i] * 1000;

    network->enable();
    network->begin(canspeed);
    network->watchFor();
    network->sendFrame(msg);
    
    bool error = false;
    unsigned long startTime = millis();
    
    while ((millis() - startTime) < 1000)
    {
      if (network->hasTXFault())
      { 
        error = true;
        network->Write16(ADDR_CiINT, 0);    // acknowledge interrupts/fault
        break;
      }
    }

    network->resetHardware();
    delay(500);
    network->disable();       // resetting hardware enables the network

    if (!error)
    {
      return canspeed;
    }
  }

  return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant