Emilio Aron Moyers

Can is sending more messages than I want to send KEA128

Discussion created by Emilio Aron Moyers on Aug 11, 2016
Latest reply on Aug 23, 2016 by Wade Whitehorn

Hello,

I'm using Kea 128 an I'm want to send an standard id message, i can do that ( send the message with the correct id and data), but there are been sent also 2 more messages that I don't want to send, they have random ids and random data.

I don't know if my configuration it's ok. I put it down:

 

void MSCAN_init(void){

  SIM_PINSEL1 &= ~SIM_PINSEL1_MSCANPS_MASK; // SIM_PINSEL1: MSCANPS=0; PTC6 PTC7

  CONFIG_PIN_AS_GPIO(PORT_C,MSCANRX,INPUT); /* Configure (PTC6) as an intput RX*/

  CONFIG_PIN_AS_GPIO(PORT_C,MSCANTX,OUTPUT); /* Configure (PTC7) as an output TX*/

 

  SIM_SCGC |=  SIM_SCGC_MSCAN_MASK; // Enable bus clock iN MSCAN

 

  MSCAN_CANCTL1 |= MSCAN_CANCTL1_CANE_MASK;           // Enable CAN mode

  MSCAN_CANCTL0 |= MSCAN_CANCTL0_INITRQ_MASK;         // Enable INIT mode

  MSCAN_CANCTL1 |= MSCAN_CANCTL1_INITAK_MASK;         // Enable INIT mode

  while ((MSCAN_CANCTL1&0x01)!=1);                    // wait for initialization mode

 

  MSCAN_CANCTL1 |= MSCAN_CANCTL1_CLKSRC_MASK;      // Enable CLK source

  MSCAN_CANCTL1 &= ~MSCAN_CANCTL1_LISTEN_MASK;      // 0 Normal operation.

  MSCAN_CANCTL1 |= MSCAN_CANCTL1_WUPM_MASK;      // 1 MSCAN wakes only in case of a dominant pulse on the CAN bus that has a length of Twup.

  MSCAN_CANBTR0 = 0x01;       //PRESCALADOR CLKBUS/2 10MHz  SI QUIERO 100KHz PREESCALADOR DEBE SER 0x09 CLKBUS/10 2MHZ

  MSCAN_CANBTR1 = 0xDC;//0xBE; //3E SG1= 15, SG2= 4 SG1+SG2+1=20   10MHz/20=500 KHz) SG2 20-25% TIME QUANTA

  //BE 1 Three samples per bit. In this case, PHASE_SEG1 must be at least 2 time quanta (Tq).

  MSCAN_CANIDAC = 0x10; // 16 bit acceptance filter

 

  MSCAN_CANIDAR0=0XFF;

  MSCAN_CANIDAR1=0XFF;

  MSCAN_CANIDAR2=0XFF;

  MSCAN_CANIDAR3=0XFF;

  MSCAN_CANIDAR4=0XFF;

  MSCAN_CANIDAR5=0XFF;

  MSCAN_CANIDAR6=0XFF;

  MSCAN_CANIDAR7=0XFF;

 

  MSCAN_CANIDMR0=0XFF;

  MSCAN_CANIDMR1=0XFF;

  MSCAN_CANIDMR2=0XFF;

  MSCAN_CANIDMR3=0XFF;

  MSCAN_CANIDMR4=0XFF;

  MSCAN_CANIDMR5=0XFF;

  MSCAN_CANIDMR6=0XFF;

  MSCAN_CANIDMR7=0XFF;

 

  MSCAN_CANCTL0 &= ~MSCAN_CANCTL0_INITRQ_MASK;         // Disable INIT mode

  MSCAN_CANCTL1 &= ~MSCAN_CANCTL1_INITAK_MASK;         // Disable INIT mode

  while ((MSCAN_CANCTL1&0x00) != 0); // wait for normal board

 

  MSCAN_CANCTL0 |= MSCAN_CANCTL0_TIME_MASK;           // time stamping

  MSCAN_CANRIER=0XFF;

 

  while ((MSCAN_CANCTL0 & MSCAN_CANCTL0_SYNCH_MASK) != MSCAN_CANCTL0_SYNCH_MASK);

 

  MSCAN_CANRIER |= MSCAN_CANRIER_RXFIE_MASK ;//0x01; //receive interrupt enabled

  MSCAN_CANRFLG |= MSCAN_CANRFLG_RXF_MASK;//0x01; //receive interrupt enabled

 

  CONFIG_PIN_AS_GPIO(PORT_G,CANTRANSEIVER,OUTPUT); //! MC33901 STB, Mapped from GPIOB16

  OUTPUT_CLEAR(PORT_G,CANTRANSEIVER); //PIN STB ACTIVA CON 0

}

 

 

void MSCAN_Tx(uint16_t ID,uint8_t DLC,uint32_t dataw1,uint32_t dataw0){

  uint16_t can_id=0;

  uint8_t txcanbuffer=0;

  txcanbuffer = MSCAN_CANTFLG; /* read transmit flag */

  txcanbuffer&=0x07;

  if(txcanbuffer!=0){

  led_off(LED3); //PRENDER UN LED

  /************* select one among 3 buffers *************/

  MSCAN_CANTBSEL = txcanbuffer; /* write the value back to Can select register */

  txcanbuffer = MSCAN_CANTBSEL;

 

 

  can_id=ID>>3;

  can_id &= 0xFF;

  MSCAN_TSIDR0  = (uint8_t)can_id;//0xFB;    frame id// standard frame has 2 registers involved

  can_id=ID <<5;

  can_id &= 0xFF;

  MSCAN_TEIDR1 = (uint8_t)can_id; //7DF OBD2READ OJO EREROR EN LOS REGISTROS MSCAN_TSIDR1=

  MSCAN_TSIDR1=0;

  MSCAN_TEIDR2 = 0;

  MSCAN_TEIDR3 = 0;

 

  MSCAN_TDLR = DLC;         //Data frame length

 

 

 

  MSCAN_TEDSR0 = (uint8_t) ((dataw1>>24)&0xFF);

  MSCAN_TEDSR1 = (uint8_t) ((dataw1>>16)&0xFF);

  MSCAN_TEDSR2 = (uint8_t) ((dataw1>>8)&0xFF);

  MSCAN_TEDSR3 = (uint8_t) dataw1&0xFF;

  MSCAN_TEDSR4 = (uint8_t) ((dataw0>>24)&0xFF);

  MSCAN_TEDSR5 = (uint8_t) ((dataw0>>16)&0xFF);

  MSCAN_TEDSR6 = (uint8_t) ((dataw0>>8)&0xFF);

  MSCAN_TEDSR7 = (uint8_t) dataw0&0xFF;

 

 

  MSCAN_TBPR = 1;              /* local priority */

  MSCAN_CANTFLG |= 1;

 

 

  }

  }

  else{

  led_on(LED3); //PRENDER UN LED

  }

}

 

The message I want have the correct Id and the correct data, but other messages are been sent with random id and data.

Can somebody check the code and help me.

 

I attached the complete project.

 

regards,

 

Emilio

Original Attachment has been moved to: prueba2.rar

Outcomes