完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
1、NUC970 裸机程序2、怎样配置CAN的寄存器,使CAN通信能够接收任意ID的数据包。
谢谢! The Message Objects and Identifier Masks for acceptance filtering of received messaged in the Message RAM. https://github.com/OpenNuvoton/NUC970_NonOS_BSP/tree/master/SampleCode/CAN int32_t CAN_SetRxMsgObj(UINT32 uCAN, uint8_t u8MsgObj, uint8_t u8idType, uint32_t u32id, uint8_t u8singleOrFifoLast) { UINT32 uOffset = uCAN * CAN_OFFSET; if((inpw(REG_CAN0_IF2_CREQ+uOffset) & CAN_IF_CREQ_BUSY_Msk) != 0) { return FALSE; } /* Command Setting */ outpw((REG_CAN0_IF2_CMASK+uOffset), (CAN_IF_CMASK_WRRD_Msk | CAN_IF_CMASK_MASK_Msk | CAN_IF_CMASK_ARB_Msk | CAN_IF_CMASK_CONTROL_Msk | CAN_IF_CMASK_DATAA_Msk | CAN_IF_CMASK_DATAB_Msk)); if (u8idType == CAN_STD_ID) /* According STD/EXT ID format,Configure Mask and Arbitration register */ { outpw((REG_CAN0_IF2_ARB1+uOffset), 0x0); outpw((REG_CAN0_IF2_ARB2+uOffset), (CAN_IF_ARB2_MSGVAL_Msk | (u32id & 0x7FF)<< 2)); /* Identifier Masks */ /* 参考 NUC970 Technical Reference Manual Page 824. CAN_IFn_ARB2, Bit 15, 0 = The Message Object is ignored by the Message Handler 当把第15位配置成0,将会忽略指定的消息对象,即所有的CAN消息对象将会被处理! */ } else { outpw((REG_CAN0_IF2_ARB1+uOffset), (u32id & 0xFFFF)); outpw((REG_CAN0_IF2_ARB2+uOffset), (CAN_IF_ARB2_MSGVAL_Msk | CAN_IF_ARB2_XTD_Msk | (u32id & 0x1FFF0000)>>16)); } outpw((REG_CAN0_IF2_MCON+uOffset), (inpw(REG_CAN0_IF2_MCON+uOffset) | CAN_IF_MCON_UMASK_Msk | CAN_IF_MCON_RXIE_Msk)); if(u8singleOrFifoLast) { outpw((REG_CAN0_IF2_MCON+uOffset), (inpw(REG_CAN0_IF2_MCON+uOffset) | CAN_IF_MCON_EOB_Msk)); } else { outpw((REG_CAN0_IF2_MCON+uOffset), (inpw(REG_CAN0_IF2_MCON+uOffset) & ~CAN_IF_MCON_EOB_Msk)); } outpw((REG_CAN0_IF2_DAT_A1+uOffset), 0x0); outpw((REG_CAN0_IF2_DAT_A2+uOffset), 0x0); outpw((REG_CAN0_IF2_DAT_B1+uOffset), 0x0); outpw((REG_CAN0_IF2_DAT_B2+uOffset), 0x0); outpw((REG_CAN0_IF2_CREQ+uOffset), (1 + u8MsgObj)); /* Message Object */ return TRUE; } Reference: NUC970 Technical Reference Manual Page 822, (CAN_IFn_MASK2), Msk[28:16] = 0 即可。 Msk[28:16] = 0 The corresponding bit in the identifier of the message object cannot inhibit the match in the acceptance filtering. 以下表述有误: /* 参考 NUC970 Technical Reference Manual Page 824. CAN_IFn_ARB2, Bit 15, 0 = The Message Object is ignored by the Message Handler 当把第15位配置成0,将会忽略指定的消息对象,即所有的CAN消息对象将会被处理! */ 我认为例程和底层的驱动均是基于标识符列表模式,没有屏蔽位模式。因英语水平所限,不知怎样设置成屏蔽位模式,请各位指教,谢谢! |
|
相关推荐
1个回答
|
|
// Set message object identifier mask to accept all message IDs
CAN->CMASK = CAN_CMASK_WRRD_Msk | CAN_CMASK_MASK_Msk; // Enter writing mode and select mask register CAN->MASK = 0x00000000; // Mask all bits (accept all IDs) CAN->CMASK &= ~CAN_CMASK_WRRD_Msk; // Exit writing mode // Configure message object to receive any ID message CAN->CMASK = CAN_CMASK_WRRD_Msk | CAN_CMASK_ARB_Msk; // Enter writing mode and select arbitration register CAN->IF[u8MsgObj].ARB = 0x00000000; // Set message object to receive any ID CAN->CMASK &= ~CAN_CMASK_WRRD_Msk; // Exit writing mode // Configure message object for reception CAN->CMASK = CAN_CMASK_WRRD_Msk | CAN_CMASK_CTRL_Msk; // Enter writing mode and select control register CAN->IF[u8MsgObj].MCON = 0x00000002; // Use message object for reception CAN->IF[u8MsgObj].DATCntL = 8; // Set message object data length to 8 CAN->IF[u8MsgObj].MADR = (uint32_t)&CAN_RxMsg[u8MsgObj][0]; // Set message object data buffer CAN->IF[u8MsgObj].MCONT |= (u8singleOrFifoLast << 15); // Set single or FIFO last mode CAN->CMASK &= ~CAN_CMASK_WRRD_Msk; // Exit writing mode // Enable message object reception CAN->CMASK = CAN_CMASK_SET_Msk | CAN_CMASK_ARB_Msk | CAN_CMASK_CTRL_Msk; // Set transfer request bit and select arbitration and control register CAN->IF[u8MsgObj].MCON |= CAN_MCON_NEWDAT_Msk; // Set new data flag to enable reception CAN->CMASK &= ~CAN_CMASK_SET_Msk; // Unset transfer request bit // Return success return 0; |
|
|
|
只有小组成员才能发言,加入小组>>
3314 浏览 9 评论
2995 浏览 16 评论
3494 浏览 1 评论
9059 浏览 16 评论
4088 浏览 18 评论
1178浏览 3评论
605浏览 2评论
const uint16_t Tab[10]={0}; const uint16_t *p; p = Tab;//报错是怎么回事?
599浏览 2评论
用NUC131单片机UART3作为打印口,但printf没有输出东西是什么原因?
2335浏览 2评论
NUC980DK61YC启动随机性出现Err-DDR是为什么?
1896浏览 2评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 11:51 , Processed in 1.529327 second(s), Total 81, Slave 61 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号