Microchip
直播中

h1654155275.5724

7年用户 212经验值
私信 关注
[问答]

MCP2515初始化问题

您好,我正在尝试连接MCP2515到Link KIT板(兼容ARDUINO)。我使用的是LinkIt ONE(数字引脚工作在3.3v)+电平转换器(TXB0108PWR)+CAN模块,板上有MCP2515和TJA1050。我不能完全确定我的初始化是错的还是好的。每次读取寄存器值时,它会返回不同的响应。在读取之间,我不调用任何SPI命令,所以理论上寄存器值不应该改变。我尝试过使用SPI命令(0xC0)和硬件(RST管脚上的低电平)在通电后使用两种类型的复位。我都得到同样的结果。我用RPI测试了我的MCP2515,所有的工作都很好,所以IC没有被破坏。我还检查了SPI是否正确地使用了回环测试,并且它通过了。现在我将分享一些关于我的方案的信息.1)连接:我不能附加连接方案,但是有一个表:LinkIt One Level.or(TXB0108PWR)MCP25153v3 VA-5v VB+5V,nRSTGND GND GNDSCK A2(3.3v)<->B2(5v)SCK MISO A4(3)。3v)-lt;->B4(5v)-B4(5v)-SOMOSI A5(3.3v)-lt->B5(5v)-B5(5v)-B5(5v)SIPIN9(CS 9(CS)A9(CS)A9(CS)A6(3.3v)- B6(5v)-B6(5v)nCSPINPINPIN2(INT)A3(3.3v)-_A3 3.3v)-<;>->> B3(5v)-> B3 B3(5v)B3(5v)B3(5v)B3(5v)-.....digitalWrite(CS_PIN,HIGH);例如readRegister:b).ization(can_mode ANY,can_.250Kbps,can_clk 16MHz):因为初始化没有完全确认,所以我现在不尝试接收任何帧。你有什么建议来解决这个问题吗?

以上来自于百度翻译


      以下为原文

    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 cannot attach connections scheme but, 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

2)My code looks like this:
a)Each SPI command call:
digitalWrite(CS_PIN, LOW);
.....
digitalWrite(CS_PIN, HIGH);
for example readRegister:
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):
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...rn");
  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?

回帖(1)

王晗

2019-6-17 16:46:35
你想读哪些寄存器,你得到什么值?设备必须连接到CAN收发器,总线必须终止,否则它永远无法正常启动(或退出配置模式)。您可能需要查看SPI总线上的数据以查看出错。将RPI SPI时序与ARDUINO进行比较。你可以在两个单元之间反转SPI时钟,或者使数据在错误的边缘上改变。汤姆

以上来自于百度翻译


      以下为原文

    Which registers are you trying to read and what values are you getting?
 
The device has to be connected to a CAN Transceiver and the bus has to be terminated or it won't ever start up properly (or exit Config mode).
 
You may need to look at the data on the SPI bus to see what is wrong. Compare the RPi SPI timing with the Arduino. You may have the SPI Clocks inverted between the two units, or have the data changing on the wrong edge.
 
Tom
 
举报

更多回帖

发帖
×
20
完善资料,
赚取积分