14 bit registers
|
|
|
|
extra bits at end are ignored
|
|
|
|
data sheet for mxp4725 page 25 is good example
|
|
|
|
you send something like
|
|
4 bytes
|
|
first is address byte
|
|
which is found via
|
|
(defun scn ()
|
|
(dotimes (p 127)
|
|
(with-i2c (str p)
|
|
(when str (print p)))))
|
|
then
|
|
run
|
|
(scn)
|
|
in ulisp
|
|
|
|
three bytes will be as in page 25
|
|
|
|
8 bit bytes
|
|
|
|
as in ulisp i2c page:
|
|
|
|
//
|
|
Writing to a slave
|
|
For example, to write the three bytes 0, 1, and 2 to a slave device with address #x70 you would use:
|
|
|
|
(with-i2c (str #x70)
|
|
(write-byte 0 str)
|
|
(write-byte 1 str)
|
|
(write-byte 2 str))
|
|
|
|
//
|
|
|
|
so as a test
|
|
i want to write
|
|
0b01000000
|
|
first byte
|
|
second byte will be
|
|
0-4096
|
|
divided across
|
|
two bytes with last 4 bits being blank
|
|
|
|
so just play around.
|
|
0b11110000
|
|
0b11110000
|
|
two bytes of that
|
|
|
|
and see what outputs.
|
|
|
|
can we output binary direct into i2c in ulisp? or do we need
|
|
decimal?
|
|
|
|
so basic test:
|
|
(with-i2c (str #x96)
|
|
(write-byte #b01000000 str)
|
|
(write-byte #b11110000 str)
|
|
(write-byte #b11110000 str))
|
|
that doesn't work
|
|
(with-i2c (str #x96)
|
|
(write-byte 0b01000000 str)
|
|
(write-byte 0b11110000 str)
|
|
(write-byte 0b11110000 str))
|
|
error: no room for long symbols
|
|
|
|
in that case
|
|
(with-i2c (str #x96)
|
|
(write-byte 64 str)
|
|
(write-byte 192 str)
|
|
(write-byte 192 str))
|
|
|
|
note: 192 == 11000000
|
|
|
|
sorry
|
|
|
|
needs to be in function
|
|
|
|
(defun go ()
|
|
(with-i2c (str #x96)
|
|
(write-byte #x40 str)
|
|
(write-byte #xc0 str)
|
|
(write-byte #xc0 str)))
|
|
|
|
still getting
|
|
256> (go)
|
|
|
|
@⸮⸮
|
|
|
|
nil
|
|
|
|
doesnt' seem to send the bytes i want...
|
|
|
|
EDIT: the address bit is
|
|
decimal 96, not hex 96. got this in 5-10 minutes.
|
|
|
|
ok
|
|
|
|
|
|
(defun go2 ()
|
|
(with-i2c (str 96)
|
|
(write-byte #x40 str)
|
|
(write-byte #xc0 str)
|
|
(write-byte #xc0 str)))
|
|
|
|
256> (defun go2 () (with-i2c (str 96) (write-byte #x40 str) (write-byte #xc0 str) (write-byte #xc0 str)))
|
|
|
|
go2
|
|
|
|
|
|
|
|
229> (go2)
|
|
|
|
nil
|
|
|
|
so, nil. no response from mcp, but
|
|
now output is 4 volts. success.
|
|
|
|
that's pretty much it for a test. now just to clarify the numbers I need to
|
|
get 0-1V and also to get 1v on output when it starts up (via eeprom)
|
|
|
|
let's play first.
|
|
|
|
(defun go2 ()
|
|
(with-i2c (str 96)
|
|
(write-byte #x40 str)
|
|
(write-byte #x00 str)
|
|
(write-byte #xA0 str)))
|
|
|
|
redefining functions, saves on memory
|
|
|
|
(defun go2 ()
|
|
(with-i2c (str 96)
|
|
(write-byte #x40 str)
|
|
(write-byte #x0F str)
|
|
(write-byte #xF0 str)))
|
|
about 500mV
|
|
|
|
(defun go2 ()
|
|
(with-i2c (str 96)
|
|
(write-byte #x40 str)
|
|
(write-byte #xFF str)
|
|
(write-byte #xF0 str)))
|
|
max at 5v
|
|
|
|
(defun go2 ()
|
|
(with-i2c (str 96)
|
|
(write-byte #x40 str)
|
|
(write-byte #xFF str)
|
|
(write-byte #x00 str)))
|
|
still max
|
|
|
|
(defun go2 ()
|
|
(with-i2c (str 96)
|
|
(write-byte #x40 str)
|
|
(write-byte #x4F str)
|
|
(write-byte #x00 str)))
|
|
|
|
1.75V
|
|
|
|
pretty much that last byte is useless. small amounts of resolution
|
|
in this application
|
|
|
|
so let's focus on byte 2
|
|
|
|
(defun go2 ()
|
|
(with-i2c (str 96)
|
|
(write-byte #x40 str)
|
|
(write-byte 200 str)
|
|
(write-byte #x00 str)))
|
|
4volts
|
|
|
|
I need a printout of hex to byte for 0-F on my wall...
|
|
but instead, lets use decimal. easier here.
|
|
|
|
|
|
(defun go2 ()
|
|
(with-i2c (str 96)
|
|
(write-byte #x40 str)
|
|
(write-byte 100 str)
|
|
(write-byte #x00 str)))
|
|
2.05volts
|
|
|
|
1.05 volts for 50
|
|
since 50 is roughly 1/5 of 255... 1/5 of VDD
|
|
|
|
so i want my cpu load converted from whatever it is, to a number
|
|
from 0-1, then take 0-1 of 48 or so.
|
|
|
|
if you send this:
|
|
|
|
(defun go2 () (with-i2c (str 96) (write-byte #x40 str) (write-byte 48 str) (write-byte #x00 str))) (go2)
|
|
as one line, you can see it change instantly. (not using variables yet)
|
|
|
|
so 47 is 1 volt. that will be 100%
|
|
|
|
0 will be 0.
|
|
|
|
basically done.
|
|
now to write 0 to eeprom
|
|
|
|
(defun go2 ()
|
|
(with-i2c (str 96)
|
|
(write-byte #x60 str)
|
|
(write-byte 0 str)
|
|
(write-byte 0 str)))
|
|
|
|
let's restart and make sure its at 0.
|
|
otherwise my dial will break
|
|
|
|
looks good. EDIT: well it's at 200mV, but good enough for now.
|
|
|
|
don't care really, as long as its lthan 1v.
|
|
|
|
let's write again. wrote to ram. works. restarted, and value is at 200mv.
|
|
|
|
OK. all set. Now to build and deploy.
|
|
|
|
|
|
|
|
|