Bonjour à tous !
J'implémente un code pour récupérer les informations depuis un bus CAN. Le problème c'est que l'identifiant du noeud qui permet d'identifier l'information est une chaine de caractère "ECU_1". Je n'arrive pas à initialiser l'information. Voici le code :
Le problème se situe au début, il ne veut pas compiler mon ID_2nd. L'objectif est de comparer cet identifiant avec celui qu'on reçoit "Rx_ID".
Merci d'avance pour votre aideCode:#include "ECAN_Defs.h" unsigned int Can_Init_Flags, Can_Send_Flags, Can_Rcv_Flags; // can flags unsigned int Rx_Data_Len; // received data length in bytes char RxTx_Data[8]; // can rx/tx data buffer char Msg_Rcvd; // reception flag const unsigned long ID_1st = 12111, // node IDs char ID_2nd[6] = "ECU_1" ; // node IDs char Rx_ID[6]; void C1Interrupt(void) org 0x005A // ECAN event iterrupt { IFS2bits.C1IF = 0; // clear ECAN interrupt flag if(C1INTFbits.TBIF) { // was it tx interrupt? C1INTFbits.TBIF = 0; // if yes clear tx interrupt flag } if(C1INTFbits.RBIF) { // was it rx interrupt? C1INTFbits.RBIF = 0; // if yes clear rx interrupt flag } } void main() { // PLL settings CLKDIVbits.PLLPRE = 0; // PLLPRE<4:0> = 0 -> N1 = 2 8MHz / 2 = 4MHz // (must be within 0.8 MHz to 8 MHz range) PLLFBD = 38; // PLLDIV<8:0> = 38 -> M = 40 4MHz * 40 = 160MHz // (must be within 100 MHz to 200 MHz range) CLKDIVbits.PLLPOST = 0; // PLLPOST<1:0> = 0 -> N2 = 2 160MHz / 2 = 80MHz // (must be within 12.5 MHz to 80 MHz range) AD1PCFGH = 0xFFFF; // AD1PCFGL = 0xFFFF; // all ports digital I/O AD2PCFGL = 0xFFFF; // /* Clear Interrupt Flags */ IFS0=0; IFS1=0; IFS2=0; IFS3=0; IFS4=0; /* Enable ECAN1 Interrupt */ IEC2bits.C1IE = 1; // enable ECAN1 interrupts C1INTEbits.TBIE = 1; // enable ECAN1 tx interrupt C1INTEbits.RBIE = 1; // enable ECAN1 rx interrupt PORTB = 0; // clear PORTB TRISB = 0; // set PORTB as output, // for received message data displaying Can_Init_Flags = 0; // Can_Send_Flags = 0; // clear flags Can_Rcv_Flags = 0; // Can_Send_Flags = _ECAN_TX_PRIORITY_0 & // form value to be used _ECAN_TX_XTD_FRAME & // with CANSendMessage _ECAN_TX_NO_RTR_FRAME; Can_Init_Flags = _ECAN_CONFIG_SAMPLE_THRICE & // form value to be used _ECAN_CONFIG_PHSEG2_PRG_ON & // with CANInitialize _ECAN_CONFIG_XTD_MSG & _ECAN_CONFIG_MATCH_MSG_TYPE & _ECAN_CONFIG_LINE_FILTER_OFF; RxTx_Data[0] = 9; // set initial data to be sent ECAN1DmaChannelInit(0, 1, &ECAN1RxTxRAMBuffer); // init dma channel 0 for // dma to ECAN peripheral transfer ECAN1DmaChannelInit(2, 0, &ECAN1RxTxRAMBuffer); // init dma channel 2 for // ECAN peripheral to dma transfer ECAN1Initialize(1, 3, 3, 3, 1, Can_Init_Flags); // initialize ECAN ECAN1SetBufferSize(ECAN1RAMBUFFERSIZE); // set number of rx+tx buffers in DMA RAM ECAN1SelectTxBuffers(0x000F); // select transmit buffers // 0x000F = buffers 0:3 are transmit buffers ECAN1SetOperationMode(_ECAN_MODE_CONFIG,0xFF); // set CONFIGURATION mode ECAN1SetMask(_ECAN_MASK_0, -1, _ECAN_CONFIG_MATCH_MSG_TYPE & _ECAN_CONFIG_XTD_MSG); // set all mask1 bits to ones ECAN1SetMask(_ECAN_MASK_1, -1, _ECAN_CONFIG_MATCH_MSG_TYPE & _ECAN_CONFIG_XTD_MSG); // set all mask2 bits to ones ECAN1SetMask(_ECAN_MASK_2, -1, _ECAN_CONFIG_MATCH_MSG_TYPE & _ECAN_CONFIG_XTD_MSG); // set all mask3 bits to ones ECAN1SetFilter(_ECAN_FILTER_10, ID_2nd, _ECAN_MASK_2, _ECAN_RX_BUFFER_7, _ECAN_CONFIG_XTD_MSG); // set id of filter10 to 2nd node ID // assign mask2 to filter10 // assign buffer7 to filter10 ECAN1SetOperationMode(_ECAN_MODE_NORMAL, 0xFF); // set NORMAL mode ECAN1Write(ID_1st, RxTx_Data, 1, Can_Send_Flags); // send initial message while (1) { // endless loop Msg_Rcvd = ECAN1Read(&Rx_ID , RxTx_Data , &Rx_Data_Len, &Can_Rcv_Flags); // receive message if ((Rx_ID == ID_2nd) && Msg_Rcvd) { // if message received check id PORTB = RxTx_Data[0]; // id correct, output data at PORTB RxTx_Data[0]++ ; // increment received data Delay_ms(10); ECAN1Write(ID_1st, RxTx_Data, 1, Can_Send_Flags); // send incremented data back } } }![]()
-----