salut tlm
j'ai besoin de votre aide pour le bus can, j'ai un problème avec le pic qui n'accepte pas ID étendu par contre avec ID standard le mask et les filtres fonction bien je travaille en mode Loopback , mais avec ID étendu fonction seulement si je désactive le mask
mask 0
filtre 0Code:RXM0EIDH = 0xFF; RXM0EIDL = 0xFF; RXM0SIDH = 0xFF; RXM0SIDL = 0xF0;
Code:RXF0EIDH = 0xAA; RXF0EIDL = 0xAA; RXF0SIDH = 0xAA; RXF0SIDL = 0xA8;code généré par le MCCCode:int counter ; uCAN_MSG RxCanMessage[3]; uCAN_MSG TxCanMessage[3]; memset(&RxCanMessage[0],0,sizeof(uCAN_MSG)); memset(&TxCanMessage[0],0,sizeof(uCAN_MSG)); TxCanMessage[0].frame.idType = dEXTENDED_CAN_MSG_ID_2_0B; TxCanMessage[0].frame.dlc = 0x08; TxCanMessage[0].frame.id = 0x5555555; TxCanMessage[0].frame.data0 = 0x55; TxCanMessage[0].frame.data1 = 0xaa; TxCanMessage[0].frame.data2 = 0x55; TxCanMessage[0].frame.data3 = 0xaa; TxCanMessage[0].frame.data4 = 0x55; TxCanMessage[0].frame.data5 = 0xaa; TxCanMessage[0].frame.data6 = 0x55; TxCanMessage[0].frame.data7 = 0xaa; while(1) { //Add your application code if(RA0_GetValue() != 1) { if(CAN_transmit(&TxCanMessage[0])) { if(CAN_receive(&RxCanMessage[0])) //CheckRXB0 { //RD0_Toggle(); PORTAbits.RA5 = 0; for(Counter = 0; Counter < 10; Counter++)__delay_ms(40); PORTD = RxCanMessage[0].frame.data0; for(Counter = 0; Counter < 10; Counter++)__delay_ms(40); PORTD = RxCanMessage[0].frame.data1; for(Counter = 0; Counter < 10; Counter++)__delay_ms(40); PORTD = RxCanMessage[0].frame.data2; for(Counter = 0; Counter < 10; Counter++)__delay_ms(40); PORTD = RxCanMessage[0].frame.data3; for(Counter = 0; Counter < 10; Counter++)__delay_ms(40); PORTD = RxCanMessage[0].frame.data4; for(Counter = 0; Counter < 10; Counter++)__delay_ms(40); PORTD = RxCanMessage[0].frame.data5; for(Counter = 0; Counter < 10; Counter++)__delay_ms(40); PORTD = RxCanMessage[0].frame.data6; for(Counter = 0; Counter < 10; Counter++)__delay_ms(40); PORTD = RxCanMessage[0].frame.data7; } } } PORTAbits.RA5 = 1; }
Code:unsigned char CAN_transmit(uCAN_MSG *tempCanMsg) { unsigned char tempEIDH = 0; unsigned char tempEIDL = 0; unsigned char tempSIDH = 0; unsigned char tempSIDL = 0; unsigned char returnValue = 0; if (TXB0CONbits.TXREQ != 1) { convertCANid2Reg(tempCanMsg->frame.id, tempCanMsg->frame.idType, &tempEIDH, &tempEIDL, &tempSIDH, &tempSIDL); TXB0EIDH = tempEIDH; TXB0EIDL = tempEIDL; TXB0SIDH = tempSIDH; TXB0SIDL = tempSIDL; TXB0DLC = tempCanMsg->frame.dlc; TXB0D0 = tempCanMsg->frame.data0; TXB0D1 = tempCanMsg->frame.data1; TXB0D2 = tempCanMsg->frame.data2; TXB0D3 = tempCanMsg->frame.data3; TXB0D4 = tempCanMsg->frame.data4; TXB0D5 = tempCanMsg->frame.data5; TXB0D6 = tempCanMsg->frame.data6; TXB0D7 = tempCanMsg->frame.data7; TXB0CONbits.TXREQ = 1;// Demande d'envoi d'un message returnValue = 1; }/* else if(TXB1CONbits.TXREQ != 1){ convertCANid2Reg(tempCanMsg->frame.id, tempCanMsg->frame.idType, &tempEIDH, &tempEIDL, &tempSIDH, &tempSIDL); TXB1EIDH = tempEIDH; TXB1EIDL = tempEIDL; TXB1SIDH = tempSIDH; TXB1SIDL = tempSIDL; TXB1DLC = tempCanMsg->frame.dlc; TXB1D0 = tempCanMsg->frame.data0; TXB1D1 = tempCanMsg->frame.data1; TXB1D2 = tempCanMsg->frame.data2; TXB1D3 = tempCanMsg->frame.data3; TXB1D4 = tempCanMsg->frame.data4; TXB1D5 = tempCanMsg->frame.data5; TXB1D6 = tempCanMsg->frame.data6; TXB1D7 = tempCanMsg->frame.data7; TXB1CONbits.TXREQ = 1; // Demande d'envoi d'un message returnValue = 1; } else if (TXB2CONbits.TXREQ != 1) { convertCANid2Reg(tempCanMsg->frame.id, tempCanMsg->frame.idType, &tempEIDH, &tempEIDL, &tempSIDH, &tempSIDL); TXB2EIDH = tempEIDH; TXB2EIDL = tempEIDL; TXB2SIDH = tempSIDH; TXB2SIDL = tempSIDL; TXB2DLC = tempCanMsg->frame.dlc; TXB2D0 = tempCanMsg->frame.data0; TXB2D1 = tempCanMsg->frame.data1; TXB2D2 = tempCanMsg->frame.data2; TXB2D3 = tempCanMsg->frame.data3; TXB2D4 = tempCanMsg->frame.data4; TXB2D5 = tempCanMsg->frame.data5; TXB2D6 = tempCanMsg->frame.data6; TXB2D7 = tempCanMsg->frame.data7; TXB2CONbits.TXREQ = 1; // Demande d'envoi d'un message returnValue = 1; }*/ /////////////////////////////////// return (returnValue); }Code:unsigned char CAN_receive(uCAN_MSG *tempCanMsg) { unsigned char returnValue = 0; //check which buffer the CAN message is in if (RXB0CONbits.RXFUL != 0) //CheckRXB0 { if ((RXB0SIDL & 0x08) == 0x08) //If Extended Message { //message is extended tempCanMsg->frame.idType = (unsigned char) dEXTENDED_CAN_MSG_ID_2_0B; tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB0EIDH, RXB0EIDL, RXB0SIDH, RXB0SIDL); } else { //message is standard tempCanMsg->frame.idType = (unsigned char) dSTANDARD_CAN_MSG_ID_2_0B; tempCanMsg->frame.id = convertReg2StandardCANid(RXB0SIDH, RXB0SIDL); } tempCanMsg->frame.dlc = RXB0DLC; tempCanMsg->frame.data0 = RXB0D0; tempCanMsg->frame.data1 = RXB0D1; tempCanMsg->frame.data2 = RXB0D2; tempCanMsg->frame.data3 = RXB0D3; tempCanMsg->frame.data4 = RXB0D4; tempCanMsg->frame.data5 = RXB0D5; tempCanMsg->frame.data6 = RXB0D6; tempCanMsg->frame.data7 = RXB0D7; RXB0CONbits.RXFUL = 0; returnValue = 1; }/*else if(RXB1CONbits.RXFUL != 0) //CheckRXB1 { if ((RXB1SIDL & 0x08) == 0x08) //If Extended Message { //message is extended tempCanMsg->frame.idType = (unsigned char) dEXTENDED_CAN_MSG_ID_2_0B; tempCanMsg->frame.id = convertReg2ExtendedCANid(RXB1EIDH, RXB1EIDL, RXB1SIDH, RXB1SIDL); }else { //message is standard tempCanMsg->frame.idType = (unsigned char) dSTANDARD_CAN_MSG_ID_2_0B; tempCanMsg->frame.id = convertReg2StandardCANid(RXB1SIDH, RXB1SIDL); } tempCanMsg->frame.dlc = RXB1DLC; tempCanMsg->frame.data0 = RXB1D0; tempCanMsg->frame.data1 = RXB1D1; tempCanMsg->frame.data2 = RXB1D2; tempCanMsg->frame.data3 = RXB1D3; tempCanMsg->frame.data4 = RXB1D4; tempCanMsg->frame.data5 = RXB1D5; tempCanMsg->frame.data6 = RXB1D6; tempCanMsg->frame.data7 = RXB1D7; RXB1CONbits.RXFUL = 0; returnValue = 1; }*/ return (returnValue); }Code:unsigned long convertReg2ExtendedCANid(unsigned char tempRXBn_EIDH, unsigned char tempRXBn_EIDL, unsigned char tempRXBn_SIDH, unsigned char tempRXBn_SIDL) { unsigned long returnValue = 0; unsigned long ConvertedID = 0; unsigned char CAN_standardLo_ID_lo2bits; unsigned char CAN_standardLo_ID_hi3bits; CAN_standardLo_ID_lo2bits = (tempRXBn_SIDL & 0x03); CAN_standardLo_ID_hi3bits = (tempRXBn_SIDL >> 5); ConvertedID = (tempRXBn_SIDH << 3); ConvertedID = ConvertedID + CAN_standardLo_ID_hi3bits; ConvertedID = (ConvertedID << 2); ConvertedID = ConvertedID + CAN_standardLo_ID_lo2bits; ConvertedID = (ConvertedID << 8); ConvertedID = ConvertedID + tempRXBn_EIDH; ConvertedID = (ConvertedID << 8); ConvertedID = ConvertedID + tempRXBn_EIDL; returnValue = ConvertedID; return (returnValue); }Code:unsigned long convertReg2StandardCANid(unsigned char tempRXBn_SIDH, unsigned char tempRXBn_SIDL) { unsigned long returnValue = 0; unsigned long ConvertedID; //if standard message (11 bits) //EIDH = 0 + EIDL = 0 + SIDH + upper three bits SIDL (3rd bit needs to be clear) //1111 1111 111 ConvertedID = (tempRXBn_SIDH << 3); ConvertedID = ConvertedID + (tempRXBn_SIDL >> 5); returnValue = ConvertedID; return (returnValue); }merci d'avance pour votre aideCode:void convertCANid2Reg(unsigned long tempPassedInID, unsigned char canIdType, unsigned char *passedInEIDH, unsigned char *passedInEIDL, unsigned char *passedInSIDH, unsigned char *passedInSIDL) { unsigned char wipSIDL = 0; if (canIdType == dEXTENDED_CAN_MSG_ID_2_0B){ //EIDL *passedInEIDL = (unsigned char) 0xFF & tempPassedInID; //CAN_extendedLo_ID_TX1 = &HFF And CAN_UserEnter_ID_TX1 tempPassedInID = tempPassedInID >> 8; //CAN_UserEnter_ID_TX1 = CAN_UserEnter_ID_TX1 >> 8 //EIDH *passedInEIDH = (unsigned char) 0xFF & tempPassedInID; //CAN_extendedHi_ID_TX1 = &HFF And CAN_UserEnter_ID_TX1 tempPassedInID = (unsigned long) tempPassedInID >> 8; //CAN_UserEnter_ID_TX1 = CAN_UserEnter_ID_TX1 >> 8 //SIDL //push back 5 and or it wipSIDL = (unsigned char) 0x03 & tempPassedInID; tempPassedInID = tempPassedInID << 3; //CAN_UserEnter_ID_TX1 = CAN_UserEnter_ID_TX1 << 3 wipSIDL = (unsigned char) (0xE0 & tempPassedInID) + wipSIDL; wipSIDL = wipSIDL + 0x08; // TEMP_CAN_standardLo_ID_TX1 = TEMP_CAN_standardLo_ID_TX1 + &H8 *passedInSIDL = 0xEB & wipSIDL; //CAN_standardLo_ID_TX1 = &HEB And TEMP_CAN_standardLo_ID_TX1 //SIDH tempPassedInID = tempPassedInID >> 8; *passedInSIDH = (unsigned char) 0xFF & tempPassedInID; } else //(canIdType == dSTANDARD_CAN_MSG_ID_2_0B) { *passedInEIDH = 0; *passedInEIDL = 0; tempPassedInID = tempPassedInID << 5; *passedInSIDL = 0xFF & tempPassedInID; tempPassedInID = tempPassedInID >> 8; *passedInSIDH = 0xFF & tempPassedInID; } }
-----