Jump to content


Photo

LinkSprite's Canbus + PCduino8 ?


  • Please log in to reply
1 reply to this topic

#1 bloodstyle

bloodstyle

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 26 May 2017 - 07:19 PM

Hi everyone,

 

I recently bought a PCduino8 for a project which needs CANbus, so I bought a CANbus shield too.

 

I am able to make the CANbus shield work on a regular Arduino UNO, but I'm having a lot of trouble with the PCduino as it is linux based.

 

I've tried the SPI example on sparkfun and in the arduino IDE of PCduino8, but I think there's a big step to communicate to the MCP2515 of the shield.

 

Can anyone help me or direct me somewhere?

 

Thank you.



#2 bloodstyle

bloodstyle

    Newbie

  • Members
  • Pip
  • 2 posts

Posted 30 May 2017 - 08:59 PM

Hi again,

 

I've manage to understand how SPI works. But I can't get the PCduino to communicate with the CANbus shield.

 

Here in the code I am using the EXACT same command to boot the MCP2515 in CONFIG MODE. The return value of the read function at address 0x0F should return 0x85, but it returns 0!

 

plz help.

 

here's the code.

#include <stdio.h>
#include <string.h>
#include <core.h>
#include "SPI.h"

//#define EX_SPI_TEST 

int ReadConfiguration(void) {
    SPI.transfer(0xC0, SPI_LAST);
    
    SPI.transfer(0x05, SPI_CONTINUE);
    SPI.transfer(0x0F, SPI_CONTINUE);
    SPI.transfer(0xE0, SPI_CONTINUE);
    SPI.transfer(0x80, SPI_LAST);
    
    SPI.transfer(0x03, SPI_CONTINUE);
    SPI.transfer(0x0F, SPI_CONTINUE);
    printf("=%x\n",SPI.transfer(0x00, SPI_LAST));
    
    return 0;
}

void setup() {
    SPI.begin(); 
    SPI.setDataMode(SPI_MODE0);
    SPI.setBitOrder(MSBFIRST);
    SPI.setClockDivider(SPI_CLOCK_DIV16);
}

void loop() {
    //MSB first 
    ReadConfiguration();
    delay(1000);
}






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users