$130 Bosch 4.9 sensor CAN-bus WB - Page 3 - Miata Turbo Forum - Boost cars, acquire cats.

Welcome to Miataturbo.net   Members
 


MEGAsquirt A place to collectively sort out this megasquirt gizmo

Reply
 
 
 
LinkBack Thread Tools
Old 02-24-2016, 12:16 AM   #41
Junior Member
 
Join Date: May 2007
Location: Atlanta
Posts: 383
Total Cats: 38
Default

With my code have you enabled a can broadcast from TS? By default my code doesn't do any requesting. Which arduino are you using?

edit: the seedstudio appears to be mostly identical to the sparkfun canbus shield.. d2 as interrupt, d10 as cs, stock spi pins. Not sure why my my code shouldn't work, serial is showing the can init?

Last edited by gooflophaze; 02-24-2016 at 12:49 AM.
gooflophaze is offline   Reply With Quote
Old 02-24-2016, 01:26 AM   #42
Boosting since 1984
Thread Starter
iTrader: (1)
 
stefanst's Avatar
 
Join Date: Sep 2011
Location: Levittown
Posts: 1,198
Total Cats: 68
Default

Yeah, broadcast was enabled. I'm sure I screwed something up. Will try again tomorrow.
stefanst is offline   Reply With Quote
Old 02-24-2016, 04:55 AM   #43
Junior Member
 
Join Date: May 2007
Location: Atlanta
Posts: 383
Total Cats: 38
Default

Weird.. I just ran the seedstudio library back to back with my code and both were able to pull data off the wire with the defaults (well, minus changing the chip select from 9 to 10).

Edit: I think I figured it out maybe.. add a SPI.transfer(0xC0); to reset and delay(100); to the beginning of setup()

and add

Serial.println(CANRead(CANCTRL), HEX);
Serial.println(CANRead(CNF1), HEX);
Serial.println(CANRead(CNF2), HEX);
Serial.println(CANRead(CNF3), HEX);

to the end. Both the sparkfun and seedstudio schematics are a little vague on their MCP2515 reset pin. If the CANread is printing 0x00, then MCP2515 isn't getting initted properly.

Last edited by gooflophaze; 02-24-2016 at 08:58 AM.
gooflophaze is offline   Reply With Quote
Old 02-24-2016, 09:08 PM   #44
Boosting since 1984
Thread Starter
iTrader: (1)
 
stefanst's Avatar
 
Join Date: Sep 2011
Location: Levittown
Posts: 1,198
Total Cats: 68
Default

Finally getting somewhere!

Your code used an apparently deprecated version of "attachInterrupt"
New code:
attachInterrupt(digitalPinToInterrupt(INT_PIN), ISR_can, FALLING);


Now I'm reading data from MS3 and from the WB. Now to get rid of all your parsing routines and do a simple HEX dump....
stefanst is offline   Reply With Quote
Old 02-24-2016, 09:45 PM   #45
Boosting since 1984
Thread Starter
iTrader: (1)
 
stefanst's Avatar
 
Join Date: Sep 2011
Location: Levittown
Posts: 1,198
Total Cats: 68
Default

@gooflophaze:
The data I'm reading using your code matches what I'm getting with the OBD2-reader!

I can see the actual data being stored in "databuffer". Where can I find the sender address?

Edit:
Of course the ultimate goal is to actually send data to the WB, reprogramming it.
Any chance you can help me with that?

Also: I have figured out part of the reason why the Seeed CAN library doesn't get any data. It seems to be the wrong initialization. Symptom: The MCP2515 doesn't pull the interrupt low after receiving from the WB. Using your code the interrupt pin gets pulled low. The RX line LED is flashing either way, so we know the transceiver is sending data to the 2515. But the 2515 can't do anything with the data when using the library. I'm using the same CNF registers as with your code, so the bitrate is set properly.

Last edited by stefanst; 02-24-2016 at 11:00 PM.
stefanst is offline   Reply With Quote
Old 02-25-2016, 12:01 AM   #46
Junior Member
 
Join Date: May 2007
Location: Atlanta
Posts: 383
Total Cats: 38
Default

Huh, guess I'll need to push a quick update then. There's an easy way of making it non-intterupt, just do a quick if (digitalRead(int_pin) == LOW) { MSParse();} or something like that. Moving from the registers to can packet.. quick and dirty I can do real quick.

if ((B00001000 & SIDL) == 0) {
// standard (not extended) can frame
CANid = SIDH; // copy
CANid = CANid << 3; // shift left 3 bits into 16bit int
CANid = CANid + ( (SIDL & B11100000) >> 5); // copy 3 bits, shift them right
}

bewm, there's your 11 bit can ID. not as clean as pulling from a can library.

