首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

CAN通信求助!!!(发送不出去,接收不到:( )

还有要注意置位发送请求位的操作,我这个写入1才是清除(虽然写入是1,但被清零了)
我就是被这个给弄了好长时间!

菜鸟所见哈,如果不是,别见笑哈〉。。。。:)
fly in the sky
这我都考虑到了,我可能是因为板子的问题吧.那你现在看到什么现象啊?
如果你早点把程序给我看,你上面的问题你会早点解决的.
我发送板子reset重新发送数据时,接受板子的led会被点亮(我设置好的led)
我用示波器也能观察到MSCAN_TX有波形...
fly in the sky
是在2块板子之间通信的吗?只有发送方也是可以的吗?

是两块板子之间的通信
只有发送的话,也可以看到波形变化的阿
fly in the sky

不知道为什么,我发送的数据和接受到的不一致.:(
各位大虾帮帮忙阿 ,拜托了

可是,接受缓冲区满标志位被置起了阿,不过我设置的接收符ID过滤屏蔽码寄存器都是1,也就是全部接收,这应该不是问题吧?,因为就两个板子之间的通信,没有其他CAN节点.

[此贴子已经被作者于2006-5-25 16:34:23编辑过]

fly in the sky
我用的是GZ16

#include
#include "main.h"

#define BAUDRATE_125k 0x0000
#define BAUDRATE_250k 0x0001
#define BAUDRATE_500k 0x0002

#define COMMSTATUS_INIT 0x0000
#define COMMSTSTUS_RCVOPEN 0x1111
#define COMMSTATUS_RCVEND 0x2222
#define COMMSTSTUS_SNDOPEN 0x3333
#define COMMSTSTUS_SNDEND 0x4444

static unsigned short s_wCANCommBuffer[100];
static unsigned short s_wCANCountSend;
static unsigned short s_wCANCommStatus;
static unsigned short s_wCANCountTimeout;
static unsigned short* s_pCANRcvPointer;
static unsigned short* s_pCANRcvEndPointer;
static unsigned short* s_pCANSndPointer;
static unsigned short* s_pCANSndEndPointer;

static void InitCAN(void)
{
CMCR0 = 0x01; //softset状态
CMCR1 = 0x01; //时钟bus
CIDAR0 = 0xff; //标准数据桢
CIDAR1 = 0xe0;
CIDAR2 = 0x00;
CIDAR3 = 0x00;
CIDMR0 = 0xff; //取消屏蔽码
CIDMR1 = 0xff;
CIDMR2 = 0xff;
CIDMR3 = 0xff;
CIDAC = 0x00; //32BIT接受
switch(GetBautRate()) //波特率
{
case BAUDRATE_125k: CBTR0 = 0x49; CBTR1 = 0x00; break;
case BAUDRATE_250k: CBTR0 = 0x49; CBTR1 = 0x00; break;
case BAUDRATE_500k: CBTR0 = 0x49; CBTR1 = 0x00; break;
default:break;
}
CRIER = 0x00;//接收中断不使能
CTCR = 0x00; //发送中断优先级不使能
CMCR0 = 0x00; //正常模式
}

static void InitCommStatus(void)
{
s_wCANCountTimeout = 50000;//超时益处时间设定
s_wCANCountSend = 14;
s_wCANCommStatus = COMMSTATUS_INIT;
}
void OnInitCAN(void)
{
InitCAN();
InitCommStatus();
}
static void CANSendPackage(void)//CAN发送数据包
{
wCountSend = 0x08;
if(CTFLG_TXE0) //判断是否为空
{
IDR00 = 0xff; //标准数据桢
IDR10 = 0xe0;
IDR20 = 0x00;
IDR30 = 0x00;

DLR0 = wCountSend&0x0f; //长度

DSR00 = s_pCANSndPointer[0]&0xff;//发送的数据
DSR10 = s_pCANSndPointer[1]&0xff;
DSR20 = s_pCANSndPointer[2]&0xff;
DSR30 = s_pCANSndPointer[3]&0xff;
DSR40 = s_pCANSndPointer[4]&0xff;
DSR50 = s_pCANSndPointer[5]&0xff;
DSR60 = s_pCANSndPointer[6]&0xff;
DSR70 = s_pCANSndPointer[7]&0xff;
TBPR0 = 0x01; //优先级
CTFLG_TXE0 = 1; //启动发送
s_pCANSndPointer += wCountSend; //指针后移
}
}
void OnPollingCAN(void) //此函数每1ms调用一次
{
unsigned short wSndCount;
unsigned short wAddress;
if(s_wCANCountTimeout>0)
{
s_wCANCountTimeout--;
if(s_wCANCountTimeout==0)
{
InitCAN();
InitCommStatus();
}
}
switch(s_wCANCommStatus)
{
case COMMSTATUS_INIT:
s_wCANCountTimeout = 2000;
s_wCANCommStatus = COMMSTSTUS_SNDOPEN;
s_pCANSndPointer = s_wCANCommBuffer; //发送指针初始地址
s_pCANSndEndPointer = s_wCANCommBuffer+8; //发送指针结束地址
break;
case COMMSTSTUS_RCVOPEN:
break;
case COMMSTATUS_RCVEND:
s_wCANCountTimeout = 5000;
s_wCANCommStatus = COMMSTSTUS_SNDOPEN;
break;
case COMMSTSTUS_SNDOPEN:
if(s_pCANSndPointer!=s_wCANCommBuffer) //等待发送结束
{
if(s_wCANCountSend)
{
s_wCANCountSend--;
break;
}
}
s_wCANCountSend = 14;
s_wCANCountTimeout = 5000;
CANSendPackage(); //发送
if(s_pCANSndPointer>=s_pCANSndEndPointer) //发送完成
{
PTE_PTE0 = 1;
s_wCANCommStatus = COMMSTATUS_INIT; 重新开始发送
}
break;
case COMMSTSTUS_SNDEND:
break;
default:
OnInitCAN();
break;
}
}

在配置寄存器中已经对CAN模块使能:
CONFIG2 = 0x09;
硬件采用的是VP251,TI公司的,不需要使能。
发送一点信号都没有,不知道是什么原因,是不是初始化的时候有问题,请斑竹给予帮助!!在线等待中!!!!着急啊。。。。。555555555555555555555
GZ16好像是CTFLAG_TXE0=0;是启动发送啊[em22][em22]
返回列表