0:09
hello and welcome to controllers Tech
0:12
this is the fifth video in the ESB 32
0:15
series using the espressive ID and today
0:18
we will cover the SBI peripheral we have
0:21
already covered the uart and i2c
0:24
peripherals of the es32 so this video
0:27
will start the SBI peripheral we will
0:30
cover the basic functioning of the SBI
0:32
peripheral in a three-part video series
0:35
today in part one of the series we will
0:37
see how to configure the SBI peripheral
0:40
and how to transmit the data to the
0:42
slave device although I am not going to
0:45
connect any slave device in today's
0:47
video instead we will use the scope to
0:49
see the data transmitted by the es32
0:52
master let's start the espressive ID and
0:57
project we will use one of the templates
1:01
project look for the SBI templates here
1:06
let's use this SBI slave send a project
1:09
this is a simple project therefore I am
1:11
using this one let's rename the project
1:15
to SBI 1 make sure that the correct
1:20
selected all right the project has been
1:23
created and here we have the main file
1:27
we will modify this entire file but
1:31
first let's delete this commented
1:34
part this project uses some kind of
1:37
handshake between master and slave
1:40
devices we don't need to use any
1:42
handshake therefore let's delete this
1:45
part next we need to define the SBI
1:49
pins I am using the 38 pin es vom 32
1:53
board which you can purchase from
1:57
store here you can see the pinout of the
1:59
this board there are multiple instances
2:03
of the SBI peripheral available here we
2:06
can either use the vbi or the
2:10
hsbi you can see the pin assignments for
2:15
instances I am going to use the vbi
2:18
therefore the pins must be defined
2:21
accordingly the mossy pin is 23 miso is
2:24
19 clock is 18 and slave select is pin
2:28
five these are configur for the pin
2:33
diagram the code is using the hsbi host
2:37
so let's change it to vbi host we will
2:40
Define the SBI host for this
2:43
project we are not receiving any data so
2:46
let's remove this part again we have the
2:50
code related to the handshake so let's
2:52
delete this part to we will Define a
2:56
separate function to initialize the
2:58
SBI here we have the code for
3:03
peripheral let's remove this handshake
3:06
related part again here we have separate
3:09
configurations for configuring the SBI
3:12
device and for configuring the SBI
3:14
Bus Let's copy these configurations in
3:17
the initialization function we just
3:20
defined we will need the SBI device
3:23
handle in other functions as well so
3:27
globally let's define it as sp sp
3:30
handle all right inside the SBI
3:33
initialization function we will first
3:37
bus here we need to define the sossi
3:43
pins the quad pins are used in case of
3:46
quad SBI mode therefore they are defined
3:48
as minus one as we are not using the
3:52
SBI next we have the configuration for
3:56
device the command bits address bits and
4:00
dummy bits are kept to zero for now we
4:02
will use them when required today we
4:05
will only focus on transmitting data
4:08
therefore we do not need to worry about
4:10
them the SBI clock is set at 5
4:14
mahz we don't need a high-speed clock
4:16
for testing so let's change it to 2
4:19
mahz the duty cycle value is set to
4:23
128 which is actually 50% duty cycle the
4:27
SBI is configured with modes zero so
4:30
both clock phase and clock polarity are
4:33
low then we need to declare the chip
4:36
select pin the next parameter is used to
4:39
keep the Cs pin low after the SBI
4:42
transaction we don't need it so let's
4:45
delete it for now finally we have the Q
4:48
size which is the amount of transactions
4:50
that can be in the que at the same time
4:54
let's leave it to three you can find
4:56
more details about these structures in
4:59
the SBI Master header file keep holding
5:02
the control button and click on the
5:04
structure here you can see the details
5:07
about all the members of the device
5:09
interface configuration structure we can
5:12
also use the callback for the SBI but it
5:15
is used in combination with the
5:17
interrupt today we will use a simple
5:20
method to get the SBI working so no call
5:23
back is being used so far we have only
5:26
defined the parameters for the
5:28
configurations we haven't configured the
5:30
SBI yet let's delete this handshake part
5:35
here are the functions to configure the
5:37
SBI bus and to add the SBI device let's
5:41
copy them inside our initialization
5:44
function the first function is used to
5:47
initialize the SBI bus let's change this
5:50
host ID to SBI host the second parameter
5:54
of this function is the configuration
5:57
for the SBI bus then the the last
6:00
parameter is used to select the dma
6:02
channel which we want to use for the SBI
6:05
we are leaving this selection to Auto
6:08
therefore the driver will select it
6:10
automatically the next function adds the
6:13
device to the SBI bus the first
6:16
parameter is the host ID then we have
6:18
the device configuration itself and the
6:21
last parameter is the device handle we
6:24
have declared the device handle as SBI
6:27
handle all right that is all we need to
6:30
initialize the SBI driver next we will
6:33
write a new function to transmit the
6:35
data to the slave device the parameters
6:38
of this function will be pointer to the
6:41
data buffer that we want to transmit and
6:43
the number of bytes to be
6:45
transmitted this example uses the
6:47
function SBI device transmit to send the
6:50
data so we will use the same function to
6:53
do so this function actually adds the
6:56
SBI transaction to the que and then
6:58
waits for the transaction action to
7:00
complete we can also use other functions
7:03
like SBI device polling transmit to
7:06
transmit the data in the polling mode I
7:09
am using the SBI device transmit
7:11
function to do the same let's copy this
7:14
transaction definition inside our
7:17
function the spbi transaction structure
7:20
contains all the information about the
7:22
data being sent or received on the SBI
7:24
bus you can find more details about the
7:27
members of this structure in the bi
7:30
Master header file the first member of
7:32
the transaction is the flags different
7:36
types of flags are defined just above
7:38
this structure you can even combine two
7:41
or more Flags by performing the or
7:44
operation we will discuss the command
7:46
and address parameters in the upcoming
7:49
tutorials the length parameter holds the
7:52
total length in bits this length
7:55
includes the length of the data to be
7:56
transmitted and the data to be received
7:59
as well but remember that this parameter
8:02
is in bits not bytes the RX length
8:06
parameter holds the amount of data to be
8:08
received if this parameter is set to
8:11
zero in full duplex mode its value will
8:14
be the same as the length parameter next
8:17
we have the pointer to the buffer which
8:19
we want to transmit we can also use the
8:22
TX data array to store the data to be
8:25
transmitted but this array is only used
8:27
when the SBI trans use TX data flag is
8:31
flags similarly we can either use the
8:34
pointer to the RX buffer to store the
8:36
received data or use the RX data array
8:39
in combination with the SBI trans use RX
8:42
data flag the problem with these RX data
8:46
and TX data arrays is that they can only
8:48
store four bytes of data at
8:50
once I am going to use the buffers
8:53
instead as they are easier to
8:56
use all right let's populate the SBI
8:59
trans transaction structure the pointer
9:02
to the transmit buffer is the pointer to
9:04
the data parameter of the function we
9:07
already have the length in the functions
9:09
parameter so let's just convert it to
9:12
bits note that I am not setting any
9:15
other member of the structure so they
9:18
zero now we will call the function SBI
9:21
device transmit to send the
9:24
transaction the handle is SBI handle and
9:27
the transaction structure is different
9:29
find above we need to pass the address
9:32
of the structure here if this function
9:35
returns any error we will print an error
9:39
console that is all we need for
9:41
transmitting the data on the SBI
9:44
bus let's delete everything from the
9:48
function we will now Define a new data
9:51
array to store the data to be
9:53
transmitted let's store four bytes of
9:56
random data in it inside the main
9:59
function we will call the SBI in it to
10:03
driver now inside the while loop call
10:06
the function SBI transmit to transmit
10:09
the data array we just
10:11
defined let's give a delay of 2 seconds
10:14
between each call to this
10:16
function include the uni standard header
10:19
file to access the sleep
10:21
function since we are not using R to
10:25
Let's remove these inclusions from here
10:28
all right let's build the project
10:33
once the SPI host is already declared in
10:36
the system file somewhere so we need to
10:39
change the name here let's rename it to
10:42
ESP host we also need to change the host
10:46
ID inside the initialization
10:49
functions all right the project builds
10:51
fine now I am going to use a logic
10:55
analyzer to capture the SBI
10:58
signals here here we need to configure
11:00
the SBI in the analyzer to the slave
11:04
select pin is connected to Channel Zero
11:06
clock is connected to channel 1 and the
11:08
mossi is connected to Channel 2 we are
11:12
using the most significant bit first
11:14
there are eight bits per transfer and
11:21
zero before flashing the project to the
11:24
board make sure the correct Target and
11:26
serial Port is selected or right let's
11:29
Flash the project to the board
11:35
now we can check the print output in the
11:38
terminal we did not get this writing
11:40
error that means the code must be
11:42
working fine let's write a new log after
11:45
transmitting the data this is just to
11:48
make sure the data was sent without any
11:50
issue all right let's Flash the project
11:57
again you can see the successful log is
11:59
printing on the terminal every 2
12:02
seconds this means that the data was
12:05
successfully let's check the data on the
12:10
analyzer here you can see the chip
12:12
select pin goes low before the
12:16
Begins the SBI clock is 2 mahz this is
12:20
exactly what we set it at then the mossy
12:23
line shows the four datab bytes
12:25
transmitted by the ESB
12:27
32 this is the same data which we
12:30
defined in the data array so the es32 as
12:34
Master is able to transmit the data via
12:37
SBI let's send some string now here I am
12:42
defining a character pointer which
12:44
points to the string to be transmitted
12:47
the SBI transmit function takes another
12:49
data type so we need to typ cast the
12:52
character pointer to the unsigned
12:54
integer pointer the number of bytes can
12:57
be calculated using the string length
13:00
function that is it let's build and
13:02
Flash the project to the board
13:07
again we are receiving data every 2
13:14
analyzer let me change the type to asky
13:17
here you can see the exact same string
13:20
is intercepted by the analyzer so the
13:23
SBI transmission works fine you can use
13:26
the SBI transmit function to transmit
13:29
any amount of data to the slave device
13:32
we will cover how to read the data back
13:34
from the slave device in the next two
13:36
parts of this series I am going to use
13:39
the w25 Q flashmemory as the slave
13:42
device and we will see how to write the
13:45
data into this memory device and how to
13:47
read the data back from it this is it
13:51
today you can download the code from the
13:55
description leave comments in case of
13:59
keep watching and have a nice day ahead