Announcement

Collapse
No announcement yet.

picbasic ISO 14230 5-baud init

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • picbasic ISO 14230 5-baud init

    Can anyone assist me with how to get a PIC to perform a 5-baud init please? I'm using picbasic & can't work out how to enable the K and L lines at 5 baud during initialisation then disable the L and dynamically change the baudrate to 10400 on the K line.

    PS - I can't use ELM32x for this project, as once initialised I need to communicate with the ECU in a non-standard ISO way.

    Cheers,
    Chrisall.
    Alt4 - The Open Source Range Rover Diagnostics Project
    http://www.swiftcomm.co.uk/alt4/

  • #2
    If it's anything like the AVR's atmega uart, it might not be able to handle 5 baud right off. I had to bit-bang to operate the baud rate slow enough, and then switch quickly to 10400. I could give you the c code for bitbanging, but not sure how much help that would be in picbasic. I was having timing issues with c at 10400 baud,and gave up and got an ELM rather than re-writing my code in assembly because for my application the ELM worked. I'm not sure how good it's going to be compiling from basic, but I could PM it to you if you think it would help.
    "stop with the REINSTALLS, what do you think we got some lame-o installer!!!" - mitchjs
    RevFE
    My Shop

    Comment


    • #3
      Do not know the PIC you are using but...

      Originally posted by chrisall View Post
      Can anyone assist me with how to get a PIC to perform a 5-baud init please? I'm using picbasic & can't work out how to enable the K and L lines at 5 baud during initialisation then disable the L and dynamically change the baudrate to 10400 on the K line.

      PS - I can't use ELM32x for this project, as once initialised I need to communicate with the ECU in a non-standard ISO way.

      Cheers,
      Chrisall.
      briefly -- this from memory so double check it before you implement it -- you need the ability to time up to 300+ milliseconds.

      Sample the bus until you find it idle and then sample it continuously for 300mS to ensure it stays idle.

      If idle at the end of 300mS then you need a way to time at least 200mS to send the 0x33 at 5 baud.

      Then once that is out, look for a start bit and using a high resolution timer measure the time from the leading edge of the start bit to the falling edge of the 1st bit in the reply, the 1 of the 0x55 (sent in LSB/MSB order).

      Then divide elapsed time between the starting edge of teh start bit and the falling edge of the 1st data bit by two and this is the bit time. Divide by 2 again and this is one half bit time and this is the amount of time by the processor's timer you are using you wait until you sample the data line for the next incoming bit.

      Once you have that bit, the second bit of the 0x55 response, then use the whole bit time to sample what should be the middle of the next data bit, and so on.

      If you receive the 0x55 ok then you have not only the bit time of the OBD2 bus and the engine controller but you have established communication with the ecu.

      I think...

      Sincerely,

      MarcW.

      Comment


      • #4
        Thanks for the replies.

        During the slow init the tester sends the address of the ECU on the K and L lines at 5 baud, then the ECU replies on the K line at 10400 with the sync byte (0x55), followed by the two keybytes. I have all the timing info from the ISO 14230 standard, it's just I can't seem to make the PIC dynamically change baudrates on the fly. I think I need to look at this bit-banging stuff in a bit more detail.

        Cheers,
        Chrisall.
        Alt4 - The Open Source Range Rover Diagnostics Project
        http://www.swiftcomm.co.uk/alt4/

        Comment


        • #5
          Hi Chrisall

          I have used Bit Banging before for non standard Baud Rates in PicBasic and looking at doing the same myself for a OBD-II Project using a Pic.

          Choose you Pin that you are going to use as the transmit line.
          Here I am using Portb.7 that outputs to the K line.

          ******************
          'Define the variable
          Byteout var Byte

          'Set it to 0x33
          Byteout=$33
          'Set the Pin as an Output
          output portb.7


          'have used pauseus of 104ms that gives you 9600 baud, simply cut down the pause time to suit required baud rate: SO for 5 Baud use 1/5 which is 200ms pause and for 10400 Baud use 1/10400 96ms


          To send a byte:

          'Send Start Bit
          portb.7=0
          pauseus 104

          'Send Byte out
          portb.7=Byteout.bit0
          pauseus 104
          portb.7=Byteout.bit1
          pauseus 104
          portb.7=Byteout.bit2
          pauseus 104
          portb.7=Byteout.bit3
          pauseus 104
          portb.7=Byteout.bit4
          pauseus 104
          portb.7=Byteout.bit5
          pauseus 104
          portb.7=Byteout.bit6
          pauseus 104
          portb.7=Byteout.bit7
          pauseus 104

          'Send 1 Stop Bit
          portb.7=1
          pauseus 104

          *****

          To receive a byte:

          'Check for start bit by sampling the port twice within 104us.
          check1:
          if portb.6=0 then
          else
          goto check1
          endif
          pauseus 52
          if portb.6=0 then
          else
          goto check1
          endif
          pauseus 104

          'Receive Byte in
          ByteIn.bit0=portb.6
          pauseus 104
          ByteIn.bit1=portb.6
          pauseus 104
          ByteIn.bit2=portb.6
          pauseus 104
          ByteIn.bit3=portb.6
          pauseus 104
          ByteIn.bit4=portb.6
          pauseus 104
          ByteIn.bit5=portb.6
          pauseus 104
          ByteIn.bit6=portb.6
          pauseus 104
          ByteIn.bit7=portb.6
          pauseus 104

          'Receive 1 Stop bits
          pauseus 104


          Hope this helps.

          Cheers

          Sean.

          Comment

          Working...
          X