Page 1 of 2

CAN - Don't get RXMSG

Posted: Sun Feb 09, 2014 4:49 pm
by bartocham
Hi,

Sorry if my english will be bad in this post - I'll do my best.

I have big problem. I'm trying to read parameters like RPM and Speed from my Car - Ford Fiesta 2006, engine - 1,25 75 KM via Can bus.
I'm using HY - RedBull eval board with STM32F103ZET6 uC. I successfully ended tests with loopback mode - I get my txmsg as a rxsmg.
But when I'm not using loopback mode and connect to car I don't get rxmsg.
There is MCP2551transceiver on Eval Board connected to PB8 - RX and PB9 - TX in uC.
Below you can see fragment of my board config.

Code: Select all

/*
 * Port B setup.
 * Everything input with pull-up except:
 * PB8 - Digital input with PullUp (CAN_RX)
 * PB9 - Alternate Push Pull output 50MHz(CAN_TX)
 */
#define VAL_GPIOBCRL            0x88888888      /*  PB7...PB0 */
#define VAL_GPIOBCRH            0x888888B8      /* PB15...PB8 */
#define VAL_GPIOBODR            0xFFFFFFFF



I conclude that if loopback test works properly my init of CAN is ok but I attach start of my main function

Code: Select all

int main(void) {

  chThdSleepMilliseconds(500);

  halInit();
  chSysInit();

  // wait to not send errors
  chThdSleepMilliseconds(500);
  chThdSleepMilliseconds(500);


  /*
   * OBD + CAN init
   */
  canStart(&CAND1, &cancfg);
  // wait for start CAN
  chThdSleepSeconds(3);
  chThdCreateStatic(can_tx_wa, sizeof(can_tx_wa), NORMALPRIO + 7, can_tx, NULL);


Below my CAN config:

Code: Select all

static const CANConfig cancfg = {
  CAN_MCR_TXFP,
  CAN_BTR_SJW(0) | CAN_BTR_TS2(1) |
  CAN_BTR_TS1(8) | CAN_BTR_BRP(6)
};



Transmission thread:

Code: Select all

/*
 * Transmitter thread.
 */
static WORKING_AREA(can_tx_wa, 256);
static msg_t can_tx(void * p) {
  CANTxFrame *txmsg;
  systime_t time;
  CANRxFrame rxmsg;
  int i;
  (void)p;
  chRegSetThreadName("transmitter");

  time = chTimeNow();
  while (!chThdShouldTerminate()) {
    time += MS2ST(100);
    for(i=0;i<4;i++)
    {
      txmsg = getTxFrame(PIDtable[i]);
      canTransmit(&CAND1, CAN_ANY_MAILBOX, txmsg, MS2ST(100));
      chThdSleepMilliseconds(300);
      // Id ramki z odpowiedzia od ECU || 0x7DF dla nadawania || 0x7E8 dla odbierania
      getFrame(0x7E8, &rxmsg);
      decode(&parData, &rxmsg);
    }
    chThdSleepUntil(time);
  }
  return 0;
}


As I said loobpack works fine so functions getTxFrame and decode works ok.
Below getTxFrame:

Code: Select all

const uint8_t PIDtable[4] = {
 RPM_PID,
 ENGINE_LOAD_PID,
 VEHICLE_SPEED_PID,
 THROTTLE_POSITION_PID,
};

CANTxFrame* getTxFrame(uint8_t PID) {
  static CANTxFrame txmsg;

  txmsg.IDE = CAN_IDE_STD;
  txmsg.SID = 0x7DF;
  txmsg.RTR = CAN_RTR_DATA;
  txmsg.DLC = 8;
  txmsg.data8[0] = 0x02;
  txmsg.data8[1] = 0x01;
  txmsg.data8[2] = PID;
  txmsg.data8[3] = 0x00;
  txmsg.data8[4] = 0x00;
  txmsg.data8[5] = 0x00;
  txmsg.data8[6] = 0x00;
  txmsg.data8[7] = 0x00;

  return &txmsg;
}


Those PIDs from PIDTable are taken correctly.

I put receiver thread into getFrame function which I present below:


Code: Select all

uint8_t getFrame(uint16_t ID, CANRxFrame *frame)
{
  EventListener el;
  static CANRxFrame rxmsg;
  uint16_t curID = 0xFFFF;

  chRegSetThreadName("receiver");
  chEvtRegister(&CAND1.rxfull_event, &el, 0);
    while(curID != ID) {
      if (chEvtWaitAnyTimeout(ALL_EVENTS, MS2ST(100)) == 0)
           canReceive(&CAND1, CAN_ANY_MAILBOX, &rxmsg, TIME_IMMEDIATE);
           curID = rxmsg.SID;
    }
    if(curID == 0){
      chEvtUnregister(&CAND1.rxfull_event, &el);
      return 0;
    }
    *frame = rxmsg;
    chEvtUnregister(&CAND1.rxfull_event, &el);
    return 0;
}


Program jumps into that functions but I don't get any resposne from ECU - all parts of rxmsg are 0. Can you help me ?

Re: CAN - Don't get RXMSG

Posted: Sun Feb 09, 2014 5:07 pm
by Giovanni
Hi,

I am not a CAN expert, I would first verify that there are no electrical problems, you may, for example, by making 2 similar boards exchange messages.
The second thing I would verify are CAN speed settings, do you know the speed the car is supposed to use?

Giovanni

Re: CAN - Don't get RXMSG

Posted: Sun Feb 09, 2014 5:14 pm
by bartocham
Reffering to http://pinoutsguide.com/CarElectronics/ford_obd_2_pinout.shtml in my car I have standard OBD2 - EOBD - 11bit identifier and 500kbaud/s speed so I think I did config well.
Unfortunately I don't have second board with CAN :(

Re: CAN - Don't get RXMSG

Posted: Sun Feb 09, 2014 5:42 pm
by bartocham
One question more - if I understand correctly after halinit() Can is used in normal mode and all filters are turned off - mailbox receives anything what is on input ?

Re: CAN - Don't get RXMSG

Posted: Sun Feb 09, 2014 5:52 pm
by Giovanni
Correct, no filters unless you configure them.

Giovanni

Re: CAN - Don't get RXMSG

Posted: Mon Feb 10, 2014 11:05 pm
by bartocham
Hi,

I have bought mini STM32 v 2.0 and MCP2551 and connected it into circuit. On both eval boards I flashed CAN example. I connected one board with second via CAN. Unfortunatelly I'm not getting rxmsg on both... Do you think that transceiver on HY-Redbull might be broken ? I'm sure that I connected transceiver circuit for mini STM32 properly + I I connected grounds to make sure that both boards have common ground.

PB8 and PB9 are basic pins fo CAN in STM32F103 so I don't have to remap it am I right?

Re: CAN - Don't get RXMSG

Posted: Mon Feb 10, 2014 11:38 pm
by Giovanni
You should check signals with an oscilloscope to make sure.

Giovanni

Re: CAN - Don't get RXMSG

Posted: Thu Feb 13, 2014 4:39 pm
by bartocham
Hi,

It looks like I'm not getting anything on PB8 and PB9. uC is not sending signal via them. I don't have any idea what's wrong :(

Re: CAN - Don't get RXMSG

Posted: Thu Feb 13, 2014 4:42 pm
by Giovanni
You may be hitting a chip errata, please verify this first.

Giovanni

Re: CAN - Don't get RXMSG

Posted: Fri Jun 20, 2014 9:45 am
by bartocham
Hi!

I didn't have time for those few months but now I'm back on track with that project.

I wrote STM32F103 deeply and I found at that:

PA11 Default
USART1_CTS/CANRX(9)/USBDM/TIM1_CH4(9)

PA12 Default
USART1_RTS/CANTX(9)/USBDPTIM1_ETR(9)

PB8 Remap
I2C1_SCL /CANRX

PB9 Remap
I2C1_SDA/CANTX

So on my eval board I'm not using default pins for CAN. Can you tell me how to remap that ports ?