Slave (receiver) example of using nRF24L01 with STM32F407VET6.
Slave (receiver) example of using nRF24L01 with STM32F407VET6 black boards.
Connect (plug in) the nRF24L01 module to the NRF24L01 connector located on the STM32F407VET6 board as follows:
nRF24L01 | STM32F407VET6 |
---|---|
Vcc | +3.3V |
GND | GND |
MOSI | PB_5 (SPI1 MOSI) |
MISO | PB_4 (SPI1 MISO) |
SCK | PB_3 (SPI1 SCK) |
CSN | PB_7 (CS) |
CE | PB_6 (CE) |
main.cpp@2:4c5ac5e09740, 2019-01-25 (annotated)
- Committer:
- hudakz
- Date:
- Fri Jan 25 14:03:41 2019 +0000
- Revision:
- 2:4c5ac5e09740
- Parent:
- 1:9bafc8faffdf
Updated.
Who changed what in which revision?
User | Revision | Line number | New 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 | } |