MS3 CANbus on Mazda3

This forum is for the discussion of other projects on Megasquirt/Microsquirt hardware that don't fit into any of the other forums

Moderators: jsmcortina, muythaibxr

Post Reply
NArcher
Helpful MS/Extra'er
Posts: 55
Joined: Wed Mar 23, 2011 1:38 pm

MS3 CANbus on Mazda3

Post by NArcher »

I have a couple questions when implementing the code that stevevp put up in his CANbus topic. By the way here is the code that I'm refering to:
stevevp wrote:Firstly you have to open up the receive buffers to allow all can message in

in CanInit()

Code: Select all

	/* Set identifier acceptance and mask registers to accept 11 and 29 bit messages from all devices */
	CANIDMR0 = 0xFF;       // anything ok in IDR0(var offset)
	CANIDMR1 = 0xFF;       //was 0xE7;		   // anything ok for var_off cont'd, msgtype
	CANIDMR2 = 0xFF;       //was 0xF0;			 // can be from any other device
	CANIDMR3 = 0xFF;       // any var_blk, spare, rtr
	CANIDAR1 = 0x00;       //was 0x18;       // 0,0,0,SRR=IDE=1
	CANIDAR2 = 0x00;       //was can_id;     // rcv msg must be to can_id, but now accepts any
	/* 2nd 32-bit filter bank */
	CANIDMR4 = 0xFF;       // anything ok in IDR0(var offset)
	CANIDMR5 = 0xFF;       //0xE7;		   // anything ok for var_off cont'd, msgtype
	CANIDMR6 = 0xFF;       //0xF0;			 // can be from any other device
	CANIDMR7 = 0xFF;       // any var_blk, spare, rtr
	CANIDAR5 = 0x00;       //0x18;       // 0,0,0,SRR=IDE=1
	CANIDAR6 = 0x00;       //0x0F;			 // rcv msg can be to everyone (id=15), and
then the interrupt routine needs to handle MSG_STD
in CanRxIsr()

Code: Select all

    if([b]CAN0RFLG[/b] & 0x01)  {
    
        var_off = ((unsigned short)CAN0_RB_IDR0 << 3) |
                       (([b]CAN0_RB_IDR1[/b] & 0xE0) >> 5);
      [b]  msg_IDE[/b] = [b](CAN0_RB_IDR1 & 0x08);[/b]
        msg_type = MSG_CMD;
        if (msg_IDE) {
          if ((CAN0_RB_DLR & 0x0F)==15){// &0x0F = 00001111, get first 4 bits
            msg_type = (CAN0_RB_IDR1 & 0x07);
          }
        } else {
          msg_type = MSG_STD;
        }
        rcv_id = [b]CAN0_RB_IDR2[/b] >> 4;		// message from device rcv_id
        var_blk = [b]CAN0_RB_IDR3[/b] >> 4;
        var_byt = ([b]CAN0_RB_DLR[/b] & 0x0F); // &0x0F = 00001111, get first 4 bits

        switch(msg_type)  {
        
          case MSG_STD:  // message to be processed
                msgID = ([b]CAN0_RB_IDR0[/b] << 3);
                msgID = msgID + ([b]CAN0_RB_IDR1[/b] >> 5);
                        // 8 high bits in IDR0, 3 low bits in IDR1      
              // update variable value with received data
                data[0]  =  CAN0_RB_DSR0; //Changed to add the "0". For ex:  CAN_RB_DSR0 changed to CAN0_RB_DSR0
                data[1]  =  CAN0_RB_DSR1;
                data[2]  =  CAN0_RB_DSR2;
                data[3]  =  CAN0_RB_DSR3;
                data[4]  =  CAN0_RB_DSR4;
                data[5]  =  CAN0_RB_DSR5;
                data[6]  =  CAN0_RB_DSR6;
                data[7]  =  CAN0_RB_DSR7;
                STD11_receive_CAN(msgID,data,var_byt,MSG_STD) ;
                
          case MSG_CMD:  // message for this ecu to set a variable to value in message
        	  break;
then we need to process the STD 11 bit message

Code: Select all

void STD11_receive_CAN(unsigned int Rx_id, unsigned char *Rx_data, unsigned char Rx_dataLen, unsigned char flags)
{
	// Receive Message Variables
  //    unsigned int Rx_id;
  //    unsigned char Rx_data[8];
  //    unsigned char Rx_dataLen;

// enable the following for debug if required
//	ECANSendMessage(Rx_id+1, Rx_data, Rx_dataLen, MSG_STD);

    if (flags == MSG_STD) {
				flags = MSG_STD;
    }

		if (Rx_id == 0x4B0) // ID of ABS wheel speed sensors. Byte 0,1 = LF; 2,3 = RF; 4,5 = RR; 6,7 = LR 
  		{
  		[b]datax1.vss1_16 = (((Rx_data[0]) /100) /256);[/b]
  		}


The questions that I have are:
1. Where to put data coming from abs computer? I think this might be pulsed data, but not sure. If I read correctly, James said that remote vss information should be in one of four fields: datax1.vss1_16, datax1_8, datax1.pwm32, or datax1.pwm16, but which field?

2. Does the code look correct? I am fairly certain that it is correct, I just made some minor adjustments to work for MS3. The problem that I have is when I load the firmware, then turn off and on the MS3, I get a settings error on TunerStudio, followed by TS going offline. I try to reload firmware the normal way, but have to bootjump to load. I think this might be caused by me not knowing where to properly store the incoming CAN data. Thanks guys for your help. I really appreciate all you do!
NArcher
Helpful MS/Extra'er
Posts: 55
Joined: Wed Mar 23, 2011 1:38 pm

Re: MS3 CANbus on Mazda3

Post by NArcher »

I know there are a lot of Miata (2002+) guys as well who would benefit from this. The ECM's from Mazda 3 plug right into their harness and can control either engine so I know this would work for them as well. That way, no one has to get custom gauges for their car.
jsmcortina
Site Admin
Posts: 39611
Joined: Mon May 03, 2004 1:34 am
Location: Birmingham, UK
Contact:

Re: MS3 CANbus on Mazda3

Post by jsmcortina »

NArcher wrote:I get a settings error on TunerStudio, followed by TS going offline.
What is the settings error?

I don't know about the code posted, I've not studied it in detail.

James
I can repair or upgrade Megasquirts in UK. http://www.jamesmurrayengineering.co.uk

My Success story: http://www.msextra.com/forums/viewtopic ... 04&t=34277
MSEXTRA documentation at: http://www.msextra.com/doc/index.html
New users, please read the "Forum Help Page".
NArcher
Helpful MS/Extra'er
Posts: 55
Joined: Wed Mar 23, 2011 1:38 pm

Re: MS3 CANbus on Mazda3

Post by NArcher »

It's a different error every time. Sometimes TS says it's an EGO error, where EGO is configured on the wrong pin, or there is a mis-match between settings. Other times it might be the speed sensor settings, or another setting. The thing is, when I try to correct it and burn to ecu, TS goes offline, saying I need to correct the issue by means of reflash. Another error that I seen recently is TS saying that it detected the flash in an erase state. After the error, TS goes offline. I try to use the reflash utility, but it cannot detect the ecu. My only option is to boot jump MS3.
Post Reply