好的一天,我目前正在尝试用CAN总线连接微芯片微控制器。我目前使用的设备有:PIC24FJ64GA002MCP2515MCP2551目前还有一个CAN总线连接到MCP2551上,其上还有一个节点。我还有一个USB-to-CAN适配器,用于从PC上的软件探测网络。此外,几天前我还能发送一个CAN帧。但是,我最近一直很挣扎,现在不能用了。这是我的初始化函数:然后我调用另一个函数在网络上传输CAN帧。这个函数首先通过以下调用执行读取状态:MCP2515Read.();现在,我得到了两个不同的行为:有时,前一个函数中的while循环不退出,并且MCP2515从不切换到正常模式。它只是永远停留在那里;其他时候,它确实切换到正常模式,但是当调用MCP2515Read.()时,它返回0xFF。我有一个8兆赫振荡器与2×22欧姆电容器。我还连接了RX和Tx引脚到MCP2551。最后,复位针连接在微控制器上,这样我就可以控制它来复位芯片。你知道有什么问题吗?问候,MB
以上来自于百度翻译
以下为原文
Good day,
I am currently trying to interface a microchip micro controller with a CAN bus. I am currently using the following devices:
- PIC24FJ64GA002
- MCP2515
- MCP2551
There is currently a CAN bus connected to the MCP2551 and it has another node connected on it. I also have a USB-to-CAN adapter to probe the network from a software on a PC. Furthermore, I was able to send a CAN frame a couple of days ago. However, I have been struggling with it lately and it's not longer working.
This is my initialize function:
void MCP2515InitI()
{
uint8_t u8Temp = 0;
CS = HIGH;
MCP2515Reset();
__delay_ms(1);
MCP2515WriteRegister(REG_CANCTRL, MODE_CONFIG);
u8Temp = u8CNF1Values[ BAUDRATE];
MCP2515WriteRegister( REG_CFN1, u8Temp);
u8Temp = u8CNF2Values[ BAUDRATE ];
MCP2515WriteRegister( REG_CFN2, u8Temp);
u8Temp = u8CNF3Values[ BAUDRATE];
MCP2515WriteRegister( REG_CFN3, u8Temp);
MCP2515WriteRegister( REG_CANINTF, 0x00 );
MCP2515WriteRegister( REG_CANINTE, 0x01 );
MCP2515WriteRegister( REG_RXB0CTRL, 0b01100100 );
MCP2515WriteRegister( REG_RXB1CTRL, 0b01100000 );
MCP2515WriteRegister( REG_TXRTSCTRL, 0b00000000 );
MCP2515WriteRegister( REG_CANCTRL, 0x05 );
u8Temp = 0xff;
while ((u8Temp & MASK_MODE_NORMAL) != 0b00000000)
{
u8Temp = MCP2515ReadRegister(REG_CANSTAT);
}
__delay_ms(5);
}
Then I call another function to transfer a CAN frame on the network. This function first performs a read status with the following call:
MCP2515ReadStatus();
Now, I am getting two different behavior:
- Sometimes, the while loop in the previous function doesn't exit and the MCP2515 never switch to normal mode. It's simply stuck there forever;
- Other times, it does switch to normal mode but then, when the MCP2515ReadStatus() gets called, it returns 0xFF.
I was able to determine those by using a logic analyzer. I have an 8 Mhz oscillator with 2 x 22 ohms capacitors. I have also connected the Rx and Tx pins to the MCP2551. Finally, the
Reset pin is linked on the micro controller so I can control it to reset the chip.
Do you have any ideas what could be the problem?
Regards,
mb