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@1:9bafc8faffdf, 2019-01-23 (annotated)
- Committer:
- hudakz
- Date:
- Wed Jan 23 17:45:09 2019 +0000
- Revision:
- 1:9bafc8faffdf
- Parent:
- 0:818ff5c70049
- Child:
- 2:4c5ac5e09740
RF24 library replaced.
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 | 1:9bafc8faffdf | 4 | const uint64_t ADDRESS = 0xF0F0F0F0F0F0F001LL; |
hudakz | 0:818ff5c70049 | 5 | |
hudakz | 0:818ff5c70049 | 6 | DigitalOut led(PA_6); |
hudakz | 0:818ff5c70049 | 7 | RF24 radio(PB_5, PB_4, PB_3, PB_7, PB_6); // mosi, miso, sck, csn, ce, (irq=Not Connected) |
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 | 0:818ff5c70049 | 13 | radio.begin(); |
hudakz | 0:818ff5c70049 | 14 | radio.setPALevel(RF24_PA_LOW); |
hudakz | 0:818ff5c70049 | 15 | radio.setRetries(5, 15); |
hudakz | 1:9bafc8faffdf | 16 | radio.setPayloadSize(sizeof(payload)); |
hudakz | 0:818ff5c70049 | 17 | radio.setAutoAck(true); |
hudakz | 0:818ff5c70049 | 18 | radio.openReadingPipe(0, ADDRESS); // use pipe 0 of this slave to receive messsages and send back auto acknowledge |
hudakz | 0:818ff5c70049 | 19 | radio.startListening(); |
hudakz | 0:818ff5c70049 | 20 | |
hudakz | 0:818ff5c70049 | 21 | while (1) { |
hudakz | 0:818ff5c70049 | 22 | if (radio.available()) { |
hudakz | 1:9bafc8faffdf | 23 | radio.read(&payload, sizeof(payload)); // read message and send acknowledge back to the master |
hudakz | 0:818ff5c70049 | 24 | led = payload; |
hudakz | 0:818ff5c70049 | 25 | } |
hudakz | 0:818ff5c70049 | 26 | } |
hudakz | 0:818ff5c70049 | 27 | } |