Skip to main content
Topic: Anyone able / available to add a new protocol to Bus Pirate? (Read 2136 times) previous topic - next topic

Anyone able / available to add a new protocol to Bus Pirate?

Good day to all.

I'm the proud owner of a Bus Pirate and think this tool is going to help me greatly.

I'd like to add a new protocol to the Bus Pirate but am not sure how to go about even beginning.

I'll describe what I want and was hoping that someone might be interested in helping me implement it.

The protocol is a receive only serial protocol that uses a form of MFM encoding.  Its generated by a chunk of code that I drop into PIC projects when I want to get some data out of a project that I am debugging.

The protocol is simple:

1) an optional sync pulse of 3us
2) 8 data bits where a logical 0 is 6us LO followed by 2us HI and a logical 1 is 2us LO and 6us HI.  Data rate is 125 K bits per second

framing: a period of more than 10us either HI or LO.

Some background:  I drop the code that generates this protocol into projects that I am currently debugging.  Its designed to share a line that is already used as an output - whether its a LED or buzzer or whatever.  It can be implemented such that it preserves and restores the original state of the line when it finishes transmitting the current byte.

I normally look at the bitstream with a DSO set up to trigger on narrow pulses.  I can easily read 1 or 2 bytes of data on the DSO screen.

This has worked well for me for many years.

It occurs to me that it should be child's play to decode this with the Bus Pirate.  That would make viewing easier and would make capturing lots of data to a disk file very easy.

Anyone interested in getting involved with this?

Many thanks!


Re: Anyone able / available to add a new protocol to Bus Pirate?

Reply #1
Hi DwayneR - I don't think it should be a problem to add this to the Bus Pirate. At the moment we're running out of room in the main firmware, though a forthcoming bootloader update should help free up some more space. Probably the best approach for the moment is to build a separate protocol->serial firmware that can be loaded onto the Bus Pirate.

Do you have debugging code that you'd be willing to release under an open license so there's a complete 'package' for anyone else who wants to use this protocol? Since it would be part of the actual Bus Pirate project, public domain (Creative Commons 0) is the preferred license.

I'll create a basic outline (setup, UART, delays, etc) for this firmware in SVN if you'd like to work together on it. It sounds like you have a lot of experience with PIC.
Got a question? Please ask in the forum for the fastest answers.


Re: Anyone able / available to add a new protocol to Bus Pirate?

Reply #2
I have working PIC code that I'm happy to share.  It has been used with 12-bit-core (12F508) and 14-bit-core devices (16Fxxx).

STXFAST  ;enters with byte in W
;This version uses MFM encoding instead of NRZ: 25% / 75% encoding
;View with DSO set to trigger on <3us pulse width
;Designed to share an output line: preserves state of that line
    #define     _STXOUT RA,0    ;transmit on spare pin
;    #define     ShareTXpin     ;uncomment to save state of TX pin
;    #define     SendSyncBit    ;uncomment to send intial sync bit
;    #define     UsingTMR1      ;uncomment if using TIMR1
;    #define     SendLSBfirst   ;uncomment to send data LSB 1st (MSB otherwise)

    movwf       SUBTMP1
    movlw       .8              ;8 data bits, no start or stop bits
    movwf       SUBTMP2

  ifdef         ShareTXpin
    clrf        SUBTMP3         ;save current state of o/p line
    btfsc       _STXOUT
      decf      SUBTMP3,F
    bcf         _STXOUT

  ifdef         UsingTMR1
    bcf         _TMR1ON         ;halt timer 1 for now

  ifdef         SendSyncBit
;send start of byte identifier that DSO can trigger on
    bsf         _STXOUT         ;single pulse 2cy wide (2us)
    nop                         ;set DSO to trigger on + pulse less than 3us

StxLoop         ;8 cy loop: 125 KB/S with 1us instruction time
    bcf         _STXOUT         ;2 cycle LO

  ifdef         SendLSBfirst
    rrf         SUBTMP1,F
    rlf         SUBTMP1,F

    bsf         _STXOUT
    skpc                        ;2cy HI + 4 cy LO **or** 6 cy HI
      bcf       _STXOUT
    decfsz      SUBTMP2,F
      goto      StxLoop

  ifdef         ShareTXpin
    btfsc       SUBTMP3,0       ;restore output pin state
      bsf       _STXOUT
    btfss       SUBTMP3,0
      bcf       _STXOUT
    nop                         ;maintain same HI or LO pulse width
    bcf         _STXOUT         ;idle LO

  ifdef         UsingTMR1
    bsf         _TMR1ON         ;only if TMR1 is used

    return      ;66 cy, not inc call & return
;Using TMR1 adds 2 cy, using SyncBit adds 2 cy, using ShareTX adds 9 cy

Notes for the above:

STMP1, STMP2, STMP3 are RAM bytes allocated for subroutine usage and must be defined prior to this code being called.