But I would encourage (now that it's verified the MCP2515 is working) getting the seed library working. I wrote my code trying as bare metal as possible to minimize memory. Plus it helps illustrate the Buffers vs Megasquirt ordering (if you use an ANSI terminal).
gooflophaze is offline   Reply With Quote
Old 02-25-2016, 01:34 AM   #47
Boosting since 1984
Thread Starter
iTrader: (1)
 
stefanst's Avatar
 
Join Date: Sep 2011
Location: Levittown
Posts: 1,198
Total Cats: 68
Default

After confirmation that Arduino & MCP2515 are actually working, I hunted around Google for a bit and discovered a fixed CAN library here: https://github.com/coryjfowler/MCP_CAN_lib
Using that library I can read data and address from the WB with the Arduino.

Tomorrow I'll try and reprogram it to use 500kbps and standard frames.

Getting there!
stefanst is offline   Reply With Quote
Old 02-25-2016, 12:52 PM   #48
Junior Member
 
Join Date: May 2012
Location: Jersey City, NJ
Posts: 108
Total Cats: 10
Default

Quote:
Originally Posted by stefanst View Post
I don't think their FW is public domain. Just checked their website and the FW I could find looks like it's already compiled. Or maybe I'm missing something? If so I would appreciate a pointer!
bottom of MS3 Development Releases - Megasquirt EFI maybe?

Works in https://en.wikipedia.org/wiki/Public_domain would be "whose exclusive intellectual property rights have expired, have been forfeited, or are inapplicable."

MS is not public domain for sure. And while we are on this subject, MS is obviously not https://en.wikipedia.org/wiki/Open_source due to limitations under which they allow you to look at their source code. But they do show their source codes, at least some of them. Even if these are getting harder to find
russian is offline   Reply With Quote
Old 02-25-2016, 12:53 PM   #49
SADFab Destructive Testing Engineer
iTrader: (5)
 
aidandj's Avatar
 
Join Date: Apr 2014
Location: Beaverton, USA
Posts: 17,992
Total Cats: 1,457
Default

As far as I know they don't claim to be open source in the traditional manner. They provide the source to people who purchase their products.
aidandj is offline   Reply With Quote
Old 02-25-2016, 01:00 PM   #50
Boosting since 1984
Thread Starter
iTrader: (1)
 
stefanst's Avatar
 
Join Date: Sep 2011
Location: Levittown
Posts: 1,198
Total Cats: 68
Default

At that point we were actually talking about the TinyIOX module, which is made by Jbperf. I don't think they are officially part of B&G which I understand to be the owner of Megasquirt intellectual property. But in any case, I don't think their FW is PD or open source either.
stefanst is offline   Reply With Quote
Old 02-25-2016, 08:06 PM   #51
Junior Member
 
Join Date: May 2007
Location: Atlanta
Posts: 383
Total Cats: 38
Default

I looked it up and turns out the attach isn't deprecated, it's just got a handy new helper macro to align pin numbers to interrupts.

I went back and read what you're trying to do with the packet - All you need to do to send that (with my code) is modify the MSRequest function.

81 81 29 01 00 00 03 (assuming these are all data bytes?). offset is pretty much the same as CanID, just need to disable setting the EID bit.

SIDL = (lowByte((offset << 5)) | B0001000); //set IDE bit change to
SIDL = lowByte((offset << 5));

and then

DLC = B00000011; < change to B00001000 since we're sending 8 bytes

and then start the data packets after DLC is transmitted
digitalWrite(CS_PIN,LOW);
SPI.transfer(0x40); // Push bits starting at 0x31 (TXB0SIDH)
SPI.transfer(SIDH); //0x31
SPI.transfer(SIDL); //0x32
SPI.transfer(EID8); //0x33
SPI.transfer(EID0); //0x34
SPI.transfer(DLC); //0x35
SPI.transfer(0x81);
SPI.transfer(0x81);
SPI.transfer(0x29);
SPI.transfer(0x01);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x03);
digitalWrite(CS_PIN,HIGH); // end write

that should write the packet you're looking for assuming I'm parsing the details correctly.

Edit: DLC should be B00000111 since we're sending 7 bytes. And if I wasn't clear before - MS's offset var is the same byte manipulation required to create an 11 bit can id. It's been a long day and my brain is fried.

Last edited by gooflophaze; 02-25-2016 at 08:37 PM.
gooflophaze is offline   Reply With Quote
Old 02-25-2016, 09:04 PM   #52
Boosting since 1984
Thread Starter
iTrader: (1)
 
stefanst's Avatar
 
Join Date: Sep 2011
Location: Levittown
Posts: 1,198
Total Cats: 68
Default

Well, I just tried sending the data package from the Seeed CAN library, using

