Go Down

Topic: Incompatibility CAN bus and NFC (Read 93 times) previous topic - next topic

lepco

Hello,

I have this CAN shield : http://www.seeedstudio.com/wiki/CAN-BUS_Shield and this NFC shield : http://www.seeedstudio.com/wiki/NFC_Shield_V2.0 .

When I begin the NFC, the CAN bus does not work.

There is my code. Someone can help me ?

Code: [Select]
#include <SPI.h>
#include <PN532_SPI.h>
#include <PN532.h>
#include <NfcAdapter.h>

#include <mcp_can.h>//bus CAN
MCP_CAN CAN(9);

PN532_SPI pn532spi(SPI, 10);
NfcAdapter nfc = NfcAdapter(pn532spi);


void setup(void) {
    Serial.begin(115200);
 
   
    //bus CAN
START_INIT:

    if(CAN_OK == CAN.begin(CAN_125KBPS))                   // init can bus : baudrate = 125k
    {
        Serial.println("CAN BUS Shield init ok!");
    }
    else
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println("Init CAN BUS Shield again");
        delay(100);
        goto START_INIT;
    }

  //start of NFC component
  Serial.println("NDEF Reader");
  nfc.begin();
 
}

void loop(void) {
 
  unsigned char var1[1] = {0}; 
 
  Serial.println("\nScan a NFC tag\n");
    if (nfc.tagPresent())
    {
        NfcTag tag = nfc.read();
        tag.print();
       
       
        if ( tag.getUidString() == "23 BF 9F D2")
         {
            Serial.println("Code OK");
             var1[1] = 1;
         }
         else
         {
            Serial.println("Pas bon");
             var1[1] = 2;
         }
   
    }
   
    CAN.sendMsgBuf(0x01, 0, 1, var1);//bus CAN
   
    delay(500);
}


PS : In the CAN shield, I change the CS to 9.

Go Up