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

关于GZ16的mscan08的标准can的配置?[原创]

c我没写过,我发现moto的汇编不比c差,指令太丰富了
我被逼用汇编改写原来人家写的一个c程序,好痛苦啊
不过后来发现,由于程序对时间要求比较高,c还真不是那么好控制呢
欢迎大家到汽车电子群2838085!
让我们推动中国汽车前进!
void CAN_Init(void)
{
  /* CMCR0: ??=0,??=0,??=0,SYNCH=0,TLNKEN=0,SLPAK=0,SLPRQ=0,SFTRES=1 */
  CMCR0 = 1;                           /* CAN reset */
  /* CMCR1: ??=0,??=0,??=0,??=0,??=0,LOOPB=0,WUPM=0,CLKSRC=0 */
  CMCR1 = 0;        //ʱÖÓԴΪÍⲿ¾§Õñ/2 = 2Mhz
  
  CIDAC_IDAM = 0;     //32λ½ÓÊÕ¹ýÂËÆ÷
  CIDAR = 0x00000000; //Set the acceptance code
  CIDMR = 0xFFFFFFFF; //Set the acceptance mask
  
  CBTR0  = 0x43;   
  CBTR1  = 0xA3;   //²¨ÌØÂÊΪ62.5K

  CMCR0  = 0x00;   //°ÑCANÄ£¿éÉèÖÃΪÊý¾ÝÊäÈëÊä³ö״̬
    CRIER  = 0xFF;   //CAN½ÓÊÕÖжÏʹÄÜ
}
给我个Email我给你发过去
谢谢楼上,我的e-meil是xmq1111@163.com
立志做个专业的工程师
已经解决了?
我现在用GZ16做项目呢!
To yunfeng:
meil已经收到,对我帮助很多,非常感谢!
立志做个专业的工程师
请点击附件下载http://bbs.chinaecnet.com/uploadImages/GZ16.rar
谢谢了,你给我的那几份资料都蛮有用的,我的can的基本功能也已经调出来了.
立志做个专业的工程师
非常感谢yunfeng大虾的解答,以及倦客朋友提出问题,本人正在研究GZ16,而且正是要应用CAN。非常感谢! 有时间希望多多联系!能给个email?
恐怖的代码

探讨LIN


我们现在也在作LIN,我是刚刚入门,感觉很茫然,想向您请教,作一个主模块,三个从模块,我是负责主模块的,现在还在画板子阶段,有的问题很茫然,我的要有两个232接口,其中一个接显示屏,另一个接PC机,这两个接口要同时用,而GZ60只有一对收发传口,那怎么实现两路232同时用呢?
本人用的是AZ32A,现在也正在调试CAN.很是头痛,这款芯片好象与其他的不太一样.
没有CAN的使能端.我现在在自发自收的情况下是可以通信的,但是在2个模块之间无法通信.
大家都是用的GZ的吗?

关于CAN通信问题[原创]

#include /* for EnableInterrupts macro */
#include /* include peripheral declarations */

//---------------------定义全局变量------------------//

unsigned int SPI_count=0; //SPI 计数器

void CAN_Transmit(void);


//----------------- transmit SPI program ------------------//

void transmit_SPI (unsigned char SPI_data)
{
PTC_PTC2 = 0 ; PTC_PTC2 = 0 ; PTC_PTC2 = 0 ;
PTC_PTC2 = 0 ; PTC_PTC2 = 0 ; PTC_PTC2 = 0 ; //SPI 端口拉低

while(SPSCR_SPTE==0);
SPDR=SPI_data;

PTC_PTC2 = 0 ; PTC_PTC2 = 0 ; PTC_PTC2 = 0 ;
PTC_PTC2 = 0 ; PTC_PTC2 = 0 ; PTC_PTC2 = 0 ; //SPI 继续端口拉低

PTC_PTC2 = 1 ; PTC_PTC2 = 1 ; // SPI 端口拉高

}




//------------------display function---------------------//
void delay(void) {
int i ;

for( i = 0; i < 100; i++) {


}
}


//------------------timer interrupt program------------------------//

interrupt 4 void TimerInterrupt(void)
{
PSC_PSTOP = 0x01;
PSC_POF = 0x00;
PSC_PRST = 0x01; //clear PSC_POF and let timer modul execute again


__RESET_WATCHDOG(); // kicks the watchdog


SPI_count++;

if(SPI_count==5) //every 100ms SPI W/D
{
transmit_SPI(0xB3);

SPI_count = 0;

CAN_Transmit();

}



PSC_PSTOP = 0;

}


interrupt 17 void CAN_Receive(void) {
unsigned char receive[8]={0,0,0,0,0,0,0,0};
unsigned char id[4] = {0,0,0,0};
PTA_PTA7 = 1;
delay();
PTA_PTA7 = 0;
delay();
id[0] = REC_IDR0;
id[1] = REC_IDR1;
id[2] = REC_IDR2;
id[3] = REC_IDR3;

receive[0] = REC_DSR0;
receive[1] = REC_DSR1;
receive[2] = REC_DSR2;
receive[3] = REC_DSR3;
receive[4] = REC_DSR4;
receive[5] = REC_DSR5;
receive[6] = REC_DSR6;
receive[7] = REC_DSR7;
CRFLG_RXF = 1;


}
//--------------------------- CAN transmit program ----------------------//

