How to Write Basic Library for NRF24L01 PART2 || Transmit DATA || SPI STM32
0 views
May 3, 2021
Purchase the Products shown in this video from :: https://controllerstech.store ________________________________________________________________________________________ This is PART2 of the video and it covers How to transmit DATA. To see the PART 1, click :::: https://youtu.be/mB7LsiscM78 To see the PART 3, click :::: https://youtu.be/X5XDSWQYYvU STM32 Playlist :::: https://www.youtube.com/playlist?list=PLfIJKC1ud8gga7xeUUJ-bRUbeChfTOOBd DOWNLOAD THIS PROJECT FROM :::: https://github.com/controllerstech/NRF24L01 ________________________________________________________________________________________ ******* SUPPORT US BY DONATING****** https://paypal.me/controllertech *******Join the Membership*******
View Video Transcript
0:02
[Music]
0:09
hello everyone
0:11
welcome to controllers tech this is
0:14
continuation to the nrf24l01 video
0:18
and in this video we will see how to
0:20
setup and use the transmit mode
0:23
if you haven't watched the first video
0:25
yet please watch it
0:27
otherwise you will not understand
0:29
anything
0:30
in the first video we configured the
0:32
common setup for the nrf
0:35
so let's start where we left now let's
0:38
write a function to configure the tx
0:40
mode
0:42
the parameters are the address of the
0:45
receiver pipe
0:46
and the channel number
0:57
i forgot to enable the device after the
0:59
configuration
1:03
here also we will disable the device
1:06
first
1:06
because we need to disable the device
1:09
while we configure it
1:11
let's start from the first register
1:13
again
1:14
we will power up the device in the end
1:17
we don't need to set up our x related
1:19
registers since we are setting the
1:21
transmit mode
1:28
here we will set up the rf channel
1:34
let's write the channel number to rf
1:36
channel register
1:45
this can take up to 6 bits of data
1:48
so unsigned 8 will be enough for this
2:07
now we will set up the tx address
2:10
this address is 5 bytes wide also if you
2:14
read here
2:14
we need to set the same address for the
2:16
rx data pipe
2:18
0. this is where the acknowledgement
2:21
from the receiver
2:22
is received but since we are not using
2:24
the auto acknowledgement
2:26
we will not set up this part
2:30
let's write the 5 bytes of address to
2:32
the tx address register
2:49
that's all the setup needed for transmit
2:51
mode
2:53
now we will power up the device
2:55
[Music]
3:03
we will keep the prim rx bit 0 since we
3:05
are setting up the transmit mode
3:08
so here we need to write a 1 in the
3:10
first position
3:15
we will first read the config register
3:17
and then add a 1 in the first position
3:32
and write the value back to the config
3:34
register
3:35
this is because we don't want to modify
3:38
other bits of this register
3:43
this is it now we will enable the device
3:46
i think we don't need to unselect the
3:48
device as this is of no use
3:51
we are already disabling the device
3:53
anyway
3:54
let me remove unselect and select parts
3:58
next we will write a function to send
4:00
the data
4:05
this function will take the argument as
4:07
the pointer to the data itself
4:10
here we don't need to disable the device
4:12
as these things should be done
4:14
when the device is powered up so select
4:17
the device first
4:21
before transmitting the payload we must
4:24
send a command to the device
4:26
indicating that the next data is the
4:28
payload
4:29
this is the command for that
4:31
[Music]
4:39
we will directly use hall spi transmit
4:42
to send the command
4:58
and after sending the payload command we
5:00
will again use whole spi
5:02
transmit to send the payload itself
5:05
our data width will be set to 32 bits
5:08
so we will send the 32 bits of data also
5:12
let's release the slave device now
5:16
this much would do the transmit part but
5:19
let's also add some feature to make sure
5:21
that the transmission was successful
5:24
to do that we will check the fifo status
5:27
register
5:28
if you check the fourth bit of this
5:30
register it is the tx fifo
5:32
empty flag this flag will set
5:35
when there is no data in the transmit
5:38
fifo
5:39
and this will indicate that the
5:40
transmission was success
5:43
let's give a delay of one millisecond
5:45
for the pin to settle
5:47
now we will read the fifo status
5:49
register
5:50
and if the fourth bit of this register
5:52
is set we will assume that the data
5:55
transferred successfully
6:00
but i noticed that if you disconnect the
6:02
device
6:03
all the bits in this register will be
6:05
set
6:06
this will make us hard to figure out if
6:08
the data transfer was a success
6:10
or the device has been disconnected
6:13
there is a way to avoid this scenario
6:16
notice that these second and third bits
6:19
are reserved
6:20
and they are always zero but if you
6:23
remove the device
6:24
these bits will also set to one so we
6:27
will check these bits also
6:29
and if they are zero we will assume that
6:32
the device is intact
6:33
and the data transfer was actually a
6:46
success
6:49
if the data was transferred we will send
6:52
a command to flush the fifo
7:07
and return a 1 indicating the success
7:11
else return 0 means failed
7:24
i have to put delay here
7:37
okay the code builds up just fine
7:40
now let's test this much part first
7:45
we will include nrfl01.h in our main
7:49
file
7:50
let's initialize the nrf
7:54
i forgot to put the functions in the
7:56
header file
7:58
let's put them all
8:03
now let's set up the nrf in the tx mode
8:07
we need to give the tx address and the
8:10
channel for communication
8:12
let's define the tx address first
8:16
this tx address will be the address of
8:18
the receive data pipe
8:20
also the address is 5 bytes wide and it
8:23
is passed as the most significant byte
8:26
first
8:27
so the actual tx address that will be
8:30
saved in the nrf will be 0 cross a
8:32
a b b c c d d
8:35
and d e let's define a string
8:38
that we will send to the receiver
8:44
now in the while loop we will first
8:47
transmit the data
8:48
and if it return a one we will blink a
8:50
led for the confirmation
8:53
that's why i set up those leds in the
8:55
cube mx
8:57
and added a delay of one second between
9:00
each
9:06
transfer
9:12
let's build it we are good to go
9:15
so let's debug this code
9:23
i have the j link attached for this
9:25
microcontroller
9:26
so i am selecting that
9:35
you can see the board on the top right
9:46
let's run it now
9:50
one led is blinking and another one is
9:54
on
9:55
actually these are active high leds and
9:58
i should have pulled it to the ground
9:59
here
10:02
anyway just focus on the blinking one
10:07
it's blinking that means the data
10:09
transmission is actually happening
10:14
let's put a break point here i want to
10:17
see the
10:18
data in the fifo status register
10:32
here you can see the fourth bit is set
10:35
and that means the tx fifo is empty
10:38
so our transmit part is working well
10:42
this is it for this video you can check
10:45
the next video for the receiving part
10:48
the link to the code is in the
10:50
description of both the videos
10:53
keep watching and have a nice day ahead
11:05
[Music]
11:12
do
11:16
you