Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[CAN] MCP2515 initialization problem

Status
Not open for further replies.

hhh321

Newbie level 2
Joined
Apr 15, 2016
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
31
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:
scheme.png
I've attached connections scheme but it can be not well visible, so there's table:
LinkIt ONELevel translator(TXB0108PWR)MCP2515
3v3VA---
5vVB+5V, nRST
GNDGNDGND
SCKA2(3.3v) <-> B2(5v)SCK
MISOA4(3.3v) <-> B4(5v)SO
MOSIA5(3.3v) <-> B5(5v)SI
PIN9(CS)A6(3.3v) <-> B6(5v)nCS
PIN2(INT)A3(3.3v) <-> B3(5v)nINT
2)My code looks like this:
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;
}
b)initialization(can_mode ANY, can_speed 250Kbps, can_clk 16MHz):
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; 
}
I don't try to receive any frames now because initialization is not fully confirmed. Do you have any suggestions how to solve that?
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top