hhh321
Newbie level 2
Hello,
I'm trying to connect mcp2515 to LinkIt ONE board(compatibile with Arduino). I'm using LinkIt ONE(digital pins operates at 3.3v) + Level translator(TXB0108PWR) + CAN module with MCP2515 and TJA1050 on board. I cannot fully determinate whether my initializations goes wrong or good. Each time I read register value it returns different response. Between reads I don't call any SPI command so theoretically registers values shouldn't change. I've tried to use two types of reset after power-up using SPI command(0xC0) and hardware(low-level on RST pin). After both i get same results. I did tested my MCP2515 with RPi and everything worked fine there so IC is not broken. I've also checked whether SPI works properly with loopback test - and it passed. Now I will share some informations about my scheme.
1)Connections:
I've attached connections scheme but it can be not well visible, so there's table:
2)My code looks like this:
a)Each SPI command call:
digitalWrite(CS_PIN, LOW);
.....
digitalWrite(CS_PIN, HIGH);
for example readRegister:
b)initialization(can_mode ANY, can_speed 250Kbps, can_clk 16MHz):
I don't try to receive any frames now because initialization is not fully confirmed. Do you have any suggestions how to solve that?
I'm trying to connect mcp2515 to LinkIt ONE board(compatibile with Arduino). I'm using LinkIt ONE(digital pins operates at 3.3v) + Level translator(TXB0108PWR) + CAN module with MCP2515 and TJA1050 on board. I cannot fully determinate whether my initializations goes wrong or good. Each time I read register value it returns different response. Between reads I don't call any SPI command so theoretically registers values shouldn't change. I've tried to use two types of reset after power-up using SPI command(0xC0) and hardware(low-level on RST pin). After both i get same results. I did tested my MCP2515 with RPi and everything worked fine there so IC is not broken. I've also checked whether SPI works properly with loopback test - and it passed. Now I will share some informations about my scheme.
1)Connections:
I've attached connections scheme but it can be not well visible, so there's table:
LinkIt ONE | Level translator(TXB0108PWR) | MCP2515 |
3v3 | VA | --- |
5v | VB | +5V, nRST |
GND | GND | GND |
SCK | A2(3.3v) <-> B2(5v) | SCK |
MISO | A4(3.3v) <-> B4(5v) | SO |
MOSI | A5(3.3v) <-> B5(5v) | SI |
PIN9(CS) | A6(3.3v) <-> B6(5v) | nCS |
PIN2(INT) | A3(3.3v) <-> B3(5v) | nINT |
a)Each SPI command call:
digitalWrite(CS_PIN, LOW);
.....
digitalWrite(CS_PIN, HIGH);
for example readRegister:
Code:
byte readRegister(const byte reg_addr){
byte ret;
digitalWrite(CS_PIN, LOW);
SPI.transfer(MCP_READ);
SPI.transfer(reg_addr);
ret = SPI.transfer(0x00);
digitalWrite(CS_PIN, HIGH);
return ret;
}
Code:
byte initialize(
const byte can_mode,
const byte can_speed,
const byte can_clk){
byte result;
softReset();//using SPI command
if(!setCtrlRegister(CANCTRL_MODE_CONFIG)) //entering config mode by using bit modify
return FAIL;
if(!configRate(can_speed, can_clk)) //setting registers: MCP_CNF1, MCP_CNF2, MCP_CNF3
return result;
initBuffers();//Initializig masks, filters. Clearing transmit buffers
modifyRegister(MCP_CANINTE, 0x03, MCP_RX0IF | MCP_RX1IF);
if(!setIdMode(can_mode))
return FAIL;
result = setCtrlRegister(MCP_NORMAL);
if(!result)
Serial.print("Returning to Previous Mode Failure...\r\n");
return result;
}