Slave (receiver) example of using nRF24L01 with STM32F407VET6.

Dependencies:   mbed RF24

Slave (receiver) example of using nRF24L01 with STM32F407VET6 black boards.

/media/uploads/hudakz/nrf24l01_2rY1GYr.png


Connect (plug in) the nRF24L01 module to the NRF24L01 connector located on the STM32F407VET6 board as follows:

nRF24L01STM32F407VET6
Vcc+3.3V
GNDGND
MOSIPB_5 (SPI1 MOSI)
MISOPB_4 (SPI1 MISO)
SCKPB_3 (SPI1 SCK)
CSNPB_7 (CS)
CEPB_6 (CE)
Committer:
hudakz
Date:
Fri Jan 25 14:03:41 2019 +0000
Revision:
2:4c5ac5e09740
Parent:
1:9bafc8faffdf
Updated.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:818ff5c70049 1 #include "mbed.h"
hudakz 0:818ff5c70049 2 #include "RF24.h"
hudakz 0:818ff5c70049 3
hudakz 2:4c5ac5e09740 4 const uint64_t ADDRESS = 0xF0F0F0F0F0F0F001L;
hudakz 0:818ff5c70049 5
hudakz 0:818ff5c70049 6 DigitalOut led(PA_6);
hudakz 2:4c5ac5e09740 7 RF24 radio(PB_5, PB_4, PB_3, PB_7, PB_6); // mosi, miso, sck, csn, ce, (irq not used)
hudakz 0:818ff5c70049 8 uint8_t payload;
hudakz 0:818ff5c70049 9
hudakz 0:818ff5c70049 10 int main(void)
hudakz 0:818ff5c70049 11 {
hudakz 0:818ff5c70049 12 // Initialize nRF24L01
hudakz 2:4c5ac5e09740 13 if (!radio.begin()) {
hudakz 2:4c5ac5e09740 14 printf("Failed to initialize nRF24L01. Check whether connected.\r\n");
hudakz 2:4c5ac5e09740 15 return -1; // Exit the program
hudakz 2:4c5ac5e09740 16 }
hudakz 0:818ff5c70049 17 radio.setPALevel(RF24_PA_LOW);
hudakz 0:818ff5c70049 18 radio.setRetries(5, 15);
hudakz 1:9bafc8faffdf 19 radio.setPayloadSize(sizeof(payload));
hudakz 0:818ff5c70049 20 radio.setAutoAck(true);
hudakz 0:818ff5c70049 21 radio.openReadingPipe(0, ADDRESS); // use pipe 0 of this slave to receive messsages and send back auto acknowledge
hudakz 0:818ff5c70049 22 radio.startListening();
hudakz 0:818ff5c70049 23
hudakz 0:818ff5c70049 24 while (1) {
hudakz 0:818ff5c70049 25 if (radio.available()) {
hudakz 1:9bafc8faffdf 26 radio.read(&payload, sizeof(payload)); // read message and send acknowledge back to the master
hudakz 0:818ff5c70049 27 led = payload;
hudakz 0:818ff5c70049 28 }
hudakz 0:818ff5c70049 29 }
hudakz 0:818ff5c70049 30 }