野火stm32-CAN(Loopback)
时间:2025-02-23
时间:2025-02-23
CAN Ё 偠
firefirestm32@http:// STM32 ST3.0.0
偠 can 偠(Ё ) USART1 ッЁ
PB8-CAN-RX
PB9-CAN-TX
startup/start_stm32f10x_hd.c
CMSIS/core_cm3.c
CMSIS/system_stm32f10x.c
FWlib/stm32f10x_gpio.c
FWlib/stm32f10x_rcc.c
FWlib/stm32f10x_usart.c
FWlib/stm32f10x_can.c
FWlib/misc.c
: USER/main.c
USER/stm32f10x_it.c
USER/led.c
USER/usart.c
USER/can.c
CAN ->
CAN (Controller Area Network, CAN) BOSCH ISO118?8 П CAN CAN J1939 催
STM32 CPU(cpu STM32F103VET6) CAN I/O Н PB8-CAN-RX PB9-CAN-TX CAN
TJA1050 CAN CAN CAN Ё CAN CAN
STM32 ЁCAN
偠Ё CAN CAN CAN CAN TX RX
偠 ->
佪 Ё
FWlib/stm32f10x_gpio.c
FWlib/stm32f10x_rcc.c
FWlib/stm32f10x_usart.c
FWlib/stm32f10x_can.c
FWlib/misc.c
c stm32f10x_conf.hЁ 1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.22.
23.
24./*Includes------------------------------------------------------------------*//*Uncommentthelinebelowtoenableperipheralheaderfileinclusion*//*#include"stm32f10x_adc.h"*//*#include"stm32f10x_bkp.h"*/#include"stm32f10x_can.h"/*#include"stm32f10x_crc.h"*//*#include"stm32f10x_dac.h"*//*#include"stm32f10x_dbgmcu.h"*//*#include"stm32f10x_dma.h"*//*#include"stm32f10x_exti.h"*//*#include"stm32f10x_flash.h"*//*#include"stm32f10x_fsmc.h"*/#include"stm32f10x_gpio.h"/*#include"stm32f10x_i2c.h"*//*#include"stm32f10x_iwdg.h"*//*#include"stm32f10x_pwr.h"*/#include"stm32f10x_rcc.h"/*#include"stm32f10x_rtc.h"*//*#include"stm32f10x_sdio.h"*//*#include"stm32f10x_spi.h"*//*#include"stm32f10x_tim.h"*/#include"stm32f10x_usart.h"/*#include"stm32f10x_wwdg.h"*/#include"misc.h"/*HighlevelfunctionsforNVICandSysTick(add-
ontoCMSISfunctions)*/
OK main
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23./***@briefMainprogram.*@paramNone*@retval:None*/intmain(void){/*configthesysclockto72M*/SystemInit();/*USART1config*/USART1_Config();/*LEDconfig*/LED_GPIO_Config();printf("\r\n CAN Ё ......\r\n");USER_CAN_Init();printf("\r\nCAN ......\r\n");USER_CAN_Test();printf("\r\nCAN ......\r\n");while(1){}}
佪 SystemInit(); 72MHZ USART1_Config(); LEDLED_GPIO_Config(); 偠Ё
LED ゴ ЁUSART1_Config(); LED_GPIO_Config();
USER_CAN_Init(); CAN I/O ッ Ё ( ㄝ CAN Ё ) can.cЁ 1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.}/** CAN_Init* * * * */voidUSER_CAN_Init(void){CAN_NVIC_Configuration();CAN_GPIO_Config(); CAN ッ Ё :
USER_CAN_Init(); CAN_NVIC_Configuration(); CAN_GPIO_Config(); Н М г can.cЁ 1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14./*EnableCAN1RX0interruptIRQchannel*/NVIC_InitStructure.NVIC_IRQChannel=USB_LP_CAN1_RX0_IRQn;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;// 0/** CAN_NVIC_Configuration * * * * */staticvoidCAN_NVIC_Configuration(void){NVIC_InitTypeDefNVIC_InitStructure; CANRX0Ё :
15.
16.
17.
18.}NVIC_InitStructure.NVIC_IRQChannelSubPriority=0;NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;NVIC_Init(&NVIC_InitStructure);// 0
CAN_GPIO_Config(void) Ё CAN RX TX I/O
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11./** CAN_GPIO_Config * * * * */staticvoidCAN_GPIO_Config(void){GPIO_InitTypeDefGPIO_InitStructure;RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO|RCC_APB2Periph_GPIOB,ENABLE); CANGPIO :
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.}/*CAN1Periphclockenable*/RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1,ENABLE);/*ConfigureCANpin:RX*/GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;GPIO_Init(GPIOB,&GPIO_InitStructure);//PB8// /*ConfigureCANpin:TX*/GPIO_InitStructure.GPIO_Pin=GPIO_Pin_9;GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;GPIO_Init(GPIOB,&GPIO_InitStructure);//PB9// //#defineGPIO_Remap_CANGPIO_Remap1_CAN1 偠 I/OGPIO_PinRemapConfig(GP …… 此处隐藏:5615字,全部文档内容请下载后查看。喜欢就下载吧 ……