0:09
hello and welcome to controllers tech
0:12
few months ago i made a video about
0:15
interfacing ds18b20 temperature sensor
0:20
some of you guys still couldn't make it
0:22
work due to some problems
0:25
this video will take a completely
0:26
different approach towards the same
0:28
sensor and also we will see how to use
0:31
multiple ds-18 v20 sensors using only
0:36
we will use the uart to do the
0:38
communication instead of the timer that
0:42
well i couldn't figure out the process
0:45
and therefore i am using a pre-existing
0:49
it's right here you can check it out if
0:52
you want to read the details
0:54
this library uses standard peripheral
0:57
driver and i have modified it to use the
1:01
i hope the author is okay with it
1:04
so today we will see how to use uart
1:06
using this library and interface
1:08
multiple ds18b20 sensors with the sdm 32
1:14
let's start with cube id and create a
1:19
i am using sdm 32 f103 controller
1:28
give some name to the project and click
1:35
first of all we will set up the clock
1:38
i am using external high speed crystal
1:43
the blue pill have 8 megahertz crystal
1:45
on board and i want to run the system at
1:47
maximum 72 megahertz clock
1:56
now go to the uart and enable the half
2:03
we will keep everything same here just
2:06
go to the nvic and enable the global
2:11
you can see the half duplex mode uses
2:13
single pin for communication
2:16
this is it for the setup click save to
2:23
before we go any further let's see the
2:27
you can see here the 2-d s-18 b-20 are
2:31
connected in a way that they're all 3
2:33
wires are attached to each other there
2:36
is a 5 kilo ohms resistor connected
2:38
between the signal wire and the v-c-c
2:42
i am going to provide the common 3.3
2:44
volts to both of them along with a
2:48
and the signal pin is connected to the
2:50
p-a-9 the u-r-t-x pin
2:54
this is it for the connection let's see
3:00
first of all we will copy the one-wire
3:02
library files into our project
3:12
now pay attention to the changes we need
3:16
open the one wire dot c file
3:19
change the uart instance that you are
3:23
i set up the uart one
3:29
now define the maximum number of devices
3:36
we need to define this in the 1 wire
3:41
make sure you make the changes at both
3:48
we also need to configure the interrupt
3:50
file that we will do in a while
3:54
all right now come to the main file and
3:57
include the one wire header file here
4:02
there is a float variable defined in the
4:07
this variable will store the temperature
4:09
values and this is why we need to define
4:12
the same in our main file also
4:15
but define it as the external variable
4:18
as it's already defined somewhere else
4:21
now in the main function we will call
4:23
the get wrong id function
4:26
this function will scan for all the
4:28
connected devices and sort them
4:30
according to their ids
4:34
now inside the while loop we will call
4:36
the get temperature function to read the
4:38
temperature from the connected sensors
4:41
these temperature values will be stored
4:43
in the variable we defined in the
4:46
you should give a delay of at least 1
4:48
second before reading it again
4:51
now the final thing we need to do is
4:54
modify the interrupt callback function
4:57
so go to the interrupt.c file
5:00
here we will first include the one wire
5:13
in the 1 wire header file there is a
5:15
function defined o w read handler
5:22
we will call this function in the uart
5:26
make sure you keep it in the user code 0
5:29
as it needs to be called before the
5:31
other interrupt handler
5:34
now let's build and debug the code
5:39
i have added the temperature array in
5:49
you can see here we are getting two
5:54
so both the sensors are working fine
6:00
now i am going to hold one of the
6:03
notice the change in the reading you can
6:06
see the temperature of the first sensor
6:08
is rising but the second one is
6:21
so here we have the 2 temperature
6:23
sensors connected on the same pin and
6:29
you can connect up to 64 sensors in this
6:33
there is one more thing i want to
6:39
the function get rom id is responsible
6:42
for scanning the connected devices
6:45
here this structure stores the
6:47
information about the device
6:49
let me show this in working
6:55
we hit the break point let's check the
6:59
here you can see the information about
7:02
this particular device
7:04
the 28 represents the type of device
7:07
this is defined in the header file
7:21
after this we have the rom id for this
7:24
if we run the code again this time we
7:27
have another device with different rom
7:30
this function sorts out the devices
7:32
based on their rom ids
7:35
the lower the id the lower the rank of
7:39
the temperature array shows the
7:41
temperature according to the rank
7:42
allotted by the rom id function
7:45
so basically if you want to fix the
7:48
sensors to show the temperature of some
7:50
particular things you either need to
7:52
know their rom ids or you can mark them
7:54
by first measuring the known
7:57
this is it for the video
8:00
i hope you understood the process
8:03
as i mentioned before try to use the use
8:06
art and not the uart for this tutorial
8:09
there are some registers involved in the
8:11
source code so i don't know if the uart
8:16
but i have tested it with different
8:18
controllers and it works pretty well
8:24
you can download the code from the link
8:29
leave comments in case of any doubt
8:32
keep watching and have a nice day ahead