Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

RS485HID.md 3.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. USB Keyboard over RS-485
  2. ========================
  3. The project is to have a device that appears to a computer as a USB
  4. keyboard, but it receives it's key presses from another computer via an
  5. RS-485 multidrop bus. It will use the Syote library for communications,
  6. and as there can be multiple devices on the bus, a single gateway
  7. controller can service multiple such keyboards, making it a nice option
  8. for an IPMI like solution. It is also expected that GPIOs of the device
  9. can be used to control the power switches, along with observing various
  10. LEDs. As most microcontrollers have an ADC, it could theoretically
  11. support beeps from the PC speaker.
  12. Devices
  13. -------
  14. These are the device that are under conideration for the project:
  15. ### STM32F103C8
  16. 64KB flash, but the devices I have seem to have 128KB flash. They
  17. appear to be BluePill clones. Green LED is GPIOC Pin 13.
  18. Currently looking at USART3, B0 for DE, B1 for RE.
  19. TIM2_CH4 can be mapped to PB11 (UART3 RX). This is to do break detection.
  20. Table 45 says TIM2_REMAP, either full or partial (value 1x).
  21. Table 5 pin definitions of stm32f103c8.pdf
  22. (all can be remapped)
  23. USART has idle line detction
  24. USART1_TX PA9 5v tollerant
  25. USART1_RX PA10 5v tollerant
  26. USART2_TX PA2 NOT 5v tollerant
  27. USART2_RX PA3 NOT 5v tollerant
  28. USART3_TX PB10 5v tollerant
  29. USART3_RX PB11 5v tollerant
  30. flash: 0/x
  31. boot loader (an2606) pattern 1: 1/0
  32. embedded sram: 1/1
  33. top jumper BOOT0/44
  34. bottom jumper BOOT1/PB2/20
  35. ### MAX485
  36. This requires a 5V VCC. There is a 3.3V part called the MAX3485, but
  37. as often micros can be 5V tollerant, and the MAX485 is fine w/ logic
  38. levels down to 2V, this should be fine.
  39. D - Driver
  40. DE Driver enable (high enable)
  41. DI Driver input
  42. R - Receiver
  43. RO Receiver output
  44. /RE Receiver enable (low enable)
  45. Note: Some pre-assembled devices have pull up resistors on the DE/RE
  46. lines. This is a BAD design as it means that it will be driving the
  47. bus by default. This can often be fixed by removing the pull-up
  48. resistors.
  49. Programming
  50. -----------
  51. Command to program the HID device:
  52. ```
  53. sudo openocd -f interface/ftdi/digilent-hs1.cfg -f interface/ftdi/swd-resistor-hack.cfg -f target/stm32f1x.cfg -c "init" -c "reset init" -c "program build/rs485hid.elf verify reset exit"
  54. ```
  55. Keying
  56. ------
  57. There are two keys involved, the initiator key, which is made w/ the
  58. Makefile, by issuing the command:
  59. ```
  60. bmake hid_priv_key
  61. ```
  62. Which creates the private key in the file `.hid_priv_key`. This is
  63. needed for the build process.
  64. The other key is the device key, which is generated by the USB HID
  65. device at first start. The device will "type" the hex encoded public
  66. key when the A7 pin is grounded. This public key should be saved to
  67. a file, which can then be passed to the `lora.py` initiator program
  68. via the `-p` argument.
  69. Low level info
  70. --------------
  71. Definitions:
  72. Mark: logic 1, B > A
  73. Space: logic 0, B < A
  74. Idle state: Mark
  75. Async comms: Space | 8 bits LSB, 0 through 7 | Mark
  76. As the start of the sequence begins w/ a space, it requires that the
  77. line be "idle" (aka mark) before things start, so any non-mark state
  78. before TX starts should consider the line as busy, and not be ready
  79. to transmit. Additional info on this is in the Wiring section.
  80. Wiring
  81. ------
  82. For long runs, it is recommend to have terminating resistors w/ a value
  83. of 120 Ω, the impedence of twisted pair, to prevent reflections.
  84. Wikipedia recommends to add biasing resistors to help w/ noise
  85. immunity, BUT, care must be done when using them. When the bus is
  86. idle, make sure that the receivers are outputing a hi value (aka
  87. mark), that is 5V if you're using a MAX485 converter. If it is 0V,
  88. then the receiver will not work. I have seen in some cases where
  89. grounding A w/ a 2.2k Ω resistor makes things work.