资源简介
使用FPGA操作CAN协议芯片MCP2515实现CAN多种通讯协议操作
代码片段和文件信息
#include “mcp2515.h“
/*RXB0‘s data registers:*/
unsigned char RXB0D[8]={RXB0D0RXB0D1RXB0D2RXB0D3RXB0D4RXB0D5RXB0D6RXB0D7};
/*TXB0‘s data registers:*/
unsigned char TXB0D[8]={TXB0D0TXB0D1TXB0D2TXB0D3TXB0D4TXB0D5TXB0D6TXB0D7};
void MCP2515_Init(void)
{
unsigned char dummy;
/*First initialize the SPI periphere*/
/*Then initialize the MCP2515.Step as follow:
1>Get into configuration mode by reset MCP2515 or write the bit of CANCTRL.REQOP.
2>Check the CANSTAT by ReadByte_MCP2515(CANSTAT) if MCP2515 is already into configuration mode.
3>Configurate the registers to set the baudrate:CN1CN2CN3.
4>Configurate TXRTSCTRL to set the function of TXnRTS pin.
5>Configurate TRXBnCTRL to set the pirority of transmit mailbox:TXB0TXB1TXB2.
6>Configurate TXBn‘SID EID and DLC.This step can configurate when you are in normal mode.
7>Configurate RXFnSIDH and RXFnSIDL to resceive the specific ID.
8>Configurate RXMnSIDH and RXMnSIDL to mask the RXFnSID‘s ID.
9>Configurate CANINTE to enable or disable the interrupts.
10>Return to the normal mode and double check if it is return to the normal mode by CANSTAT.
*/
/*Flip into the Configuration Mode*/
MCP2515_Reset();
_delay_(0x4000);/* 1ms _delay_ using Fcpu = 16Mhz*/
//Set the baudrate
//set CNF1SJW=00lengthe is 1TQBRP=49TQ=[2*(BRP+1)]/Fsoc=2*50/8M=12.5us
SendByte_MCP2515(CNF1CAN_125Kbps);
//set CNF2SAM=0caputre one timePHSEG1=(2+1)TQ=3TQPRSEG=(0+1)TQ=1TQ
SendByte_MCP2515(CNF20x80|PHSEG1_3TQ|PRSEG_1TQ);
//set CNF3PHSEG2=(2+1)TQ=3TQwhen CANCTRL.CLKEN=1set CLKOUT pin to output
SendByte_MCP2515(CNF3PHSEG2_3TQ);
/*
3 Transimit Buffers:TXB0TXB1TXB2
2 Receive Buffers:RXB0RXB1
6 ID Filter:RXF0~RXF5
2 ID Mask Regieter:RXM0RXM1
*/
//configurate RXB0‘ registers
// SendByte_MCP2515(RXB0CTRL0x60);//Receive all frames from CAN bus
SendByte_MCP2515(RXB0CTRL0x20);//RXB0 just receive the standard frames
SendByte_MCP2515(RXF0SIDH0xFF);//Fileter register
SendByte_MCP2515(RXF0SIDL0xE0);//Just receive ID=0x7FF frame
SendByte_MCP2515(RXF1SIDH0xFD);//Fileter register
SendByte_MCP2515(RXF1SIDL0xC0);//Just receive ID=0x7EE frame
SendByte_MCP2515(RXM0SIDH0xFF);//Mask register
SendByte_MCP2515(RXM0SIDL0xE0);
//Configurate TXB0‘s ID and DLC registers
SendByte_MCP2515(TXB0SIDH0xFF);//Standard ID
SendByte_MCP2515(TXB0SIDL0xE0);//Standard ID
SendByte_MCP2515(TXB0DLCDLC_1);//DLC
/*Set the RXB0 or RXB1 interrupt enableling*/
// SendByte_MCP2515(CANINTERX0IE);//Enable RXB0 interrupt
SendByte_MCP2515(CANCTRLREQOP_NORMAL | CLKOUT_ENABLED);//Go into the normal mode
dummy=ReadByte_MCP2515(CANSTAT);
if (OPMODE_NORMAL != (dummy & 0xE0))
SendByte_MCP2515(CANCTRLREQOP_NORMAL | CLKOUT
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2019-08-08 22:32 CAN_MCP2515_fpga\
文件 3078 2018-05-21 23:37 CAN_MCP2515_fpga\CAN_SPI_TR.v
文件 2898 2018-04-22 10:53 CAN_MCP2515_fpga\CAN_SPI_TR.v.bak
文件 48696 2018-05-24 23:52 CAN_MCP2515_fpga\CAN_TR.v
文件 27203 2018-04-22 12:47 CAN_MCP2515_fpga\CAN_TR.v.bak
目录 0 2018-10-23 19:16 CAN_MCP2515_fpga\db\
文件 206 2018-07-17 22:05 CAN_MCP2515_fpga\db\.cmp.kpt
文件 269110 2018-04-27 15:20 CAN_MCP2515_fpga\db\altsyncram_0324.tdf
文件 270198 2018-04-26 21:13 CAN_MCP2515_fpga\db\altsyncram_1324.tdf
文件 232118 2018-04-26 21:08 CAN_MCP2515_fpga\db\altsyncram_3324.tdf
文件 185328 2018-04-25 21:18 CAN_MCP2515_fpga\db\altsyncram_5324.tdf
文件 203830 2018-04-26 22:44 CAN_MCP2515_fpga\db\altsyncram_6324.tdf
文件 204918 2018-04-27 13:57 CAN_MCP2515_fpga\db\altsyncram_7324.tdf
文件 312630 2018-04-28 14:24 CAN_MCP2515_fpga\db\altsyncram_8324.tdf
文件 151607 2018-05-27 23:42 CAN_MCP2515_fpga\db\altsyncram_8424.tdf
文件 264758 2018-04-27 15:13 CAN_MCP2515_fpga\db\altsyncram_9324.tdf
文件 432310 2018-05-05 19:58 CAN_MCP2515_fpga\db\altsyncram_b324.tdf
文件 199472 2018-04-26 20:15 CAN_MCP2515_fpga\db\altsyncram_d324.tdf
文件 286518 2018-04-28 08:43 CAN_MCP2515_fpga\db\altsyncram_e324.tdf
文件 425782 2018-05-05 12:06 CAN_MCP2515_fpga\db\altsyncram_h324.tdf
文件 136368 2018-04-25 22:27 CAN_MCP2515_fpga\db\altsyncram_j224.tdf
文件 417078 2018-05-04 21:20 CAN_MCP2515_fpga\db\altsyncram_j324.tdf
文件 432311 2018-05-26 09:44 CAN_MCP2515_fpga\db\altsyncram_k424.tdf
文件 265846 2018-04-27 15:03 CAN_MCP2515_fpga\db\altsyncram_p224.tdf
文件 130928 2018-04-25 20:23 CAN_MCP2515_fpga\db\altsyncram_r224.tdf
文件 239728 2018-04-26 20:41 CAN_MCP2515_fpga\db\altsyncram_t224.tdf
文件 142896 2018-04-25 22:24 CAN_MCP2515_fpga\db\altsyncram_v224.tdf
文件 4343 2018-04-25 21:08 CAN_MCP2515_fpga\db\alt_pll1_altpll.v
文件 1683 2018-04-25 20:23 CAN_MCP2515_fpga\db\cmpr_efc.tdf
文件 2005 2018-04-25 20:23 CAN_MCP2515_fpga\db\cmpr_ifc.tdf
文件 2164 2018-04-25 20:23 CAN_MCP2515_fpga\db\cmpr_kfc.tdf
............此处省略113个文件信息
- 上一篇:verilog语言教程
- 下一篇:把玩链接器(iOS分享)
相关资源
- 具有可编程环路补偿功能高密度电源
- FPGA系统中有源电容放电电路设计需注
- 玩转Altera FPGA:基于PLL分频计数的LE
- 二院型号FPGA 硬件描述语言编程准则
- ETC中FM0解码器的设计
- 基于FPGA和万兆网的GigE Vison设计方案
- Xilinx FPGA底层资源架构与设计规范
- fpga多通道采样
- 基于FPGA的电梯控制器系统设计
- 基于MCU+FPGA的LED大屏幕控制系统的设计
- Modelsim学习资料很全
- 宽频带数字锁相环的设计及基于FPGA的
- 一种基于FPGA的三相锁相环设计方法
- 开发板EP4CE10F17C8技术手册.zip
- 基于FPGA的快速并行FFT及应用
- 基于FPGA的移位寄存器流水线结构FFT处
- 基于FPGA的彩色线阵CCD图像采集系统设
- 在FPGA上优化实现复数浮点计算
- 基于FPGA的高速流水线浮点乘法器设计
- 电源纹波调试的小结
- 详析单片机、ARM、FPGA嵌入式的特点和
- 详析单片机、ARM、FPGA嵌入式的特点
- actel fpga外部输入时钟毛刺问题排查与
- 基于Actel FPGA的TFT控制器技术方案设计
- FPGA实现单极性SPWM调制
- uart_tx.zip
- 基于FPGA的多电平载波移相SPWM方法实现
- 基于FPGA的瓦斯浓度模糊控制系统设计
- FPGA最全面的VHDL例程源码
- FPGA工作原理.pdf
评论
共有 条评论