void CAN_Transmit(void){

unsigned char emptytest;
unsigned char emptytest0;
unsigned char emptytest1;
unsigned char emptytest2;

emptytest = CTFLG;

emptytest0 = emptytest&0x01; //判断接受区为空
emptytest1 = emptytest&0x02;
emptytest2 = emptytest&0x04;



if(emptytest0!=0)
{
DLR0 = 0x08;


DSR00 = 0xff;
DSR10 = 0x00;
DSR20 = 0xff;
DSR30 = 0x00;
DSR40 = 0xff;
DSR50 = 0x00;
DSR60 = 0xff;
DSR70 = 0x00;


IDR00 = 0x33; // DP256:0x11; AZ60:0x33; GZ16:0x22; MPC555:0x44
IDR10 = 0xFF;
IDR20 = 0xFF;
IDR30 = 0xFE; //extended identifers

TBPR0 = 0x01;

CTFLG = 0x01; //buffer0 启动发送


}



else if(emptytest1!=0)
{
DLR1 = 0x08;


DSR01 = 0xff;
DSR11 = 0x00;
DSR21 = 0xff;
DSR31 = 0x00;
DSR41 = 0xff;
DSR51 = 0x00;
DSR61 = 0xff;
DSR71 = 0x00;

IDR01 = 0x33; // IDR11 = 0xFF;
IDR21 = 0xFF;
IDR31 = 0xFE; //extended identifers

TBPR1 = 0x01;

CTFLG = 0x02; //buffer1 启动发送


}




else if(emptytest2!=0)
{
DLR2 = 0x08;


DSR02 = 0xff;
DSR12 = 0x00;
DSR22 = 0xff;
DSR32 = 0x00;
DSR42 = 0xff;
DSR52 = 0x00;
DSR62 = 0xff;
DSR72 = 0x00;

IDR02 = 0x33; // DP256:0x11; AZ60:0x33; GZ16:0x22; MPC555:0x44
IDR12 = 0xFF;
IDR22 = 0xFF;
IDR32 = 0xFE; //extended identifers

TBPR2 = 0x01;

CTFLG = 0x04; //buffer2 启动发送


}


}





//------------------------ Ports initial ------------------------------//
void Init_PORT(void){
DDRA_DDRA7 = 1;

DDRC_DDRC2 = 1; //MC33989 CSB choice
DDRC_DDRC4 = 1;
DDRC_DDRC5 = 1;


DDRE_DDRE4 = 0x0; //PTE4==high, AZ32A als master wird

PTA_PTA7 = 0;
PTC_PTC2 = 1 ;
PTC_PTC4 = 0 ;
PTC_PTC5 = 0 ;

}


//-------------------------SPI initial program-------------------------//

void Init_SPI(void){

SPCR_SPE =1; //设置SPI寄存器
SPCR_SPMSTR = 1;

SPSCR_SPR0=0;
SPSCR_SPR1=0; //bund rate =500k ,CGMOUT=2M hz ,intenal bus clock =1M hz

PTC_PTC2 = 1 ;

}


//--------------------------MSCAN initial program-----------------------//

void Init_MSCAN08(void){

CMCR0 = 0x01; //CAN模块为软复位状态
CMCR1 = 0x04;
CBTR0 = 0x43;
CBTR1 = 0xA3; //波特率为62.5K


CIDAC = 0x00; //接收滤波为32位滤波


CIDAR0 = 0x00; //滤波使它接收一帧
CIDAR1 = 0x00;
CIDAR2 = 0x00;
CIDAR3 = 0x00; //extended identifers

CIDMR0 = 0xFF;
CIDMR1 = 0xFF;
CIDMR2 = 0xFF;
CIDMR3 = 0xFF; //extended identifers



CMCR0 = 0x00; //把CAN模块设置为数据输入输出状态

CRIER = 0xff; //CAN接收中断使能

}





//------------------------MCU initial program------------------------//

void Init_AZ32A(void)
{

PSC_PPS = 0; //1分频
PSC_POIE = 1; //PIT interrupt enable

PMODH = 0x03;
PMODL = 0xe8; //定时器设置成为1ms产生一次中断

PSC_PSTOP = 0; //PIT 计数器启动

Init_PORT();
Init_MSCAN08(); //MSCAN initial
Init_SPI(); //SPI initial


}

//----------------------------main function----------------------------//

void main(void){

EnableInterrupts; //中断使能

Init_AZ32A(); //调用单片机初始化子程序

//set MC33989 status by SPI
transmit_SPI(0xB3); //set MC33889 watchdog works at no window mode and 350ms
transmit_SPI(0x11); //set MC33889 MCR Reg,and MC33889 works at Normal status
transmit_SPI(0x50); //set MC33889 CAN Reg,and CAN works normal status

for(;;){

//__RESET_WATCHDOG(); /* feeds the dog */
}
}


如果是自发自收,我通过单步调试是可以通信的.也就是我发送成功,接收缓冲寄存器也相应地正确地接收到发送的值.

可是我用2块板子之间进行调试时始终看不到总线上有信号.

请哪位高手帮忙看一下我的程序代码有何问题?

在此谢过!

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

救救我啊!
MC33989如何使用啊?
为什么我的CAN在自发自收的情况下是可以的,但是在用MC33989与另块板子通信的时候就不行了啊?
返回列表