pierremolinaro / acan2517FD

Distribution of Arduino driver for MCP2517FD CAN controller (CANFD mode)
MIT License
68 stars 16 forks source link

SPI connection with Arduino Nano 33 BLE #23

Open Marittia opened 3 years ago

Marittia commented 3 years ago

Hello! First of all, thanks a lot for the library.

I currently have a MCP2518FD-Click and i wanted to use it along with my Arduino 33 nano BLE.

I already tried the example LoopBackDemoArduinoUno with an Arduino Uno and everything works fine.

But when i switch to the Arduino Nano the code seems to stuck (Arduino IDE stops working as long as i don't disconnect the Arduino from the USB) when calling the function "writeRegister8" inside ACAN2517FD::begin. Could it be something wrong with the SPI communication? I double checked the wiring and it seems to be correct (it's equal to the one on my Arduino Uno).

Also, i'm using the MCP2518 with jumper on VIO=3.3 (used a shifter with arduino UNO) and i'm connecting both 3.3V and 5V.

Thanks for your time!

pierremolinaro commented 3 years ago

Hello!

I have no Arduino 33 nano BLE, so I can't reproduce the bug. But there is no reason why it shouldn't work.

From what I've seen on the Internet, the connection should be : D11 - Mosi (SDO) D12 - Miso (SDI) D13 - SCK CS connection : any pin INT connection : any PIN

It is strange that Arduino IDE stops working as long as i don't disconnect the Arduino from the USB. What pins are you using for CS and INT ? Perhaps there is a conflict with an USB function ?

Pierre

Le 15 juil. 2021 à 11:41, Marittia @.***> a écrit :

Hello! First of all, thanks a lot for the library.

I currently have a MCP2518FD-Click and i wanted to use it along with my Arduino 33 nano BLE.

I already tried the example LoopBackDemoArduinoUno with an Arduino Uno and everything works fine.

But when i switch to the Arduino Nano the code seems to stuck (Arduino IDE stops working as long as i don't disconnect the Arduino from the USB) when calling the function "writeRegister8" inside ACAN2517FD::begin. Could it be something wrong with the SPI communication? I double checked the wiring and it seems to be correct (it's equal to the one on my Arduino Uno).

Also, i'm using the MCP2518 with jumper on VIO=3.3 (used a shifter with arduino UNO) and i'm connecting both 3.3V and 5V.

Thanks for your time!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan2517FD/issues/23, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVAZFJJ4AIYEQAQDKHDTX2UNXANCNFSM5ANFSVYQ.

Marittia commented 3 years ago

I'm using the same wiring you're describing. For CS i'm using pin D6 and for INT pin D7 (i saw that every pin on the Nano is interruptable). I also tried with some other different CS and INT pins, but none of the tries worked out.

Tomorrow i will be able to test it a bit further and see what can cause the problem.

For now, thank you very much!

Marittia commented 3 years ago

Hello! Thanks for the help. So far i recognized the "IDE stuck while Arduino is connected" was due to the code blocking (maybe an infinite loop?) after a noInterrupts() call. So what i did was basically commenting all the "noInterrupts()" i found in the library code. The result is that now the Begin function seems to succeed (errorCode = 0).

Still the InternalLoop mode doesn't work, and i saw that in NormalFD mode my can sniffer is able to read only the first packet, all the other ones cannot be sent. Do you happen to have any idea about what could be the problem?

Also, i noted that with noInterrupts enabled it seems to stuck inside this portion of code here, right after writing and the reading back MCP2517FD RAM at address 0x400:

//----------------------------------- Check SPI connection is on (with a 1 MHz clock)
// We write and the read back MCP2517FD RAM at address 0x400
Serial.println("This will be printed");
  for (uint32_t i=1 ; (i != 0) && (errorCode == 0) ; i <<= 1) {
    const uint16_t RAM_WORD_ADDRESS = 0x400 ;
    writeRegister32 (RAM_WORD_ADDRESS, i) ;
    const uint32_t readBackValue = readRegister32 (RAM_WORD_ADDRESS) ;
    if (readBackValue != i) {
      errorCode = kReadBackErrorWith1MHzSPIClock ;
    }
  }
Serial.println("This won't!");

Thank you very much once again, Mariano

pierremolinaro commented 3 years ago

Hello !

It is strange that noInterrupts() call causes code blocking. But the library requires disabling and enabling interrupts, so it's no wonder that by commenting noInterrupts() the library no longer works.

You can try your luck in the following ways (see LoopBackDemoTeensy3xNoInt demo sketch):

Best Regards,

Pierre

Le 21 juil. 2021 à 09:17, Marittia @.***> a écrit :

Hello! Thanks for the help. So far i recognized the "IDE stuck while Arduino is connected" was due to the code blocking (maybe an infinite loop?) after a noInterrupts() call. So what i did was basically commenting all the "noInterrupts()" i found in the library code. The result is that now the Begin function seems to succeed (errorCode = 0).

Still the InternalLoop mode doesn't work, and i saw that in NormalFD mode my can sniffer is able to read only the first packet, all the other ones cannot be sent. Do you happen to have any idea about what could be the problem?

Thank you very much once again, Mariano

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/pierremolinaro/acan2517FD/issues/23#issuecomment-883952839, or unsubscribe https://github.com/notifications/unsubscribe-auth/AEWKZVEC4WZFNE4UDT4WNODTYZYCJANCNFSM5ANFSVYQ.

jmFernandezMola commented 1 year ago

Hi there, I have the same problem of Marittia. After some investigations I found this: "Note that disabling interrupts on the Arduino boards with native USB capabilities (e.g., Leonardo) will make the board not appear in the Port menu, since this disables its USB capability." In the nointerrupts() reference from arduino (here). Arduino Nano 33 BLE seems to be affected by this also. I hope this comment sheds some light. Best regards, JM