unsigned char stmp[8] = {0x81, 0x81, 0x29, 0x01, 0x00, 0x00, 0x00, 0x03};
u32 address = 0x1FFFFFFF;
CAN0.sendMsgBuf(address, 1, 8, stmp);

And it worked, since I can see it showing up on the monitor in between the data from the WB, but it didn't actually reprogram the WB....

I will try your addition/change to your code next.

Edit: This is the output I get with the monitor:

3 0FF00 01 33 5B FC FF 85 9A 0A 00
6 0F00E 01 FF FF 33 5B BA EA FF FF
7 1FFFF FF 81 81 29 01 00 00 00 03
3 0FF00 01 33 5B FC FF 85 9A 0A 00
3 0FF00 01 33 5B FC FF 85 9A 0A 00
7 1FFFF FF 81 81 29 01 00 00 00 03
3 0FF00 01 33 5B FC FF 85 9A 0A 00
3 0FF00 01 33 5B FC FF 85 9A 0A 00
7 1FFFF FF 81 81 29 01 00 00 00 03
3 0FF00 01 33 5B FC FF 85 9A 0A 00
6 0F00E 01 FF FF 33 5B BA EA FF FF
3 0FF00 01 33 5B FC FF 85 9A 0A 00
7 1FFFF FF 81 81 29 01 00 00 00 03
3 0FF00 01 33 5B FC FF 85 9A 0A 00
3 0FF00 01 33 5B FC FF 85 9A 0A 00
7 1FFFF FF 81 81 29 01 00 00 00 03

The "7 1FFFF FF" packets are my attempt at reprogramming.
stefanst is offline   Reply With Quote
Old 02-25-2016, 09:31 PM   #53
Boosting since 1984
Thread Starter
iTrader: (1)
 
stefanst's Avatar
 
Join Date: Sep 2011
Location: Levittown
Posts: 1,198
Total Cats: 68
Default

So I have rewritten your MSrequest routine like this:
Code:
void MSwrite(byte block, unsigned int offset, byte req_bytes) {

  byte SIDH, SIDL, EID8, EID0, DLC, D0, D1, D2;

  SIDL = (lowByte((offset << 5)) | B0001000); //set IDE bit change to
  SIDL = lowByte((offset << 5)); 
    
  EID8 = B10011000; //:7 msg_req, from id 3 (4:3)

  //      TBBBBBSS To, Block, Spare
  EID0 = ( ( block & B00001111) << 3); // last 4 bits, move them to 6:3
  EID0 = ((( block & B00010000) >> 2) | EID0); // bit 5 goes to :2

  DLC = B00001000;
  D0=(block);
  D1=(offset >> 3);
  D2=(((offset & B00000111) << 5) | req_bytes); // shift offset

  digitalWrite(CS_PIN,LOW);
  SPI.transfer(0x40); // Push bits starting at 0x31 (RXB0SIDH)
  SPI.transfer(SIDH); //0x31
  SPI.transfer(SIDL); //0x32
  SPI.transfer(EID8); //0x33
  SPI.transfer(EID0); //0x34
  SPI.transfer(DLC);  //0x35
  SPI.transfer(0x81); 
  SPI.transfer(0x81); 
  SPI.transfer(0x29); 
  SPI.transfer(0x01); 
  SPI.transfer(0x00); 
  SPI.transfer(0x00); 
  SPI.transfer(0x03); 
  digitalWrite(CS_PIN,HIGH); // end write

  CANWrite(CANINTF,0x00);
but what parameters to use for block, offset and reqbytes?
stefanst is offline   Reply With Quote
Old 02-25-2016, 09:40 PM   #54
Junior Member
 
Join Date: May 2007
Location: Atlanta
Posts: 383
Total Cats: 38
Default

That's a function I ripped out of another program - so you can pass offset(can id), and ignore block and req_bytes (well, not ignore - you'll have to pass data but it won't do anything since EID* bits are ignored in a standard frame).

SIDH declaration is missing.

SIDH = lowByte(offset >> 3);


And we're sending 7 bytes, not 8 - so DLC = 0x07
gooflophaze is offline   Reply With Quote
Old 02-25-2016, 09:50 PM   #55
Junior Member
 
Join Date: May 2007
Location: Atlanta
Posts: 383
Total Cats: 38
Default

quickcheck - no, i'm counting wrong.. it needs 8 bytes. DLC = 0x08, and you need another SPI.transfer.
gooflophaze is offline   Reply With Quote
Old 02-25-2016, 10:13 PM   #56
Boosting since 1984
Thread Starter
iTrader: (1)
 
stefanst's Avatar
 
Join Date: Sep 2011
Location: Levittown
Posts: 1,198
Total Cats: 68
Default

Code is now changed to
Code:
void MSwrite(byte block, unsigned int offset, byte req_bytes) {
  
  byte SIDH, SIDL, EID8, EID0, DLC, D0, D1, D2;

  SIDL = (lowByte((offset << 5)) | B0001000); //set IDE bit change to
  SIDL = lowByte((offset << 5)); 
  SIDH = lowByte(offset >> 3);
    
  EID8 = B10011000; //:7 msg_req, from id 3 (4:3)

  //      TBBBBBSS To, Block, Spare
  EID0 = ( ( block & B00001111) << 3); // last 4 bits, move them to 6:3
  EID0 = ((( block & B00010000) >> 2) | EID0); // bit 5 goes to :2

  DLC = 0x08;
  D0=(block);
  D1=(offset >> 3);
  D2=(((offset & B00000111) << 5) | req_bytes); // shift offset

  digitalWrite(CS_PIN,LOW);
  SPI.transfer(0x40); // Push bits starting at 0x31 (RXB0SIDH)
  SPI.transfer(SIDH); //0x31
  SPI.transfer(SIDL); //0x32
  SPI.transfer(EID8); //0x33
  SPI.transfer(EID0); //0x34
  SPI.transfer(DLC);  //0x35
  SPI.transfer(0x81); 
  SPI.transfer(0x81); 
  SPI.transfer(0x29); 
  SPI.transfer(0x01); 
  SPI.transfer(0x00); 
  SPI.transfer(0x00);
  SPI.transfer(0x00); 
  SPI.transfer(0x03); 
  digitalWrite(CS_PIN,HIGH); // end write

  CANWrite(CANINTF,0x00);
}
called with
MSwrite(0x7ff,0x00,0x00);

Still can't see anything showing up on the bus....
stefanst is offline   Reply With Quote
Old 02-25-2016, 10:18 PM   #57
Junior Member
 
Join Date: May 2007
Location: Atlanta
Posts: 383
Total Cats: 38
Default

You've filled the buffer, but you still need to trigger it. RTS == request to send.

// RTS - Send this buffer down the wire
digitalWrite(CS_PIN,LOW);
SPI.transfer(B10000001);
digitalWrite(CS_PIN,HIGH);

CANWrite(CANINTF,0x00);
gooflophaze is offline   Reply With Quote
Old 02-25-2016, 10:28 PM   #58
Boosting since 1984
Thread Starter
iTrader: (1)
 
stefanst's Avatar
 
Join Date: Sep 2011
Location: Levittown
Posts: 1,198
Total Cats: 68
Default

Still no data on the bus -sorry to be such a pain...
stefanst is offline   Reply With Quote
Old 02-25-2016, 10:38 PM   #59
Junior Member
 
Join Date: May 2007
Location: Atlanta
Posts: 383
Total Cats: 38
Default

Salright, I've been awake for 24 hours now so I'm starting to see crosseyed. MSWrite needs some of the values transposed, I think..

MSwrite(0x7ff,0x00,0x00);

should be MSwrite(0x00, 0x7ff, 0x00);

and the RTS is at the end of MSwrite right?
gooflophaze is offline   Reply With Quote
Old 02-25-2016, 10:48 PM   #60
Boosting since 1984
Thread Starter
iTrader: (1)
 
stefanst's Avatar
 
Join Date: Sep 2011
Location: Levittown
Posts: 1,198
Total Cats: 68
Default

Progress!

data is showing up on the bus, but it looks like standard frames- not extended....
dump from sniffer:
Code:
7FF 81 81 29 01 00 00 00 03 <DATA ERROR
7FF 81 81 29 01 00 00 00 03 <DATA ERROR
7FF 81 81 29 01 00 00 00 03 <DATA ERROR
7FF 81 81 29 01 00 00 00 03 <DATA ERROR
7FF 81 81 29 01 00 00 00 03 <DATA ERROR
7FF 81 81 29 01 00 00 00 03 <DATA ERROR
7FF 81 81 29 01 00 00 00
BUFFER FULL
stefanst is offline   Reply With Quote
 
 
Reply

Related Topics
Thread Thread Starter Forum Replies Last Post
Difficult/Impossible to start when cold Ncorlis General Miata Chat 14 01-11-2016 11:16 PM
MS2 enhanced boost control circuit for VVT control elektron MEGAsquirt 7 01-08-2016 09:35 AM
Knock sensor ground btabor Engine Performance 10 01-06-2016 11:40 AM
NA ABS front spindles/sensors/hubs $100 Savington Miata parts for sale/trade 2 01-04-2016 09:41 PM
DIYPNP sensor noise & grounding wackbards MEGAsquirt 1 12-31-2015 07:35 PM


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



All times are GMT -4. The time now is 06:15 PM.