2个节点都通过了单节点测试,2个节点收发时不能通讯,示波器测2个节点的中断脚都没有中断信号!这是怎么回事?
//-------------------------------------------------------------- void SJA_Init(void) { unsigned char temp; do { SJA_Write(REG_CONTROL, 0x01); temp = SJA_Read(REG_CONTROL); } while (!(temp & 0x01));
SJA_Write(REG_BTR0, 0x05); SJA_Write(REG_BTR1, 0xff);
SJA_Write(REG_ACR, 0xaa); SJA_Write(REG_AMR, 0x00);
SJA_Write(REG_CDR, 0xaa); SJA_Write(REG_OCR, 0x48);
do { SJA_Write(REG_CONTROL, 0x06); temp = SJA_Read(REG_CONTROL); } while(!(temp & 0x06));
}
//-------------------------------------------------------------- void SJA_SendBuf(void) { unsigned char i; unsigned char temp; unsigned char TxBufB;
TxBufB = REG_TxBuffer1; while ((SJA_Read(REG_STATUS) & 0x04) == 0); // 等待发送缓冲区释放 for (i=0; i<10; i++) { SJA_Write(TxBufB++, TxData); }
SJA_Write(REG_COMMAND, 0x01);
temp = SJA_Read(REG_STATUS); PC_send(temp);
}
//-------------------------------------------------------------- void SJA_ReceiveBuf(void) { unsigned char i; unsigned char RxBufB;
RxBufB = REG_RxBuffer1;
while ((SJA_Read(REG_STATUS) & 0x01) == 0); for (i=0; i<10; i++) { RxData = SJA_Read(RxBufB++); }
SJA_Write(REG_COMMAND, 0x04); }
//-------------------------------------------------------------- void SJA_INT(void) interrupt 0 using 1 { unsigned char status; unsigned char temp; EX0 = 0; status = SJA_Read(REG_INTERRUPT); temp = status & 0x02; if(temp == 0x02) { ; } temp = status & 0x01; if(temp == 0x01) { CAN_RxFlag = 1; }
EX0 = 1;
} //节点1主程序 void main(void) {
MCU_Init(); PC_send(0x01); SJA_Init(); PC_send(0x02);
ANOLD = AN;
while (1) { while (AN == ANOLD); AN = ANOLD; SJA_SendBuf(); BEEP = 0; Delay(500); BEEP = 1;
while (CAN_RxFlag == 0); CAN_RxFlag = 0; SJA_ReceiveBuf(); BEEP = 0; Delay(100); BEEP = 1; Delay(100); BEEP = 1; } } //节点2主程序 void main(void) { unsigned char temp; MCU_Init(); SJA_Init(); while (1) { if (CAN_RxFlag == 1) { CAN_RxFlag = 0; SJA_ReceiveBuf(); BEEP = 0; Delay(100); BEEP = 1; Delay(100); BEEP = 1;
Delay(100); SJA_SendBuf(); BEEP = 0; Delay(100); BEEP = 1; } } }
|