|
楼主 |
发表于 2007-6-21 13:30:56
|
显示全部楼层
帮忙看一下CAN配置和收发程序(PCB打样还没回来)
请问一下:CANIDT、CANIDM这几个配置
#define SWRES 0
#define TXOK 6
#define RXOK 5
#define ENIT 7
#define ENRX 5
/*-----------------------------------------------------------------
*函数名:CANint
*功能 :initialize AT90CAN32 CAN
*参数 :non
-----------------------------------------------------------------*/
void CANint()
{ CANGCON |= (1<<SWRES); //reset CAN controller by software
CANBT1 = 0x02; //set baud rate for 125K
CANBT2 = 0x08; //
CANBT3 = 0x25; //
CANTCON = 0xff; //
/*MOB0=RX[CMD] receive */
CANPAGE = 0x00; //MOB0 auto increment,initial value is 0
CANSTMOB = 0;
CANCDMOB = 0x18; //use 2.0B edition,lenth is 29bits,DLC=8
CANIDT4 = 0x30;
CANIDT3 = 0x00;
CANIDT2 = 0x41;
CANIDT1 = 0x00;
CANIDM4 = 0x00;
CANIDM3 = 0x00;
CANIDM2 = 0x00;
CANIDM1 = 0x00;
/*MOB1=TX[STA1] transmit */
CANPAGE = 0x10; //
CANSTMOB = (1<<TXOK);
CANCDMOB = 0x18;
CANIDT4 = 0x30;
CANIDT3 = 0x80;
CANIDT2 = 0x00;
CANIDT1 = 0x20;
CANGIE |= ((1<<ENIT) + (1<<ENRX)); //open full intermit and receive intermit
}
/*-----------------------------------------------------------------
*函数名:CANRX
*功能 :receive and store data
*参数 : non
-----------------------------------------------------------------*/
void CANRX()
{ uchar rxnum_i;
CANGIE &= ~(1 << ENRX); //close receive intermit
CANPAGE = 0x00;
if(CANSTMOB & (1 << RXOK)
{ for(cannum_i = 0; cannum_i < 8; cannum_i++)
{ can_receivedata[cannum_i]=CANMSG; //get the data (8 byte)
}
CANPAGE = 0x00;
CANSTMOB &= ~(1 << RXOK); //clear intermit(need clear after received by software)
CANCDMOB = 0x98; //open received
CANGIE |= (1 << ENRX); //open intermit
CanReceiveEndFlag = 1; //set receive over flag
}
}
/*-----------------------------------------------------------------
*函数名:CANTX
*功能 :transmit data
*参数 : non
-----------------------------------------------------------------*/
void CANTX()
{ uchar txnum_i;
CANPAGE = 0x10;
if(CANSTMOB & (1 << TXOK)) //need to transmit
{ CANSTMOB &= ~(1 << TXOK); //clear transmit flag
for(i = 0; i < 8; i ++) //send data
{ CANMSG = can_transdata[txnum_i];
}
CANCDMOB = 0x58; //frame send
CANGIE |=(1 << ENRX); //open intermit
}
} |
|