Master (transmitter) example of using nRF24L01 with STM32F407VET6.
Master (transmitter) 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) |
Diff: main.cpp
- Revision:
- 0:a910b574c2d9
- Child:
- 2:f2d55b32f539
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jan 23 07:43:18 2019 +0000 @@ -0,0 +1,33 @@ +#include "mbed.h" +#include "RF24.h" + +const uint64_t SLAVE_ADDRESS = 0xF0F0F0F0F0F0F001L; // slave's address + +DigitalOut led(PA_6); // LED1 +RF24 radio(PB_5, PB_4, PB_3, PB_7, PB_6); // mosi, miso, sck, csn, ce, (irq is not connected/used) +uint8_t payload; + +int main() +{ + // Initialize nRF24L01 + radio.begin(); + radio.setPALevel(RF24_PA_LOW); + radio.setRetries(5, 15); + radio.setPayloadSize(sizeof(payload)); + radio.setAutoAck(true); + + while (1) { + led = !led; + payload = led; + + // Send led's status to slave + radio.stopListening(); + radio.openWritingPipe(SLAVE_ADDRESS); + if (radio.write(&payload, sizeof(payload))) // send message to slave and get acknowledge + printf("Message delivery succeeded.\r\n"); + else + printf("Message delivery failed.\r\n"); + + wait(1); + } +}