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

Issue with Buffer. #14

Open
gannaramu opened this issue Apr 13, 2020 · 0 comments
Open

Issue with Buffer. #14

gannaramu opened this issue Apr 13, 2020 · 0 comments

Comments

@gannaramu
Copy link

Hello,

Firstly thank you so much for the library!. I currently have a MCP2517fd click board by mikroE. after some good time, I was able to figure out how to get it to work. the issue I am currently facing is that I am just able to receive a small set of can message after which I don't receive any more messages.
I am using a teensy4.0.

Below is the code I am running on it. Could you let me know what I am doing wrong.. I have gone through the documentation but couldn't figure out why I was facing this issue? could you guide me?

//——————————————————————————————————————————————————————————————————————————————
//  ACAN2517FD or ACAN2518FD send-even, for Teensy 3.5 using SPI1
//——————————————————————————————————————————————————————————————————————————————

#include <ACAN2517FD.h>

//——————————————————————————————————————————————————————————————————————————————
//  MCP2517FD connections: adapt theses settings to your design
//  As hardware SPI is used, you should select pins that support SPI functions.
//  This sketch is designed for a Teensy 3.5, using SPI1
//  But standard Teensy 3.5 SPI1 pins are not used
//    SCK input of MCP2517 is connected to pin #32
//    SDI input of MCP2517 is connected to pin #0
//    SDO output of MCP2517 is connected to pin #1
//  CS input of MCP2517 should be connected to a digital output port
//——————————————————————————————————————————————————————————————————————————————

static const byte MCP2517_SCK = 13 ; // SCK input of MCP2517
static const byte MCP2517_SDI =  11 ; // SDI input of MCP2517
static const byte MCP2517_SDO =  12 ; // SDO output of MCP2517

static const byte MCP2517_CS  = 10 ; // CS input of MCP2517
static const byte MCP2517_INT = 9 ; // INT output of MCP2517

//——————————————————————————————————————————————————————————————————————————————
//  ACAN2517FD Driver object
//——————————————————————————————————————————————————————————————————————————————

ACAN2517FD can (MCP2517_CS, SPI, MCP2517_INT) ;
static unsigned gSendDate = 0 ;
static unsigned gSentCount = 0 ;
static unsigned gReceivedCount = 0 ;
//——————————————————————————————————————————————————————————————————————————————
//   SETUP
//——————————————————————————————————————————————————————————————————————————————

void setup () {
//--- Switch on builtin led
  pinMode (LED_BUILTIN, OUTPUT) ;
  digitalWrite (LED_BUILTIN, HIGH) ;
//--- Wait for Serial monitor (blink at 5 Hz)
  Serial.begin (38400) ;
  while (!Serial) { digitalWrite (LED_BUILTIN, !digitalRead (LED_BUILTIN)) ; }
//----------------------------------- Begin SPI1
  SPI.begin () ;
//----------------------------------- Configure ACAN2517FD
//--- For version >= 2.1.0
  ACAN2517FDSettings settings (ACAN2517FDSettings::OSC_40MHz, 250 * 1000, DataBitRateFactor::x8);
settings.mRequestedMode = ACAN2517FDSettings::NormalFD;

//--- For version < 2.1.0
//  ACAN2517FDSettings settings (ACAN2517FDSettings::OSC_4MHz10xPLL, 1000 * 1000, ACAN2517FDSettings::DATA_BITRATE_x8) ;
  settings.mDriverReceiveFIFOSize = 5000 ;
//--- Begin
  const uint32_t errorCode = can.begin (settings, canISR) ;
  Serial.print ("Bit Rate prescaler: ") ;
  Serial.println (settings.mBitRatePrescaler) ;
  Serial.print ("Arbitration Phase segment 1: ") ;
  Serial.println (settings.mArbitrationPhaseSegment1) ;
  Serial.print ("Arbitration Phase segment 2: ") ;
  Serial.println (settings.mArbitrationPhaseSegment2) ;
  Serial.print ("Arbitration SJW:") ;
  Serial.println (settings.mArbitrationSJW) ;
  Serial.print ("Actual Arbitration Bit Rate: ") ;
  Serial.print (settings.actualArbitrationBitRate ()) ;
  Serial.println (" bit/s") ;
  Serial.print ("Exact Arbitration Bit Rate ? ") ;
  Serial.println (settings.exactArbitrationBitRate () ? "yes" : "no") ;
  Serial.print ("Arbitration Sample point: ") ;
  Serial.print (settings.arbitrationSamplePointFromBitStart ()) ;
  Serial.println ("%") ;
  Serial.print ("Data Phase segment 1: ") ;
  Serial.println (settings.mDataPhaseSegment1) ;
  Serial.print ("Data Phase segment 2: ") ;
  Serial.println (settings.mDataPhaseSegment2) ;
  Serial.print ("Data SJW:") ;
  Serial.println (settings.mDataSJW) ;
  Serial.print ("TDCO:") ;
  Serial.println (settings.mTDCO) ;
  Serial.print ("Even, error code 0x") ;
  Serial.println (errorCode, HEX) ;
 //--- Endless  loop on error
  while (errorCode != 0) { }
}


//——————————————————————————————————————————————————————————————————————————————
//   RECEIVE FUNCTION
//——————————————————————————————————————————————————————————————————————————————

void receiveFromFilter0 (const CANFDMessage & inMessage) {
  Serial.println ("Match filter 0") ;
}
//——————————————————————————————————————————————————————————————————————————————

void receiveFromFilter1 (const CANFDMessage & inMessage) {
  Serial.println ("Match filter 1") ;
}

//——————————————————————————————————————————————————————————————————————————————

void receiveFromFilter2 (const CANFDMessage & inMessage) {
  Serial.println ("Match filter 2") ;
}
//——————————————————————————————————————————————————————————————————————————————

static uint32_t gBlinkLedDate = 0 ;
static uint32_t gSentFrameCount = 0 ;
static uint32_t gReceivedFrameCount = 0 ;
static bool gCompleted = false ;
static const uint32_t SEND_COUNT = 50 * 1000 ;

//——————————————————————————————————————————————————————————————————————————————
void canISR () {
can.isr () ;
Serial.println("Interrupt Called");
handleReceivedMessages();

}
static void handleReceivedMessages (void) {
  CANFDMessage frame ;
//  Serial.println("Waiting ");
  while (can.receive (frame)) {
    gReceivedFrameCount ++;
    Serial.print("ID: ");
    Serial.print(frame.id,HEX);
    Serial.print(" len: ");
    Serial.print(frame.len);
    Serial.print(" data: ");
    for ( uint8_t i = 0; i < 8; i++ ) {
      Serial.print(frame.data[i], HEX); Serial.print(" ");
    }
    Serial.println("");
  }
}
static uint8_t gPhase = 0 ;

//——————————————————————————————————————————————————————————————————————————————
// 18F0010B 08FE6E0B
void loop () {
handleReceivedMessages();
}
void PrintHex8(uint8_t *data, uint8_t length) // prints 8-bit data in hex with leading zeroes
{
       Serial.print("0x");
       for (int i=0; i<length; i++) {
         if (data[i]<0x10) {Serial.print("0");}
         Serial.print(data[i],HEX);
         Serial.print(" ");
       }
}
//——————————————————————————————————————————————————————————————————————————————

image

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