usbxyz / can-bootloader Goto Github PK
View Code? Open in Web Editor NEW使用USB2XXX实现的CAN Bootloader功能,实现CAN节点固件远程升级
License: GNU General Public License v3.0
使用USB2XXX实现的CAN Bootloader功能,实现CAN节点固件远程升级
License: GNU General Public License v3.0
也就是当命令地址为0的时候,每个节点收到命令之后都应该执行该命令,但是由于同一时刻,CAN总线上不能传输多个节点的数据,所以这些从节点再执行0地址命令的时候可以不用返回状态
不能同时传输,但可以依次传输啊,为何不能返回状态呢?
star
本人使用STM32F103ZET6型号单片机,CAN1的TX RX引脚复用到GPIOD_0和GPIOD_1上面。
在参考了博主的资料后以下是本人的GPIO初始化代码,如有问题还请帮忙指正!
static void CANPort_GPIO_Config(void)
{
/*-----------------1.使能GPIO_D并重映射为CAN1---------------------*/
/*-----------------1.1使能GPIO_D1 CAN TX引脚---------------------*/
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE); //使能GPIOD的时钟
RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE); //使能CAN1时钟
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //CAN TX发送引脚
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD,&GPIO_InitStructure);
/*-----------------1.2使能GPIO_D0 CAN RX引脚---------------------*/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //上拉输入
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Init(GPIOD,&GPIO_InitStructure); //初始化TX引脚
GPIO_PinRemapConfig(GPIO_Remap2_CAN1, ENABLE);
}
static void CAN_Mod_Config(void)
{
/*--------CAN配置结构体---------------*/
CAN_InitTypeDef CAN_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
CAN_DeInit(CAN1); //CAN结构体复位
CAN_StructInit(&CAN_InitStructure); //CAN结构体初始化
#if CAN_INT_ENABLE
NVIC_InitTypeDef NVIC_InitStructure;
#endif
// CAN_InitStructure.CAN_TTCM=DISABLE; //MCR-TTCM 关闭时间触发通信模式使能
// CAN_InitStructure.CAN_ABOM=ENABLE; //MCR-ABOM 使能自动离线管理
// CAN_InitStructure.CAN_AWUM=ENABLE; //MCR-AWUM 使用自动唤醒模式
// CAN_InitStructure.CAN_NART=DISABLE; //MCR-NART 禁止报文自动重传
// CAN_InitStructure.CAN_RFLM=DISABLE; //MCR-RFLM 接收 FIFO 不锁定
/*------------------设置CAN的工作模式-------------------------*/
CAN_InitStructure.CAN_TTCM=DISABLE; //非时间触发通信模式
CAN_InitStructure.CAN_ABOM=DISABLE; //软件自动离线管理
CAN_InitStructure.CAN_AWUM=DISABLE; //睡眠模式通过软件唤醒(清除CAN->MCR的SLEEP位)
CAN_InitStructure.CAN_NART=ENABLE; //禁止报文自动传送
CAN_InitStructure.CAN_RFLM=DISABLE; //报文不锁定,新的覆盖旧的
CAN_InitStructure.CAN_TXFP=DISABLE; //优先级由报文标识符决定
CAN_InitStructure.CAN_Mode= CAN_Mode_Normal; //模式设置:CAN_Mode_Normal 普通模式,CAN_Mode_LoopBack 回环模式;
/*--------------------设置CAN的通信速率----------------------------*/
//CANbps= Fpclk/((BRP+1)*((Tseg1+1)+(Tseg2+1)+1)
//例如CANbps=APB1总线频率30000000/4/(8+6+1))=500k bps
//总体配置方向: Tseg1>=Tseg2 Tseg2>=tq; Tseg2>=2TSJW
CAN_InitStructure.CAN_SJW=CAN_SJW_1tq; //设置项目(1~4)
CAN_InitStructure.CAN_BS1=CAN_BS1_6tq; //设置项目(1~16)
CAN_InitStructure.CAN_BS2=CAN_BS2_3tq; //设置项目(1~8)
CAN_InitStructure.CAN_Prescaler=10; //设置项目(1~1024)
CAN_Init(CAN1,&CAN_InitStructure);
/*---------------设置过滤器------------------------*/
CAN_FilterInitStructure.CAN_FilterNumber = 0;
CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdMask; //屏蔽位模式
CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_32bit; //32位宽
CAN_FilterInitStructure.CAN_FilterIdHigh=0x0000; //32位ID
CAN_FilterInitStructure.CAN_FilterIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterMaskIdHigh=0x0000;//32位MASK
CAN_FilterInitStructure.CAN_FilterMaskIdLow=0x0000;
CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_Filter_FIFO0;//过滤器0关联到FIFO0
CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;//激活过滤器0
CAN_FilterInit(&CAN_FilterInitStructure); //滤波器初始化
#if CAN_INT_ENABLE //以下是用于CAN中断方式接收的设置
CAN_ITConfig(CAN1,CAN_IT_FMP0,ENABLE); //FIFO0消息挂号中断允许.
NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // 主优先级为1
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // 次优先级为0
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
#endif
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.