完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
使用CH32F20这款MCU的CAN通信,例子代码看不懂,有无大侠解释一下:
代码如下: 1)函数的各参数是什么含义?除了Bps =Fpclk1/((tpb1+1+tbs2+1+1)*brp)含义以外,各参数设置注意哪些事项。 2)函数内的各个设置都有哪些注意事项 void CAN_Test_Mode_Init( u8 tsjw, u8 tbs2, u8 tbs1, u16 brp, u8 mode ) { GPIO_InitTypeDef GPIO_InitSturcture = {0}; CAN_InitTypeDef CAN_InitSturcture = {0}; CAN_FilterInitTypeDef CAN_FilterInitSturcture = {0}; RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOB, ENABLE ); RCC_APB1PeriphClockCmd( RCC_APB1Periph_CAN1, ENABLE ); GPIO_PinRemapConfig( GPIO_Remap1_CAN1, ENABLE ); GPIO_InitSturcture.GPIO_Pin = GPIO_Pin_9; GPIO_InitSturcture.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitSturcture.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init( GPIOB, &GPIO_InitSturcture ); GPIO_InitSturcture.GPIO_Pin = GPIO_Pin_8; GPIO_InitSturcture.GPIO_Mode = GPIO_Mode_IPU; GPIO_Init( GPIOB, &GPIO_InitSturcture ); CAN_InitSturcture.CAN_TTCM = DISABLE; CAN_InitSturcture.CAN_ABOM = DISABLE; CAN_InitSturcture.CAN_AWUM = DISABLE; CAN_InitSturcture.CAN_NART = ENABLE; CAN_InitSturcture.CAN_RFLM = DISABLE; CAN_InitSturcture.CAN_TXFP = DISABLE; CAN_InitSturcture.CAN_Mode = mode; CAN_InitSturcture.CAN_SJW = tsjw; CAN_InitSturcture.CAN_BS1 = tbs1; CAN_InitSturcture.CAN_BS2 = tbs2; CAN_InitSturcture.CAN_Prescaler = brp; CAN_Init( CAN1, &CAN_InitSturcture ); CAN_FilterInitSturcture.CAN_FilterNumber = 0; CAN_FilterInitSturcture.CAN_FilterMode = CAN_FilterMode_IdMask; CAN_FilterInitSturcture.CAN_FilterScale = CAN_FilterScale_32bit; CAN_FilterInitSturcture.CAN_FilterIdHigh = 0; CAN_FilterInitSturcture.CAN_FilterIdLow = 0; CAN_FilterInitSturcture.CAN_FilterMaskIdHigh = 0; CAN_FilterInitSturcture.CAN_FilterMaskIdLow = 0x0006; CAN_FilterInitSturcture.CAN_FilterFIFOAssignment = CAN_Filter_FIFO1; CAN_FilterInitSturcture.CAN_FilterActivation = ENABLE; CAN_FilterInit( &CAN_FilterInitSturcture ); } |
|
相关推荐
1个回答
|
|
你好,如果需要,可以留个邮箱,给你发一份关于CAN协议的文档以及配置教程
|
|
|
|
只有小组成员才能发言,加入小组>>
491 浏览 1 评论
CH579M+RT-Thread,RTC从Sleep模式唤醒失败是什么原因?
2884 浏览 2 评论
2374 浏览 1 评论
834浏览 2评论
511浏览 1评论
CH32F103C8T6使用当前官网上的CDC例程会出现设备描述符请求失败
379浏览 1评论
657浏览 1评论
riscv-none-embed-objcopy: \'PWM_Output.elf\': No such file这个咋解决,
396浏览 1评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-2 11:04 , Processed in 0.895675 second(s), Total 48, Slave 42 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号