AVR新人求助! 我将CAN的接收和发送脚短接。 主要TXOK置1就发,但发不出去。(TKOK一直为0) 那位高手帮我看看,指点指点。谢谢! uchar num_channel; uchar num_data; /*----------------------------------------------------------------- *函数名:CANint *功能 :initialize AT90CAN32 CAN *参数 :non -----------------------------------------------------------------*/ void CANint() { //uchar num_channel; CANGCON |= (1<<SWRES); //reset CAN controller by software /* reset all mailboxes */ for (num_channel = 0; num_channel < 15; num_channel++) { CANPAGE = num_channel << 4; CANCDMOB = CH_DISABLE; CANSTMOB = 0; CANIDT1 = 0; CANIDT2 = 0; CANIDT3 = 0; CANIDT4 = 0; CANIDM1 = 0; CANIDM2 = 0; CANIDM3 = 0; CANIDM4 = 0; for (num_data = 0; num_data < 8; num_data++) CANMSG = 0; } /* setup bit timing at 500k with 12 MHz crystal*/ CANBT1 = 0x02; CANBT2 = 0x08; CANBT3 = 0x25; CANGCON |= MSK_CANGCON_ENA; //start CAN /* Channel 0: identifier = 11bits. CANIDT=0x123 */ CANIDT1 = 0x24; CANIDT2 = 0x60; /* Channel 0: mask = 11bits. 0x7F0 */ CANIDM1 = 0xFE; CANIDM2 &= ~0xE0; CANIDM4 = 0; /* Channel 0 configuration */ CANIDT4 &=~0x04; /* clear bit rtr in CANIDT4. */ CANCDMOB |= DLC_MAX; /* Reception 8 bytes.*/ CANCDMOB |= CH_RxENA; /* Reception enabled without buffer.*/ /* Channel 1 init */ CANPAGE = (1 << 4); /* CHNB=0x01; select channel 1 */ CANSTMOB = 0x00; /* reset channel status */ CANCDMOB = CH_DISABLE; /* reset control and dlc register */ /* Channel 1: identifier = 11bits. CANIDT=0x123 */ CANIDT1 = 0x24; CANIDT2 = 0x60; /* Channel 1: mask = 11bits. 0x7F0 */ CANIDM1 = 0xFE; CANIDM2 &= ~0xE0; CANIDM4 = 0; /* interrupt configuration */ CANIE2 |= 0x09; //开MOB3 & MOB0信箱接收中断(接收邮箱) CANPAGE = 0x00; CANCDMOB |= 0x80; //MOB0接收使能 CANGIE |= ((1<<ENRX)|(1<<ENIT)); /* Can_Rx & IT enable */ }
SIGNAL( CANIT_vect ) { //LEDtest = ~LEDtest; uchar rxnum_i; CANGIE &= ~(1<<ENRX); //关接收中断**** CANPAGE = 0x00; // for(rxnum_i = 0; rxnum_i < 8; rxnum_i++) { can_receivedata[rxnum_i]=CANMSG; //取得8个字节的数据 R_test = can_receivedata[rxnum_i]; } CANPAGE = 0x00; CANSTMOB &= ~(1<<RXOK); //清中断标志**** CANCDMOB = 0x98; //接收使能 CANGIE |= (1<<ENRX); //开中断 CanReceiveEndFlag=1; } /*----------------------------------------------------------------- *函数名:CANTX *功能 :transmit data *参数 : non -----------------------------------------------------------------*/ void CANTX() { uchar txnum_i; CANPAGE = 0x10; if(CANSTMOB & (1 << TXOK)) //need to transmit { LEDtest = ~LEDtest; CANSTMOB &= ~(1 << TXOK); //clear transmit flag for(txnum_i = 0; txnum_i < 8; txnum_i ++) //send data { CANMSG = can_transdata[txnum_i]; } CANCDMOB = 0x58; //frame send CANGIE |=(1 << ENRX); //open intermit } }
|