打印
[CAN-bus/DeviceNet]

SJA1000不工作

[复制链接]
1930|2
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
xzffff|  楼主 | 2012-9-20 14:45 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
第一次使用SJA1000,寄存器读写已经ok了,但是在自测试模式下,发送数据了一直没有中断产生。下面是我的初始化代码:

RST1_ACTIVE;
// 200ns
DelayCPUClock(40);
Sleep(200);
RST1_INACTIVE;

Sleep(500);

// wait to enter reset mode
ucTemp = ReadSja1000REG(pSJA1000Head, REG_MODE);
while( (ucTemp&MODE_RM) != MODE_RM )
{
  WriteSja1000REG(pSJA1000Head, REG_MODE, MODE_RM|MODE_AFM);
  ucTemp = ReadSja1000REG(pSJA1000Head, REG_MODE);
}

// PeliCAN mode, CBP, disable CLKOUT
WriteSja1000REG(pSJA1000Head, REG_CDR, 0xC8);

// close all interrupt
WriteSja1000REG(pSJA1000Head, REG_IER, 0x00);

// allow all data
WriteSja1000REG(pSJA1000Head, REG_ACR0, 0x00);
WriteSja1000REG(pSJA1000Head, REG_ACR1, 0x00);
WriteSja1000REG(pSJA1000Head, REG_ACR2, 0x00);
WriteSja1000REG(pSJA1000Head, REG_ACR3, 0x00);
WriteSja1000REG(pSJA1000Head, REG_AMR0, 0xFF);
WriteSja1000REG(pSJA1000Head, REG_AMR1, 0xFF);
WriteSja1000REG(pSJA1000Head, REG_AMR2, 0xFF);
WriteSja1000REG(pSJA1000Head, REG_AMR3, 0xFF);

// set timing
WriteSja1000REG(pSJA1000Head, REG_BTR0, pSJA1000Head->BBTR0);
WriteSja1000REG(pSJA1000Head, REG_BTR1, pSJA1000Head->BBTR1);

// set output control
WriteSja1000REG(pSJA1000Head, REG_OCR, 0x1A);

//clear reg
WriteSja1000REG(pSJA1000Head, REG_RXERR, 0x00);
WriteSja1000REG(pSJA1000Head, REG_TXERR, 0x00);
WriteSja1000REG(pSJA1000Head, REG_RBSA, 0x00);
ReadSja1000REG(pSJA1000Head, REG_ECC);

for(i=0; i<32; i++)
{
  ucTemp = ReadSja1000REG(pSJA1000Head, i);
  RETAILMSG(1,(TEXT("sja1000 reg: %d -- 0x%x\r\n"),i,ucTemp));
}

// wait to enter work mode
ucTemp = ReadSja1000REG(pSJA1000Head, REG_MODE);
while( (ucTemp&MODE_RM) == MODE_RM )
{
  WriteSja1000REG(pSJA1000Head, REG_MODE, MODE_AFM|MODE_STM);  //test
  ucTemp = ReadSja1000REG(pSJA1000Head, REG_MODE);
}

WriteSja1000REG(pSJA1000Head, REG_IER, IER_BEIE|IER_ALIE|IER_EPIE|IER_DOIE|IER_EIE|IER_RIE);
//release receive buffer
WriteSja1000REG(pSJA1000Head, REG_CMR, CMR_RRB);

发送数据的代码是:

        RETAILMSG(1,(TEXT("DoTxData\r\n")));
       
        ucStatus = ReadSja1000REG(pHWHead->pSJA1000Info, REG_SR);
        while( (ucStatus&SR_TBS) != SR_TBS )
        {
                Sleep(5);
                ucStatus = ReadSja1000REG(pHWHead->pSJA1000Info, REG_SR);
        }
       
        for(ucLoop=0; ucLoop<Len; ucLoop++)
        {
                WriteSja1000REG(pHWHead->pSJA1000Info, REG_TX_INFO+ucLoop, pBuf[ucLoop]);
        }
       
        ucTemp = ReadSja1000REG(pHWHead->pSJA1000Info, REG_IER);
        ucTemp |= IER_TIE;
        WriteSja1000REG(pHWHead->pSJA1000Info, REG_IER, ucTemp);
        WriteSja1000REG(pHWHead->pSJA1000Info, REG_CMR, CMR_SRR|CMR_TR);        //test

