[wisp stuff doelie@zzz.kotnet.org**20050412220934] { addfile ./comp/wisp.f addfile ./wisp/protocol.html hunk ./comp/compiler.f 36 +: char accept buffer h@ 0xff and ; hunk ./comp/compiler.f 62 +: while_ if_ swap again_ then_ ; hunk ./comp/compiler.f 69 - +: hc@ h@ 0xff and ; hunk ./comp/compiler.f 158 + + + +( port IO ) + hunk ./comp/wisp.f 1 +( -*- forth -*- ) +( wisp628 interfacing ) + +: c char ; +: [c]_ c lit_ ; + +: >hex 0xf and 10 over > if [c] 0 + else [c] 10 - + then ; +: hex> dup [c] A >= if 10 [c] A - + else [c] 0 - then 0xf and ; + + + + + +( for 12f629: + 004cx programming mode + 0000g launch target + rnnni read current location and increment ) + +: w out in ( dup emit ( ) ; ( send a byte to wisp + get ack ) +: char w ; +: [w]_ char lit_ w_ ; + +: !ww 4 for dup >hex w drop 4 >> next drop ; ( send a 16bit number to wisp ) +: !www 6 for dup >hex w drop 4 >> next drop ; ( send a 24bit number to wisp ) +: @ww 0 4 for 4 << [w] N hex> or next ; ( fetch a 16bit number from wisp ) + + + +( wisp commands ) +: read [w] R drop @ww [w] I drop ; +: jump [w] !www [w] m drop ; + + +: forchar_ accept_ buffer_ begin_ dup_ hc@_ ; +: nextchar_ 1 lit_ +_ dup_ hc@_ while_ drop_ ; + +( generic parsing command ) +: wisp forchar w drop nextchar ; +: [wisp]_ forchar lit_ w_ drop_ nextchar ; + +: program [wisp] 004cx ; +: go [wisp] 0000g ; +: hello [wisp] 0000h ; +: who [wisp] tnnnnnnnn cr [wisp] vnnnnnnnn cr ; + hunk ./src/badnop.c 174 +int port_fd = -1; // serial port fd hunk ./src/badnop.c 437 +#include +#include hunk ./src/badnop.c 792 + else if (val = FLAG("--port=")) { + port_fd = open(val, O_RDWR); + if (-1 == port_fd){ + fprintf(stderr, "can't open port %s\n", val); + } + } hunk ./src/badnop.c 975 + PRIM("buffer", buffer); hunk ./src/badnop.c 995 + PRIM("in", readport); + PRIM("out", writeport); hunk ./src/badnop.c 1133 + buffer: + PUSH_DS(word); NEXT; hunk ./src/badnop.c 1441 + + /* port io */ + writeport: { char buf[1]; buf[0] = pop_ds(); write(port_fd, buf, 1); NEXT; } + readport: { char buf[1]; if (1 != read(port_fd, buf, 1)) error_abort("can't read"); push_ds(buf[0]); NEXT; } + hunk ./wisp/protocol.html 1 - + + + + +Wisp628 communication protocol + + + +

+
+wesp + + +

Wisp628
communication protocol

+ +
+wesp +
+

+ +
+ +

introduction

+ +

+The communication protocol used by the Wisp628 programmer +conforms to the WBus definition, +but the multi-drop feature of WBus is not used. +This is the reason for some concepts and commands +(like the 'activation' of the programmer) +that might seem a bit out of place in a one-to-one communication protocol. +

+ +

+The protocol uses the asynchronous serial format, 8 data bits, no parity, +1 stop bit, at 19200 baud. Only three lines (ground, transmit, receive) +are used. No hardware handshake signals are used. +The highest (MSB) bit of received data is ignored. +The programmer's serial interface uses a female DB9 connector, +which can be plugged directly into a PC's male DB9 connector. +When (more likely) a serial cable is used it must be +a straight ('extension') cable, not a crossed ('null modem') cable. +

+ +

+The protocol requires the PC to send only the digits '0' .. '9' +and the letters 'a' .. 'z'. The digits '0' .. '9' and the letters 'a' .. 'f' +are used for data, the other letters are commands. +The data that applies to a command is sent before the command. +

+ +

+The protocol requires that (with a few exceptions) the programmer +echoes each character sent by the PC, and the PC sends the +next character only when it has received the echo for the previous one. +The programmer converts the character to uppercase +and clears the highest (MSB) bit before echoing it. +The programmer echoes a command character after it +has succesfully completed a command. When +a command fails a '?' character is echoed +instead to indicate the failure. +

+ +

+To get data from the programmer a command is sent that instructs the +programmer to put the data in a buffer. +Next a sequence of next commands +is used to retrieve the data, character by character, from the buffer. +The data can contain any printable character. +

+ +

+The programmer can be in three states: +sleep, attention, active, and passthrough. +The sleep state is supported by the programmer but has no function +for one-to-one communication. +A break condition on the serial line forces the programmer +from the sleep or passthrough state to the attention state. +The hello command forces the programmer to the active state, +which is the state required by most commands. +The passthrough command sets the programmer in +passthrough state. This state can only be left by a serial line break. +

+ +

+The passthrough state is used to 'connect' the serial line directly +to the target PICmicro, for instance for debugging. +In this state the programmer itself ignores the data +on the serial line completely, except that a break +condition ends the passthrough. +The communication between the host and the target PICmicro can use +any data format and baudrate, except that + +
  +a break condition must be avoided +
+ +
  +baudrates above 19k2 might not be reliable because passthrough is implemented in software. +
+

+ +

+For experimenting, debugging etc. +the wisp.exe program has the talk command that activates the programmer +and then presents a simple interface to the user where he can type characters +to be sent to the programmer and see the response. +

+ + + +
+ +

commands

+ +

+The relevant commands are described, with the states in which the command is recognised +by the programmer. When the letters 'a' .. 'f' appear in the format they +stand for data values, as explained with the command. All other letters +in the format stand for themselves. +

+ +

+ + + + +
command  break
formatbreak condition
statessleep, passthrough
+A break on the serial line of at least 80 ms forces the programmer +from the sleep or passthrough state to the attention state. +After a break the programmer will respond to a hello command. +

+ +

+ + + + +
command  go
format0000g
statesactive
+A go command causes the programmer to end programming +the target and to release the targets /MCLR (reset) line, +thus causing the target to start running it stored program. +

+ +

+ + + + +
command  hello
format0000h
statesattention, active
+A hello command forces the programmer to the active state, +provided that it was either in the active or attention state. +(Use a break to get the programmer into one of these states.) +Depending on the state of the programmer the characters +of the hello command can either be echoed by the programmer +or not. When no echo is received an interval of +at least 80 ms must be observed between sending the characters +of the hello command. +

+ +

+ + + + +
command  increment
formati
statesactive
+An increment command causes the programmer to +increment the current location. +

+This command is best used with the programming algorithms 1 and 2 +when sequential locations are programmed. +For programming algorithm 3 +the read and write commands are auto-incrementing. +The jump command can be used (and must be used with algorithm 3) +to select a random address +(instead of incrementing up to the desired address). +

+ +

+ + + + +
command  jump
formatabcdefm
statesactive
+An jump command causes the programmer to +set the current location to the value 'abcdef'. +

+This command is supported only by algorithm 3. +For algorithms 1 and 2 the increment command +must be used to change the current addrees. +

+ +

+ + + +
command  lazy write
format +a..fl (note: the last character is the letter l, not the number) +
statesactive
+A lazy write command causes the programmer to +read from the target the data at the current location. +If it is equal to the specified data nothing is done. +If it is not equal +the data is written to the current location (see write command). +A lazy write command requires a previous program command. + +

+Lazy writing can speed up programming of when programming algorithm 1, 2 or 4 is used. +For programming algorithm 3 a lazy write behaves the same as a normal write. +

+ +

+ +The current firmware handles lazy write as a normal write. +This might change in the future. + +

+ +

+ +

+ + + + +
command  next
formatn
statesactive
+The next command is used to retrieve the next data character +from the programmer's data buffer. +The programmer responds with the next data character. +

+This command is used after a command that stores data in this buffer. +When a string is retrieved from the data buffer it can either be +preceded by a space and be terminated by a space (both spaces are +not considered part of the string), or +start with a non-space, and be exactly four characters in length. +

+ +

+ + + + +
command  passtrough
format00abp
statesactive
+The passthrough command is used to put the programmer in passthrough mode. +

+The a value selects the lines +(of the programmers target DB15M connector) and polarity used for the communication +between the programmer and the target PICmicro. +

+ +
  +ab = '00' : line 3 for programmer-to-target, line 4 for +target-to-programmer, RS232 polarity (used when the PICmicro would +connect to +the RS232 lines without an inverting buffer) +
+ +
  +ab = '01' : line 3 for programmer-to-target, line 4 for target-to-programmer, TTL polarity (as used by the PICmirco UART) +
+ +
  ab += '02' : line 7 for programmer-to-target, line 8 for +target-to-programmer, RS232 polarity (used when the PICmicro would +connect to +the RS232 lines without an inverting buffer) +
+ +
  +ab = '03' : line 7 for programmer-to-target, line 8 for target-to-programmer, TTL polarity (as used by the PICmirco UART) +
+ +

+When the PICmicro communicates using its UART the passthrough command +should be 0011p, line 7 should be connected to the target's UART RxD pin, +and line 8 to the target's UART TxD pin. +

+ +

+The passthrough command can also be used to switch the programmer to a different +baudrate, without entering the passthrough mode. +The confirmation (the 'p') will be sent back at the new baudrate. +A break (framing error) will switch the baudrate back to the default. +

+ +
  +ab = '04' : switch to 9k6 +
+ +
  +ab = '14' : switch to 19k2 (which is the power-up default) +
+ +
  +ab = '24' : switch to 38k4 +
+ +
  +ab = '34' : switch to 57k6 +
+ +
  +ab = '44' : switch to 115k2 +
+ +

+ +

+ + + +
command  program
formataabcx
statesactive
+The program command causes the programmer to start programming. +It applies the Vpp (programming enable) voltage to the target PICmicro +so the target enters programming mode. +A suitable (c, d or f) program command must be used before +a read or write command is used. + +

+The value of c selects the memory region that is programmed. +The current location is set to the first location of the selected region. + +
  +c = 'c' : enter programming mode for code memory +
+ +
  +c = 'd' : enter programming mode for eeprom data memory +
+ +
  +c = 'e' : erase the target (needed to remove copy protection) +
+ +
  +c = 'f' : enter programming mode for configuration memory (device ID, fuses) +
+ +

+The value of b selects the programming (read and write) algorithms. + +
  +b = '0' : read and write algorithms for 16x84, 16f62x and 16f87x, +works for reading 16f7x, 16f87xA, 16f81x, 12fxxx +
+ +
  +b = '1' : read, write, erase algorithms for 16f7x (writes one location at a time) +
+ +
  +b = '2' : read, write, erase algorithms for 16f87xA (writes one location at a time) +
+ +
  +b = '3' : read, write, erase algorithms for 18fxxx (writes 8 bytes at a time) +
+ +
  +b = '4' : read, write, erase algorithms for 12fxxx +
+ +
  +b = '5' : as '0', but reads 4 locations = 8 bytes at a time, auto-increments on read +
+ +
  +b = '6' : as '3', but reads 8 locations = 8 bytes at a time, auto-increments on read +
+ +
  +b = '7' : read, write, erase algorithms for 16f81x (writes 4 locations = 8 bytes at a time, autoincrementing) +
+ +

+The value of aa selects (where appropriate) the delay used. + +
  +aa = '00' : use a suitable default that will work but might be somewhat slow +
+ +
  +aa = ... : for writes this is interpreted as the write delay (two hex nibbles), +for other commands it is ignored. +
+ + + +

+ +

+ + + + +
command  read
formatr
statesactive
+The read command causes the programmer to read, +form the target, the value at current location, +and copy its value (as hexadecimal nibbles) +to the data buffer, from which it can be retrieved by next commands. +A read command requires a previous program command. +

+The number of bytes read depends on the programming algorithm and the memory area. +EEPROM data memory is always read one byte at a time. +Algorithms 1 and 2 read program and configuration memory 14 bits at a time. +Algorithm 3 reads program and configuration memory one byte at a time. +

+For algorithms 1 and 2 the current location is not affected by a read +command. For algorithm 3 the current location is incremented by the amount of data read. +

+ +

+ + + + +
command  type
formatt
statesactive
+The type command causes the programmer to copy its type name +string (Wisp628) +to its data buffer, from which it can be retrieved by next commands. +

+ +

+ + + + +
command  version
formatv
statesactive
+The query command causes the programmer to copy its version string +to its data buffer, from which it can be retrieved by next commands. +

+ +

+ + + + +
command  write
formata..fw
statesactive
+A write command causes the programmer to +write the value a..f (interpreted as hexadecimal nibbles) +to the current location in the target. +A write command requires a previous program command. +

+The number of bytes written depends on the programming algorithm and the memory area. +EEPROM data memory is always written one byte at a time. +Algorithms 1 and 2 write program and configuration memory 14 bits at a time. +Algorithm 3 writes configuration memory byte wise, +but writes program memory 8 bytes at a time. +

+For algorithms 1 and 2 the current location is not affected by a write +command. For algorithm 3 the current location is incremented by the amount of data written.

+ + + +
+ +

examples

+ +Below a typical program - run sequence is shown. +Note that only the data sent by the host is shown (in bold). + + + +

+

http://www.voti.nl/wisp628/protocol.html +
+Copyright (c) 2002 Van Ooijen Technische Informatica / Wouter van Ooijen +
+Permission is granted to copy, distribute and/or modify this +document under the terms of the GNU Free Documentation License, +Version 1.1 or any later version published by the Free Software +Foundation; with no Invariant Sections, no Front-Cover Texts and +no Back-Cover Texts. A local copy of version 1.1 of the license can be found +here. +

+ + }