|
发表于 2020-3-26 12:26:24
|
显示全部楼层
搜了下相关讨论,这个比较全面:
The easiest way to get the right timing for 1wire is to use a UART. If you set the baud just right, you can use 0x01 (or 0x80 depending on endian) and 0xff for short and long pulses, and set it up for half duplex so you can read the byte back to see if the device held a '1' for you. A single schottky diode from TxD to the 1wire bus should be sufficient, plus the pull-up.
Otherwise, you have a few choices...
* Use a separate 1wire driver chip that talks SPI or I2C and hook it up to the existing busses.
* Disable interrupts and use a fixed timing loop for each pulse.
* Use a separate timer and do all the 1wire logic in its interrupt handler (i.e. outside the realm of the RTOS tasks)
* Use a separate chip like an R8C just to do the timing.
My furnace controller uses an R8C for each zone, and those R8Cs use a timer/interrupt to do the 1wire timing. The 1wire search/scan logic is done in the main loop, and the results are passed back to the main MCU via I2c. |
|