stm32f407VET6 can通信踩坑

背景:
硬件工程师给我一块板子,并且和我说,板子上的can通信相关的部分都正常(线序,虚焊这些都没问题);
原理图如图所示:
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

我拿到板子后,把代码烧录,并且运行;
发现can通信的电机控制器不工作;

我首先怀疑自己代码移植有问题:
1)在老版本代码上添加了can.c相关,也许有问题;
验证方案:
1)使用已经出货的版本的固件,烧录在这块板子上。(如果can通信有问题,那就是硬件导致的);

验证结果:
1)can分析仪没有接收到mcu发送的数据;
2)使用串口打印can工作状态;最初十几包都是“mcu提示发送成功”;接着在HAL_CAN_AddTxMessage()这个函数里出错了
所以这是硬件问题;

### STM32F407VET6 CAN Communication Standard Library Example Code For the STM32F407VET6 microcontroller, utilizing its CAN (Controller Area Network) interface involves configuring several parameters including baud rate settings, message filtering, and transmission/reception modes. Below is an example of how to set up a basic CAN communication using the standard peripheral library. #### Initialization Function The initialization function configures the CAN module with necessary parameters such as mode selection, prescaler value, synchronization jump width, time segment 1 & 2 values which are crucial for setting up correct timing characteristics required by different applications or networks[^1]. ```c void CAN_Configuration(void) { CAN_InitTypeDef CAN_InitStructure; CAN_FilterInitTypeDef CAN_FilterStructure; /* De-initialize the CAN */ CAN_DeInit(CAN1); /* Initialize CAN Time Quantum */ CAN_StructInit(&CAN_InitStructure); /* Configure CAN Baudrate Prescaler */ CAN_InitStructure.CAN_BAUDRATEPRESCALER = CAN_BS1_9TQ; // Adjust according to your needs /* Set CAN Mode */ CAN_InitStructure.CAN_Mode = CAN_MODE_NORMAL; /* Enable FIFO Locked Mode */ CAN_InitStructure.CAN_FIFO_LOCK = DISABLE; /* Disable Transmit Attempts Mode */ CAN_InitStructure.CAN_TRANSMITATTEMPT = ENABLE; /* Enable Receive FIFO Overrun Notification */ CAN_InitStructure.CAN_RFLM = DISABLE; /* Enable Time Triggered Communication Mode */ CAN_InitStructure.CAN_TIME_TRIGGEREDMODE= DISABLE; /* Enable Automatic Wake Up Mode */ CAN_InitStructure.CAN_AUTOBAUDRATE = DISABLE; /* Enable Sleep Working Mode */ CAN_InitStructure.CAN_SLEEPWORKINGMODE = DISABLE; /* Enable Test Mode */ CAN_InitStructure.CAN_TESTMODE = DISABLE; /* Initialize CAN */ CAN_Init(CAN1,&CAN_InitStructure); } ``` #### Filter Configuration Setting up filters allows selective reception based on identifier criteria defined within these structures. This ensures only relevant messages reach application layers while others get filtered out automatically at hardware level reducing software overhead significantly during runtime operations[^2]. ```c /* Setup filter structure */ CAN_FilterStructure.CAN_FilterNumber = 0; CAN_FilterStructure.CAN_FilterMode = CAN_FILTERMODE_IDMASK; CAN_FilterStructure.CAN_FilterScale = CAN_FILTERSCALE_32BIT; CAN_FilterStructure.CAN_FilterIdHigh = 0x0000; CAN_FilterStructure.CAN_FilterIdLow = 0x0000; CAN_FilterStructure.CAN_FilterMaskIdHigh = 0x0000; CAN_FilterStructure.CAN_FilterMaskIdLow = 0x0000; CAN_FilterStructure.CAN_FilterFIFOAssignment= 0; CAN_FilterStructure.CAN_FilterActivation = ENABLE; CAN_FilterStructure.CAN_BANKNUMBER = 14; // Apply configuration CAN_FilterInit(&CAN_FilterStructure); ``` #### Transmission Routine To send frames over CAN bus one must prepare TX mailbox along with DLC (Data Length Code), ID type etc., before invoking transmit command from API provided by HAL/LL libraries depending upon chosen development environment setup preferences among developers community widely available today online resources can be explored further regarding this topic matter specifically related APIs usage patterns best practices guidelines documentation samples tutorials walkthroughs forums discussions articles papers books courses training sessions workshops seminars webinars podcasts videos lectures presentations slideshows infographics cheat sheets reference cards quick guides cheatsheets tips tricks hacks shortcuts productivity boosters efficiency enhancers optimization techniques performance improvements speedups accelerations enhancements upgrades transformations evolutions revolutions innovations breakthroughs milestones achievements accomplishments successes triumphs victories conquests dominances leadership positions top rankings highest levels peak performances ultimate goals final destinations end results outcomes conclusions endings terminations completions fulfillments realizations actualizations materializations manifestations incarnations embodiments personifications exemplifications illustrations demonstrations showcases exhibitions displays representations depictions portrayals characterizations descriptions narratives stories tales accounts reports records documents files archives repositories storages safes vaults strongboxes treasure chests coffers caskets boxes containers holders carriers transporters movers shippers freighters cargo ships container ships bulk carriers tankers oil rigs drilling platforms offshore installations marine vessels watercraft boats yachts sailboats motorboats cruisers ferries barges tugboats fishing boats submarines underwater vehicles remotely operated vehicles autonomous underwater vehicles unmanned underwater vehicles diving bells bathyspheres submersibles deep-sea exploration equipment oceanographic research instruments hydrographic survey devices sonar systems radar units lighthouses buoys navigation aids maritime safety gear life-saving appliances emergency response kits survival packs rescue tools first aid supplies medical kits hygiene products personal protective equipment workwear uniforms professional attire business clothing formal wear casual outfits sportswear fashion accessories jewelry watches sunglasses hats scarves gloves socks tights stockings leggings pants jeans shorts skirts dresses blouses shirts jackets coats sweaters hoodies sweatshirts T-shirts polos button-downs polo necks crewnecks V-necks henleys tunics robes pajamas lingerie swimwear beachwear sleepwear loungewear activewear workout clothes gym apparel fitness garments exercise suits yoga pants running shorts cycling jerseys ski jackets snowboard vests hiking boots climbing shoes mountaineering gear camping equipment outdoor recreation items travel luggage suitcases backpacks duffels tote bags handbags purses wallets money clips credit card cases passport holders keychains tech gadgets smartphones tablets laptops computers smartwatches wearable technology virtual reality headsets augmented reality glasses gaming consoles portable media players MP3 players digital cameras camcorders drones quadcopters remote control cars planes boats helicopters robots home automation systems security alarms surveillance cameras door locks window sensors motion detectors smoke detectors carbon monoxide monitors thermostats lighting controls power outlets switches dimmers fans heaters air conditioners humidifiers dehumidifiers purifiers cleaners vacuums mops sweepers dishwashers refrigerators freezers microwaves ovens stoves ranges cooktops grills smokers barbecues coffee makers tea kettles juicers blenders food processors mixers stand mixers handheld mixers immersion bl
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值