1-Wire slave on MK. Part 1: Iron

    For one of the automation projects, it was necessary to make a device that is a 1-Wire slave device, receives commands from the master and sets the value of the analog signal at its outputs in the range from 0 to 10V.
    After analyzing the line of standard 1-Wire microcircuits from Maxim, it became clear that there is no microcircuit that will allow such functionality to be implemented.
    Therefore, it was decided to implement 1-Wire slave on the microcontroller. I hope this material will be interesting and useful to people who make a "smart home" with their own hands, because 1-Wire is a fairly popular bus in such projects. As a stone was chosen MK Cortex M0 + ATSAMD20G16from Atmel, but we'll talk about implementation in code in the second part. Running a little ahead, I’ll say that in the third part of the series we will talk about implementing our own family of devices for the OWFS (One Wire File System) Linux library . Today we’ll talk about some of the hardware solutions that we came to during the development process.

    It will mainly be about how to connect the leg of the microcontroller to the 1-Wire bus with minimal damage to health. We will move from simple to complex.

    Nothing to do

    The first problem you encounter when trying to assemble a 1-Wire device on a microcontroller with a Cortex core is the 3.3V microcontroller power level, while on the 1-Wire bus we have 5V. You can use the tolerance of the feet of the microcontroller to 5V and connect as is, directly to the bus. Unfortunately, the legs of the SAM D20 are not tolerant to 5 volts, therefore this option did not suit us, but it’s worth noting it, in fairness. Although, putting the external bus directly on the 3.3V stone foot is not a good idea. Firstly, there is a possibility of unstable operation of other devices on the bus with parasitic power, and secondly, on a long wire, you can "catch" the tip.

    Level conversion

    The simplest option is a bi-directional level converter on a transistor. For it, you need to take somewhere 5V from the side of the 1-Wire bus.
    The first option is to make 5V on your device (in addition to 3.3V) to “power” the bus. As a result, the complexity of circuitry.
    The second option is to lay the 1-Wire bus in three wires . The third wire is the + 5V power line. Of the problems - an extra wire, a voltage drop on a long wire.

    Level Matching

    If you really do not want to use + 5V, you can divide the signal line into 2 components (input and output)

    It is important to consider that with this scheme, the lines on the controller side are inverse.
    As a bonus, dividing the data line into 2 parts makes it somewhat easier to further debug software, as allows you to see the oscilloscope separately coming from us signals ( 1-Wire Tx line ), not mixed with the signals of other devices on the bus.

    Increase stability

    In order to make 1-Wire data reception more confident, it is necessary to make steep pulse edges from the side of the microcontroller. To do this, we use the comparator from TI LMV331 , which will provide a more accurate and sharp transition between the logical "0" and "1", as well as a hysteresis of 160mV. We will also replace the output BC547 bi-polar transistor with the field IRLML6346 and put the protective TVS diode ESD5Z6 at 6V.

    For this circuit, the comparator will need to be powered from 5V. Where can I get them was said above.

    Untied 1-Wire

    To ensure electrical isolation of the 1-Wire bus and the internal electronics of the device, we will use an isolated level translator ADuM1201 , and an isolated DC / DC converter TES 1-1211 . As in the previous case, divide the 1-Wire data line into 2 lines: 1W_Rx and 1W_Tx.

    A DC / DC converter with 12 to 5 volts is taken as an example, you can use a similar 3.3 / 5.

    The rest of the circuitry

    For completeness, we show the circuitry for connecting the microcontroller, as well as the output analog channels 0-10V.

    Because 1-Wire protocol requires a unique address for each device on the bus, on the board we put 1-Wire UID from Maxim DS2411 . As a bus master for her, we will read her UID and use it as her own address. DS2411 has a 0x01 family code (family code is the high byte of the UID). On the OWFS website, we will select an unoccupied family code for our new device and will replace the first byte.

    As already mentioned, in the second part we will proceed to the software implementation of the 1-Wire Slave protocol.

    Also popular now: