View Single Post
Old 11-11-2008, 11:48 PM   #269 (permalink)
trebuchet03
MechE
 
Join Date: Dec 2007
Location: Bay Area
Posts: 1,151

The Miata - '01 Mazda MX-5 Miata
Thanks: 0
Thanked 22 Times in 18 Posts
So I'm going over the code....

prj.perquin.com shows the slowinit sequence as:

Quote:
Code:
_________ S ___ 2 3 ___ 6 7 ___        ____        ____ 
         \_/0 1\___/4 5\___/P  \/\/\/\/    \/\/\/\/
 300ms  200 400 400 400 400 250 packet     response
1) Wait for 300ms with K line high.
2) send a byte 33 hex at 5 baud. 200ms per bit
startbit: 200ms low
databit0,1: 400ms high
databit2,3: 400ms low
databit4,5: 400ms high
databit6,7: 400ms low
stopbit+pause: 250ms high
4) init serial connection to 10400 baud, 8N1, 1=0Volt 0=12Volt, least significant bit first
5) send package c1 33 f1 81 66 33=dest, f1=our tester id, 81=start comms
6) wait for response 83 f1 01 c1 e9 8f ae 01=physical address, c1=response ok (7f=fail), e9=kb1, 8f=kb2

So everything in the obduino code seems good up until step 4/5.

The opengauge code does the 300ms thing, the 5 baud 0x33 stuff... But then it deviates significantly... Rather than sending data, it waits 60ms and then listens for a response. I don't fully understand what steps 4, 5 and 6 are/do, however.

It's also slightly different on the stopbit, it pulls K high for 200ms rather than 250. But, even with that change, I'm still no go.

Does anyone have a better source of documentation for the proper init sequences?


Referenced openguage function
Code:
/* ISO 9141 init */
byte iso_init()
{
  byte b;

 // drive K line high for 300ms
  digitalWrite(K_OUT, HIGH);
  delay(300);

  // send 0x33 at 5 bauds
  // start bit
  digitalWrite(K_OUT, LOW);
  delay(200);
  // data
  b=0x33;
  for (byte mask = 0x01; mask; mask <<= 1)
  {
    if (b & mask) // choose bit
      digitalWrite(K_OUT, HIGH); // send 1
    else
      digitalWrite(K_OUT, LOW); // send 0
    delay(200);
  }
  // stop bit
  digitalWrite(K_OUT, HIGH);
  delay(200);

  // pause between 60 ms and 300ms (from protocol spec)
  delay(60);

  // switch now to 10400 bauds

  // wait for 0x55 from the ECU
  b=iso_read_byte();
  if(b!=0x55)
    return -1;

  delay(5);

  // wait for 0x08 0x08
  b=iso_read_byte();
  if(b!=0x08)
    return -1;

  delay(20);

  b=iso_read_byte();
  if(b!=0x08)
    return -1;

  delay(25);

  // sent 0xF7 (which is ~0x08)
  iso_write_byte(0xF7);

  delay(25);

  // ECU answer by 0xCC
  b=iso_read_byte();
  if(b!=0xCC)
    return -1;

  // init OK!
  return 0;
}
__________________
Cars have not created a new problem. They merely made more urgent the necessity to solve existing ones.

Last edited by trebuchet03; 11-11-2008 at 11:55 PM..
  Reply With Quote