Jump to content
Sign in to follow this  
bloodstyle

LinkSprite's Canbus + PCduino8 ?

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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);
}

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×