You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

222 lines
4.0 KiB

3 years ago
  1. 14 bit registers
  2. extra bits at end are ignored
  3. data sheet for mxp4725 page 25 is good example
  4. you send something like
  5. 4 bytes
  6. first is address byte
  7. which is found via
  8. (defun scn ()
  9. (dotimes (p 127)
  10. (with-i2c (str p)
  11. (when str (print p)))))
  12. then
  13. run
  14. (scn)
  15. in ulisp
  16. three bytes will be as in page 25
  17. 8 bit bytes
  18. as in ulisp i2c page:
  19. //
  20. Writing to a slave
  21. For example, to write the three bytes 0, 1, and 2 to a slave device with address #x70 you would use:
  22. (with-i2c (str #x70)
  23. (write-byte 0 str)
  24. (write-byte 1 str)
  25. (write-byte 2 str))
  26. //
  27. so as a test
  28. i want to write
  29. 0b01000000
  30. first byte
  31. second byte will be
  32. 0-4096
  33. divided across
  34. two bytes with last 4 bits being blank
  35. so just play around.
  36. 0b11110000
  37. 0b11110000
  38. two bytes of that
  39. and see what outputs.
  40. can we output binary direct into i2c in ulisp? or do we need
  41. decimal?
  42. so basic test:
  43. (with-i2c (str #x96)
  44. (write-byte #b01000000 str)
  45. (write-byte #b11110000 str)
  46. (write-byte #b11110000 str))
  47. that doesn't work
  48. (with-i2c (str #x96)
  49. (write-byte 0b01000000 str)
  50. (write-byte 0b11110000 str)
  51. (write-byte 0b11110000 str))
  52. error: no room for long symbols
  53. in that case
  54. (with-i2c (str #x96)
  55. (write-byte 64 str)
  56. (write-byte 192 str)
  57. (write-byte 192 str))
  58. note: 192 == 11000000
  59. sorry
  60. needs to be in function
  61. (defun go ()
  62. (with-i2c (str #x96)
  63. (write-byte #x40 str)
  64. (write-byte #xc0 str)
  65. (write-byte #xc0 str)))
  66. still getting
  67. 256> (go)
  68. @⸮⸮
  69. nil
  70. doesnt' seem to send the bytes i want...
  71. EDIT: the address bit is
  72. decimal 96, not hex 96. got this in 5-10 minutes.
  73. ok
  74. (defun go2 ()
  75. (with-i2c (str 96)
  76. (write-byte #x40 str)
  77. (write-byte #xc0 str)
  78. (write-byte #xc0 str)))
  79. 256> (defun go2 () (with-i2c (str 96) (write-byte #x40 str) (write-byte #xc0 str) (write-byte #xc0 str)))
  80. go2
  81. 229> (go2)
  82. nil
  83. so, nil. no response from mcp, but
  84. now output is 4 volts. success.
  85. that's pretty much it for a test. now just to clarify the numbers I need to
  86. get 0-1V and also to get 1v on output when it starts up (via eeprom)
  87. let's play first.
  88. (defun go2 ()
  89. (with-i2c (str 96)
  90. (write-byte #x40 str)
  91. (write-byte #x00 str)
  92. (write-byte #xA0 str)))
  93. redefining functions, saves on memory
  94. (defun go2 ()
  95. (with-i2c (str 96)
  96. (write-byte #x40 str)
  97. (write-byte #x0F str)
  98. (write-byte #xF0 str)))
  99. about 500mV
  100. (defun go2 ()
  101. (with-i2c (str 96)
  102. (write-byte #x40 str)
  103. (write-byte #xFF str)
  104. (write-byte #xF0 str)))
  105. max at 5v
  106. (defun go2 ()
  107. (with-i2c (str 96)
  108. (write-byte #x40 str)
  109. (write-byte #xFF str)
  110. (write-byte #x00 str)))
  111. still max
  112. (defun go2 ()
  113. (with-i2c (str 96)
  114. (write-byte #x40 str)
  115. (write-byte #x4F str)
  116. (write-byte #x00 str)))
  117. 1.75V
  118. pretty much that last byte is useless. small amounts of resolution
  119. in this application
  120. so let's focus on byte 2
  121. (defun go2 ()
  122. (with-i2c (str 96)
  123. (write-byte #x40 str)
  124. (write-byte 200 str)
  125. (write-byte #x00 str)))
  126. 4volts
  127. I need a printout of hex to byte for 0-F on my wall...
  128. but instead, lets use decimal. easier here.
  129. (defun go2 ()
  130. (with-i2c (str 96)
  131. (write-byte #x40 str)
  132. (write-byte 100 str)
  133. (write-byte #x00 str)))
  134. 2.05volts
  135. 1.05 volts for 50
  136. since 50 is roughly 1/5 of 255... 1/5 of VDD
  137. so i want my cpu load converted from whatever it is, to a number
  138. from 0-1, then take 0-1 of 48 or so.
  139. if you send this:
  140. (defun go2 () (with-i2c (str 96) (write-byte #x40 str) (write-byte 48 str) (write-byte #x00 str))) (go2)
  141. as one line, you can see it change instantly. (not using variables yet)
  142. so 47 is 1 volt. that will be 100%
  143. 0 will be 0.
  144. basically done.
  145. now to write 0 to eeprom
  146. (defun go2 ()
  147. (with-i2c (str 96)
  148. (write-byte #x60 str)
  149. (write-byte 0 str)
  150. (write-byte 0 str)))
  151. let's restart and make sure its at 0.
  152. otherwise my dial will break
  153. looks good. EDIT: well it's at 200mV, but good enough for now.
  154. don't care really, as long as its lthan 1v.
  155. let's write again. wrote to ram. works. restarted, and value is at 200mv.
  156. OK. all set. Now to build and deploy.