0:09
hello and welcome to controllers Tech
0:12
this is the sixth video in the esp32
0:15
series using the espressive ID and today
0:18
we will continue with the SBI peripheral
0:21
in the previous video we saw how to
0:23
configure the SBI peripheral and how to
0:26
transmit any amount of data to the slave
0:28
device we will now start reading the
0:31
data from the slave device in this video
0:34
we will see how to connect the w25 Q
0:37
flash device with the ESB 32 and how to
0:41
read the ID of the device I will also
0:44
make one more video where we will write
0:46
some data into the device and then read
0:49
the same data back from it here is the
0:52
picture showing the connection between
0:54
ESB 32 and the w25 Q slave device the
0:59
device is powered by 3.3 volts from the
1:02
ESB 32 itself the Cs pin of the device
1:06
is connected to the GP i05 the data out
1:09
is connected to the Miso that is pin 19
1:13
data in is connected to the mossi that
1:15
is pin 23 and the clock is connected to
1:17
the clock which is pin 18 on the
1:20
MCU here is the reference Manual of the
1:24
w25 Q32 which is a 4 mgab flash memory
1:29
note that these videos do not cover the
1:31
w25 Q flash memories in detail rather we
1:35
are only focusing on the SBI part to
1:38
write and read data from it I will make
1:41
a separate series covering the
1:43
interfacing of w25 Q flash with the sb32
1:47
in depth let's check the requirement for
1:50
the SBI peripheral first the device
1:54
supports SBI mode 0 and mode 3 so make
1:57
sure you configure the master in either
2:00
modes let's scroll down to the
2:04
section here you can see the device ID
2:08
which we want to read from the memory
2:10
device the device ID is 24 bits in size
2:14
the higher 8 Bits represents the winbond
2:17
serial flash that is EFX whereas the
2:20
lower 16 bits represents the memory type
2:23
size the 416 hex will be returned in
2:27
case of w25 Q32 chip so we should get a
2:34
f416 hex when we read the ID
2:38
register this is the ID register 9fx
2:42
which Returns the 24-bit device
2:45
ID let's scroll down to this
2:48
register here you can see the details
2:53
register we need to send the instruction
2:58
device in return the device will
3:00
transmit 24 bits containing the
3:02
manufacturer ID memory type ID and the
3:07
ID here I have the project which we
3:10
created in the previous
3:12
video I am creating a new project for
3:15
this video but I will modify the code
3:19
itself let's call the project SBI
3:23
2 here I am replacing the generated main
3:26
file with the one from the previous
3:30
let's build the project once we will
3:33
write a new function to receive the data
3:37
device the parameters of this function
3:39
will be the address inside the slave
3:42
device where we want to read the data
3:44
from pointer to the buffer where the
3:46
received data will be stored and the
3:48
number of bytes we want to read the
3:51
reception works in the similar way as
3:53
transmission the master will send the
3:56
transaction on the SBI bus on receiving
3:58
the appropriate command and the slave
4:00
device will respond to this
4:03
transaction here we will store the
4:05
address parameter to the TX buffer
4:07
member of the transaction
4:09
structure this is the only data we need
4:13
transmit the member RX buffer is the
4:16
pointer to the buffer where the received
4:19
stored as I mentioned in the previous
4:22
video the length is basically the total
4:24
length which includes the data to be
4:26
transmitted and the data to be received
4:30
we already have the number of data byes
4:32
to be received in addition to this we
4:34
also need to transmit the address bite
4:38
slave therefore the length will be one
4:40
bite higher than the amount of data we
4:43
receive also the length should be in
4:47
bits now we will call the function SBI
4:50
device transmit to transmit the address
4:54
device we are using the full duplex mode
4:57
therefore the data sent by the slave
4:59
device will be automatically received by
5:03
32 now print the received data on the
5:06
terminal console one bite at a time we
5:10
will write the main function now but
5:13
before that let's define the address
5:15
variable where we will store the address
5:17
of device ID register that is 9
5:20
fhx also Define an array to store the
5:24
received data let's make it store 10
5:27
bytes data and we will print 5 data
5:30
bytes from the RX data
5:32
array this is just to demonstrate the
5:36
total inside the main function call the
5:39
function SBI received to read the data
5:43
slave the data will be stored in the RX
5:46
data array and we will read only three
5:50
slave this is because the slave device
5:55
size let's build and Flash the project
6:00
here you can see the received data is
6:04
console let me fix the data Arrangement
6:07
first there should be a tab here instead
6:10
of the new line all right let's see the
6:14
received data again we are printing five
6:17
data bytes on the console and you can
6:20
see them here we have only programmed
6:23
the master to receive three data bytes
6:25
from the slave and you can see the
6:27
actual data here in the middle
6:30
the last bite is zero which is as
6:32
expected because the master did not
6:34
receive anything at that position but
6:39
noticeable FFX was unexpected I wanted
6:42
the data to start from the first
6:44
position itself but instead it is
6:46
starting from the second
6:48
position basically the
6:50
es32 received four bytes in total the
6:53
first bite is FFX and the next three
6:56
bytes is the ID data sent by the slave
7:00
let's understand this on the analyzer
7:03
since we are also reading the data we
7:06
need to add the Miso line to the scope
7:08
as well all right let's capture the
7:14
data here we have the complete
7:17
transaction we are using the SBI in full
7:20
duplex mode therefore the esp32 will
7:23
also receive data while it is
7:25
transmitting the first bike transmitted
7:28
by the ES3 2 is the address bite 9
7:32
FX while this data was being transmitted
7:34
on the mossy line the Miso line was
7:37
being read by the ESB
7:39
32 there was no data on the Miso line
7:42
but it was pulled and kept High
7:45
therefore the esp32 interpreted it as
7:49
FFX the next three bytes are the actual
7:52
data bytes sent by the slave device note
7:56
here that the es32 keeps transmitting
7:59
some random things on the mossy line
8:01
while it is reading the data from the
8:03
Miso line so if we send four bytes of
8:06
addressed data to the slave device the
8:09
es32 will read four bytes of useless
8:12
data on the Miso line we can still
8:15
manage the received data where we can
8:17
simply start reading the data from the
8:19
specified position instead of reading it
8:21
from the beginning of the buffer but
8:24
there is another feature in the library
8:26
a better one which we can use to avoid
8:29
the b32 from reading the Miso line when
8:34
transmitted along with the SBI
8:36
transaction structure there is another
8:40
structure inside this structure we can
8:43
assign the custom values for the command
8:47
bits remember that I have configured all
8:50
these bits to zero in the main SBI
8:54
configuration now for example if this
8:56
particular transaction requires the
8:58
transmission of the address we can
9:00
configure the address bits here for this
9:03
transaction the base member of this
9:05
structure should point to the actual
9:07
transaction that is SBI transaction
9:10
structure where the rest of the data is
9:13
declared when using this external
9:15
transaction we need to set the flag for
9:17
the variable command address in the main
9:21
transaction there is no common flag for
9:23
both so you can set them individually by
9:27
operation I just need to set the address
9:30
so I will use this variable address flag
9:34
let's define a new external transaction
9:37
structure here we just need to define
9:40
the member address bits of this external
9:43
transaction so how many address bits can
9:46
there be let's see the transaction
9:49
structure once again here we have the
9:52
address member of this structure which
9:56
variable so we can have a maximum of 6
9:59
64-bit address inside the slave
10:02
device it does not mean that we need to
10:04
send 64 bits every time therefore the
10:07
address bits in the external transaction
10:09
structure control how many address bits
10:11
are being sent in a particular
10:13
transaction the 64 bits for the address
10:16
is more than enough the w25 Q flash
10:19
memory we are using has 24 bits
10:22
addresses for the specific memory
10:24
location there is some modification in
10:27
how the address used to be written in
10:29
previous versions so make sure you read
10:32
this properly I have the latest version
10:35
of the ID that is version three so I
10:38
will follow the new method of writing
10:40
address let's change the address
10:43
variable type to unsign
10:46
64bit I am also defining a new variable
10:49
to identify the number of address byes
10:52
transmit the length should not include
10:54
the address length only the number of
10:56
data bytes to be read should come here
11:00
the address length will be managed by
11:01
the address bits in the external
11:04
transaction I will update the
11:07
article since we are using the address
11:09
bits now let's store the address in the
11:12
address parameter of the transaction
11:14
structure now comes the address
11:17
bits this parameter depends on how many
11:22
transferring we also need to update the
11:27
structure the base is the pointer to the
11:29
actual SBI transaction structure so
11:32
let's pass the pointer here now the
11:35
external transaction had all the data
11:38
from the actual transaction along with
11:40
the address bits as well we will pass
11:43
this external transaction to the device
11:45
transmit function but the parameter SBI
11:48
transaction is only accepted here so typ
11:52
cast the external transaction to the SBI
11:54
transaction and pass the
11:57
structure inside the while loop we are
11:59
reading the ID every 2
12:02
seconds we also need to pass the
12:06
length the address is only one bite long
12:09
so pass one here all right that is all
12:13
let's build and Flash the project to the
12:16
board let me connect the console again
12:20
here you can see now we are receiving
12:22
the data at the beginning of the RX data
12:25
array the first three bytes are the ID
12:30
device let's check the transmission on
12:36
analyzer here we still have the same
12:41
previously during the time when the
12:43
address is being transmitted the Miso
12:46
line is still high but the es32 does not
12:49
read it we have configured the address
12:52
bits to 8 therefore the master does not
12:54
read any data while these eight bits are
12:57
transmitted other than one address bite
13:00
you can see the master transmitted four
13:02
more bytes so as to read the data from
13:06
slave actually it should have only
13:08
transmitted three additional bytes since
13:10
we want to read three bytes from the
13:13
device because I have added the address
13:16
bite in the length parameter the master
13:18
thinks there are four bytes that need to
13:20
be handled therefore I said the address
13:23
bite should not be added to the length
13:25
as the address bits already handl it you
13:28
can find the this update in the project
13:30
you will download and in the article as
13:33
well we will continue this series in the
13:36
next video also we will see how to write
13:39
and read data from this flash memory in
13:42
the simplest way possible this is it for
13:45
the video you can download the project
13:48
from the link in the
13:50
description leave comments in case of
13:52
any doubt keep watching and have a nice