Is it possible to configure the CAN module to prevent receiving unnecessary message’s interrupt?
Answer
The Bosch CAN module supports both 11-bit (standard) and 29-bit (extended) message identifiers. The UMask bit determines whether any of the mask bits (Msk28-0, MXtd, and MDir) are used for acceptance filtering, and the corresponding bit of Mask Registers should be set for 11-bit (standard) or 29-bit (extended) message identifiers. The MXtd and MDir bits indicate whether the Xtd and Dir bit are used for acceptance filtering.
However, after configuring the acceptance filtering, the CAN controller may receive some unmatched message’s interrupt if the SIE bit (Status Change Interrupt Enable) is enabled.
The SIE bit is used to disable/enable status change interrupt, if this bit be enabled, an interrupt will be generated when a message transfer is successfully completed or a CAN bus error is detected.
Status interrupts may be caused by:
Transmission from the CAN modules (TxOK is set) is successful.
Reception of a message on the CAN bus is successful independent of the result of acceptance filtering. IntId register indicate the number of matched message object which caused the interrupt, for the unmatched message, the IntId will be 0x0.
An error on the CAN bus is detected
Enable the SIE will cause the interrupt whenever a message be acknowledged in the CAN bus, and if the IE be set, the interrupt will line to the CPU.
If don’t need to monitor the CAN bus activity closely, this bit will not be recommended to set. And the CAN module will only generate the interrupt after receiving the message matched acceptance filtering.
8-bit Knowledge Base
How to configure the CAN module to prevent unnecessary message’s interrupt
在BL51或LX51中使用常量来设定flash lock字节值
问题
是否可以在编译代码时指定8051 MCU lock 字节的值 ?
答案
可以,在使用Keil C51工具链时,可以很容易的通过BL51或LX51来实现
首先,需要在代码中的某个位置初始化lock 字节的设定。譬如,可以创建一个新的文件,并命名为”lockbyte.c”,然后在其中加入如下的代码,
这段代码将会在flash中占用一个byte,且其初始值为0,但此时并未指定其具体地址。为了将这个字节放置在flash的lock字节位置,需要使用到链接器。
关于lock字节的地址,请查阅相应MCU的参考手册。例如EFM8BB1F8的lock 字节在flash的0x1FFF位置。
如果使用Simplicity Studio,链接器的指令可以在如下位置修改,Project -> Properties -> C/C++ Build -> Settings-> Keil 8051 Linker > Miscellaneous。然后在[Additional Flags]中添加链接器指令。
如果使用LX51,请在[Additional Flags]中添加如下命令:
如果使用LX51,同时该MCU有code banking, 则需要指定code bank以及地址。例如,使用如下命令将LOCKBYTE放置在bank3 0x1FFFF位置。
如果REMOVEUNUNUSED有被使能,那么需要使用OVERLAY命令以保证其不会处理该lock字节,否则链接器会将LOCKBYTE从代码段移除掉。REMOVEUNUNUSED设定在如下位置:
如果使用BL51,相应的命令如下
编译完成之后,查看.m51文件或.hex文件,即可以确定是否有将常量放置在指定的lock字节(0x1FFF)位置,同时其初始值是否正确。
此外还有一种比较简单直接的方法就是手动修改HEX文件,在HEX文件结束符之前加入一行用来锁定Flash
以C8051F02x MCU为例,其lock byte在0xFDFE和0xFDFF,手动修改HEX文件如下:
...
...User code...
...
:02FDFE00000003
:00000001FF
其中
02 表示包含2个字节数据
FDFE 表示起始地址
00 表示记录类型(普通数据)
0000 待写入的值
03 校验和
00000001FF 文件结束符
SPI最大传输速率