查看: 8950|回复: 7

[MPC] MPC5604B的CAN接收中断程序疑问

[复制链接]

该用户从未签到

3

主题

7

帖子

0

新手上路

Rank: 1

积分
17
最后登录
1970-1-1
发表于 2013-4-29 14:47:49 | 显示全部楼层 |阅读模式
 
看datasheet有点看不懂
我直接贴程序和datasheet的语句
下面是datasheet的资料
Each one of the message buffers can be an interrupt source, if its corresponding IMASK bit is set. There
is no distinction between Tx and Rx interrupts for a particular buffer, under the assumption that the buffer
is initialized for either transmission or reception. Each of the buffers has assigned a flag bit in the IFLAG
Registers. The bit is set when the corresponding buffer completes a successful transmission/reception and
is cleared when the CPU writes it to ‘1’ (unless another interrupt is generated at the same time).
                                                      NOTE
It must be guaranteed that the CPU only clears the bit causing the current
interrupt. For this reason, bit manipulation instructions (BSET) must not be
used to clear interrupt flags. These instructions may cause accidental
clearing of interrupt flags which are set after entering the current interrupt
service routine.
好像是说清除中断标志位最好不使用位操作来清除。我是直接采用位操作来清除的,但是原因我不是很清楚。希望有人帮忙解释下。
下面是我写的中断程序,可以运行,但是我不知道以后出现特殊情况会不会导致BUG。

static  void Can0FrameToData(u8  ucIdIndex)
{
    int j, dummy; 
    RxCODE   = CAN_0.BUF[ucIdIndex].CS.B.CODE;    /* Read CODE, ID, LENGTH, DATA, TIMESTAMP */
    stCanRxBuffer[ucIdIndex].ulCanID     = CAN_0.BUF[ucIdIndex].ID.R;
    stCanRxBuffer[ucIdIndex].ulCanLength = CAN_0.BUF[ucIdIndex].CS.B.LENGTH;   
    for (j=0; j < stCanRxBuffer[ucIdIndex].ulCanLength; j++)
    {
        stCanRxBuffer[ucIdIndex].aucCanData[j] = CAN_0.BUF[ucIdIndex].DATA.B[j];
    }  
    stCanRxBuffer[ucIdIndex].ulMesgTime = CAN_0.BUF[ucIdIndex].CS.B.TIMESTAMP;
    dummy = CAN_0.TIMER.R;                /* Read TIMER to unlock message buffers */  
  //  CAN_0.IFRL.R |= (0x00000001)
我知道答案 目前已有7人回答
回复

使用道具 举报

该用户从未签到

0

主题

45

帖子

0

注册会员

Rank: 2

积分
146
最后登录
1970-1-1
发表于 2013-5-7 14:24:46 | 显示全部楼层

RE:MPC5604B的CAN接收中断程序疑问

Using a bit manipulation instruction to clear an interrupt flag by writing a '1' can
result in other interrupt flags being inadvertently cleared.
The BSET instruction is a read, modify, write command. That is it reads the
contents of a memory location, modifies the contents, and then writes the
modified value back to the memory location.
In the case of BSET it reads the memory contents, performs a logical OR with
a user defined mask byte and then writes the contents back to the memory
location.
BSET Operation: (Memory Contents) + (Mask) ⇒ (Memory Location)
Thus it is possible that if two or more interrupt flag bits are set and a BSET
command is used to clear one of the flag bits, all of the interrupt flags which are
set will be cleared.
Using a MSCAN Receiver Flag Register (CRFLG) as an example, we see that
it consists of 8 interrupts flags.
不要采用iflag值与mask值与过之后的值去位操作写回,直接哪个flag处理完清除哪个就ok了
回复 支持 反对

使用道具 举报

该用户从未签到

1

主题

5

帖子

0

新手上路

Rank: 1

积分
15
最后登录
1970-1-1
发表于 2013-8-5 17:01:58 | 显示全部楼层

RE:MPC5604B的CAN接收中断程序疑问

请教版主:CAN接收必须使用中断吗?如果使用不停扫描CAN_0.IFRL.B.BUF04I位是否置位,去读CAN数据,为什么不可以?该位一直是0,程序死在这里。
回复 支持 反对

使用道具 举报

该用户从未签到

7

主题

66

帖子

0

注册会员

Rank: 2

积分
155
最后登录
2020-12-15
发表于 2013-8-8 23:03:57 | 显示全部楼层

回复:MPC5604B的CAN接收中断程序疑问

在接收之前要设置一系列参数,包括接收的是标准帧还是扩展帧、数据帧还是遥控帧以及接收的匹配ID值。CAN接收到任何数据时,开始都是存放在“虚拟缓冲器”的。当Cpu检测到虚拟缓冲器中的信息帧满足上面设置的要求时,才会将数据存放在CAN缓冲器中,这样既可成功接收,相应中断标志位才会置位。置位后必须软件清中断标志位,这样既可接收下一帧数据。所以接收Can数据并非必须通过中断,查询方式同样可以。
回复 支持 反对

使用道具 举报

该用户从未签到

0

主题

39

帖子

0

新手上路

Rank: 1

积分
81
最后登录
1970-1-1
发表于 2013-9-2 16:51:05 | 显示全部楼层

RE:MPC5604B的CAN接收中断程序疑问

可否介绍一下您用的是飞思卡尔的评估板吗?
有些跳线需要配置正确。
另外建议在最开始调试时使用MB8之后的,可能可以更方便点。
如果目前仍未调通,请联系我,我有验证过可以收发的程序。
回复 支持 反对

使用道具 举报

该用户从未签到

0

主题

25

帖子

0

新手上路

Rank: 1

积分
12
最后登录
1970-1-1
发表于 2013-12-20 13:53:46 | 显示全部楼层

回复:MPC5604B的CAN接收中断程序疑问

芯片中文资料上搜IC数据手册看中文版吧,700多万中文datasheet,还可以用中文关键字搜索数据手册内容
回复 支持 反对

使用道具 举报

该用户从未签到

0

主题

25

帖子

0

新手上路

Rank: 1

积分
12
最后登录
1970-1-1
发表于 2013-12-20 13:54:35 | 显示全部楼层

回复:MPC5604B的CAN接收中断程序疑问

芯片中文资料上搜IC数据手册看中文版吧,700多万中文datasheet,还可以用中文关键字搜索数据手册内容
回复 支持 反对

使用道具 举报

该用户从未签到

0

主题

2

帖子

0

新手上路

Rank: 1

积分
16
最后登录
2018-6-5
发表于 2018-6-5 14:51:43 | 显示全部楼层
楼主,MPC5604B CAN接收的问题解决了吗,有没有代码可以给小弟参考一下,邮箱:allance_wang@163.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 注册/登录

本版积分规则

关闭

站长推荐上一条 /3 下一条

Archiver|手机版|小黑屋|恩智浦技术社区

GMT+8, 2025-9-11 10:02 , Processed in 0.098124 second(s), 27 queries , MemCache On.

Powered by Discuz! X3.4

Copyright © 2001-2024, Tencent Cloud.

快速回复 返回顶部 返回列表