发送数据命令下发后,一直没有中断产生。
在初始化进入工作模式之前的读出来的寄存器值是:
sja1000 reg: 0 -- 0x1
sja1000 reg: 2 -- 0x3c
sja1000 reg: 6 -- 0x1c
sja1000 reg: 8 -- 0x1a
sja1000 reg: 13 -- 0x60
sja1000 reg: 20 -- 0xff
sja1000 reg: 21 -- 0xff
sja1000 reg: 22 -- 0xff
sja1000 reg: 23 -- 0xff
sja1000 reg: 31 -- 0xc8
其它都是0
下发发送数据的命令之后,读出来的寄存器值是:
sja1000 reg: 0 -- 0xc
sja1000 reg: 2 -- 0x30
sja1000 reg: 4 -- 0xef
sja1000 reg: 6 -- 0x1c
sja1000 reg: 8 -- 0x1a
sja1000 reg: 13 -- 0x60
sja1000 reg: 16 -- 0x6e
sja1000 reg: 17 -- 0xff
sja1000 reg: 18 -- 0xf8
sja1000 reg: 19 -- 0xff
sja1000 reg: 20 -- 0x0
sja1000 reg: 21 -- 0x1
sja1000 reg: 22 -- 0x80
sja1000 reg: 23 -- 0x3
sja1000 reg: 24 -- 0xfe
sja1000 reg: 25 -- 0xff
sja1000 reg: 26 -- 0xe7
sja1000 reg: 27 -- 0xdf
sja1000 reg: 31 -- 0xc8
其它都是0.
下发发送数据的命令之后,过了10秒钟,寄存器的值是:
sja1000 reg: 0 -- 0x21
sja1000 reg: 1 -- 0xff
sja1000 reg: 2 -- 0xc
sja1000 reg: 3 -- 0xe0
sja1000 reg: 4 -- 0x0
sja1000 reg: 5 -- 0xff
sja1000 reg: 6 -- 0x1c
sja1000 reg: 7 -- 0x0
sja1000 reg: 8 -- 0x1a
sja1000 reg: 9 -- 0x0
sja1000 reg: 10 -- 0xff
sja1000 reg: 11 -- 0xff
sja1000 reg: 12 -- 0xff
sja1000 reg: 13 -- 0xff
sja1000 reg: 14 -- 0xff
sja1000 reg: 15 -- 0xff
sja1000 reg: 16 -- 0xff
sja1000 reg: 17 -- 0xff
sja1000 reg: 18 -- 0xff
sja1000 reg: 19 -- 0xff
sja1000 reg: 20 -- 0x6e
sja1000 reg: 21 -- 0xff
sja1000 reg: 22 -- 0xf8
sja1000 reg: 23 -- 0xff
sja1000 reg: 24 -- 0x0
sja1000 reg: 25 -- 0x1
sja1000 reg: 26 -- 0x80
sja1000 reg: 27 -- 0x3
sja1000 reg: 28 -- 0xfe
sja1000 reg: 29 -- 0xff
sja1000 reg: 30 -- 0xff
sja1000 reg: 31 -- 0x0

居然回到了复位模式。

从回到工作模式和下发发送命令后,看起来寄存器的值都没什么问题,但是就是无法产生中断。奇怪啊。哪位热心人指点一下?
谢谢啦。

相关帖子

沙发
xzffff|  楼主 | 2012-9-21 15:10 | 只看该作者
附件 是原理图。在设置为正常工作模式的时候,CANL1和CANH1都是0,量不到电平。这个硬件设计有没有问题?我的板子上是有两个SJA1000.

使用特权

评论回复
板凳
xzffff|  楼主 | 2012-9-27 15:12 | 只看该作者
终于工作正常了。
两个原因:
1,BTR设错了,BTR1被设为了0.
2,SJA1000与CTM8251之间的连接不用加电阻,直接相连就可以了。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

16

帖子

0

粉丝