CAN - Don't get RXMSG
Posted: Sun Feb 09, 2014 4:49 pm
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.
I conclude that if loopback test works properly my init of CAN is ok but I attach start of my main function
Below my CAN config:
Transmission thread:
As I said loobpack works fine so functions getTxFrame and decode works ok.
Below getTxFrame:
Those PIDs from PIDTable are taken correctly.
I put receiver thread into getFrame function which I present below:
Program jumps into that functions but I don't get any resposne from ECU - all parts of rxmsg are 0. Can you help me ?
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 0xFFFFFFFFI 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 ?