Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed RF24Network RF24
main.cpp
- Committer:
- Giamarchi
- Date:
- 2021-05-20
- Revision:
- 4:d7a0a07f21f3
- Parent:
- 3:d605536db315
File content as of revision 4:d7a0a07f21f3:
#include "mbed.h"
#include <RF24Network.h>
#include <RF24.h>
#include "isen32_board.h"
Serial pc(USBTX, USBRX); // 9600 baud par défaut
#define nrf_CE PB_3 // D3 sur connecteur Arduino
#define nrf_CSN PB_12
#define spi_MOSI PB_15
#define spi_MISO PB_14
#define spi_SCK PB_13
RF24 radio(spi_MOSI, spi_MISO, spi_SCK, nrf_CE, nrf_CSN );
// Network uses that radio
RF24Network network(radio);
// Address of our node
const uint16_t this_node = 01;
// Address of the other node
const uint16_t other_node = 00;
// How often to send payload packet to the other unit
const unsigned long interval = 1000; //ms
// When did we last send?
unsigned long last_sent;
Timer t;
// How many have we sent already
unsigned long packets_sent;
Timer t_packet;
// Structure of our payload
struct payload_t
{
// unsigned long ms;
// unsigned long counter;
uint8_t num;
uint8_t del;
};
struct _node
{
uint8_t num;
uint8_t del;
};
int main()
{
_node node;
BTN1.mode(PullUp); // Resist interne Pull up
pc.baud(9600);
wait_ms(1000);
pc.printf("mBed RF24Network node : 01\r\n");
radio.begin();
network.begin(/*channel*/ 90, /*node address*/ this_node);
wait_ms(2000);
t.start();
t_packet.start();
while(1)
{
// Refresh Dels
Set_8Dels(node.del);
// Pump the network regularly
network.update();
/* If it's time to send a message, send it! */
unsigned long now = t.read_ms();
if ( now >= interval )
{
t.reset();
pc.printf("Envoi...");
payload_t payload_tx;
if(!BTN1)
payload_tx.num = 02;
else
payload_tx.num = 00;
payload_tx.del++;
RF24NetworkHeader header_tx(/*to node*/ other_node);
bool ok = network.write(header_tx,&payload_tx,sizeof(payload_tx));
if (ok)
pc.printf("%d ok.\r\n",payload_tx.del);
else
pc.printf("erreur.\r\n");
}
while ( network.available() )
{
// If so, grab it and print it out
RF24NetworkHeader header_rx;
payload_t payload_rx;
network.read(header_rx,&payload_rx,sizeof(payload_rx));
// pc.printf("Received packet # %d at %d ms\r\n",payload_rx.counter,payload_rx.ms);
pc.printf("Node %d del %d\r\n",payload_rx.num,payload_rx.del);
if (payload_rx.num == 01)
{
node.del = payload_rx.del;
}
}
}
}