For an I2C scanner I wanted to realize the output of the addresses as hexadecimal values. For this I oriented myself on David’s examples and wrote this solution:
(defun pc (i) (princ (code-char (+ i (if (<= i 9) 48 55)))))
(defun pb (i)
(pc (ash i -4))
(pc (logand i 15))
)
(defun scn ()
(dotimes (p 127)
(with-i2c (str p)
(if (not str) (princ ". ")
(progn (princ "0x") (princ (pb p)))
))))
The output looks like this:
7900> (scn)
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . 0x388 . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . .
nil
Although address 56 (decimal) is correctly converted to 0x38, an additional 8 is appended. This comes from the return value of the function.
In the reference I found the symbol “nothing”, which I wanted to use to prevent the additional output:
(defun pb (i)
(pc (ash i -4))
(pc (logand i 15))
(nothing)
)
The result is a ESP core crash:
7897> (scn)
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . 0x38
Error: 'Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
Any idea what could be causing ESP to crash here? Is it the right strategy to use the noting symbol here?