0

I come seeking expert knowledge :)

I have a mega connected to two SPI devices. One is a MCP2516 CAN transceiver and the other is a digital potentiometer https://digilent.com/reference/pmod/pmoddpot/start?redirect=1

I seem to have trouble getting the potentiometer to work though. The MCP2516 is connected to dedicated SPI ports and the CS is a digital pin - 12

I then have my potentiometer connected to the ICSP header. the COPI and SCK lines,

I initialise the can bus using the CAN library like so:

      // Setup CAN bus interface
      CAN.setPins(MCP2515_CS, MCP2515_INT);
      CAN.setClockFrequency(MCP2515_FCLK);
      // Initialize CAN bus
      while (true) {
        Serial.print("Initializing CAN bus interface ... ");
        if (CAN.begin(CAN_BITRATE)) {
          Serial.println("OK");
          break;
        } else {
          Serial.println("FAIL");
          delay(1000);
        }
      //Set up the pot
      pinMode(POT_CS_PIN, OUTPUT);
      pinMode(POT_CS_PIN, HIGH);
      SPI.begin()

Then for the potentiometer I call a function when I need to setup an initial value:

    void setDigitalPotentiometer(int level) {
      int potValue = constrain(level, 0, 255);
    
      // Set the potentiometer value via SPI
      SPISettings potSPISettings(1000000, MSBFIRST, SPI_MODE0); 
    
      digitalWrite(POT_CS_PIN, LOW);
      SPI.beginTransaction(potSPISettings);
      delayMicroseconds(15);
      SPI.transfer(level);
      delayMicroseconds(15);
      digitalWrite(POT_CS_PIN, HIGH);
      SPI.endTransaction();
    }

I've taken the step to disable the CAN CS pin to avoid collisions, but try as I may no luck. Measuring between the A and W terminals the resistance stays near 0 as if the wiper is just stuck.

Any guidance? Anything obviously wrong?

4
  • The MCP2516 is connected to dedicated SPI ports and the CS is a digital pin - 12 - what do you mean by the dedicated SPI ports exactly?
    – Nick Gammon
    Commented Jun 22 at 8:03
  • I mean the MCP2516 is connected : CS pin 53 SCK pin 12 on the Arduino Mega MOSI pin 51 on the Arduino Mega MISO pin 50 on the Arduino Mega INT pin
    – Isenwald
    Commented Jun 22 at 9:17
  • SPI.transfer(level) sent ONE byte of data, if your level is a int, it will be truncated. To send an int, use SPI.transfer16(level). If this is not the problem, then please provide more complete setup code, including the pin assignment of MCP2515_CS, and connection diagram.
    – hcheung
    Commented Jun 25 at 8:43
  • When you use one device, its CS pin should be set LOW, and the CS pin of the other device should be HIGH to avoid bus contention.
    – tepalia
    Commented Jul 1 at 6:47

0

Browse other questions tagged or ask your own question.