forked from NordicPlayground/nrf51-micro-esb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
78 lines (63 loc) · 2.09 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved.
*
* The information contained herein is property of Nordic Semiconductor ASA.
* Terms and conditions of usage are described in detail in NORDIC
* SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
*
* Licensees are granted free, non-transferable use of the information. NO
* WARRANTY of ANY KIND is provided. This heading must NOT be removed from
* the file.
*
*/
#include <stdbool.h>
#include <stdint.h>
#include "nrf.h"
#include "micro_esb.h"
#include "uesb_error_codes.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
static uesb_payload_t rx_payload;
void uesb_event_handler()
{
static uint32_t rf_interrupts;
uesb_get_clear_interrupts(&rf_interrupts);
if(rf_interrupts & UESB_INT_TX_SUCCESS_MSK)
{
}
if(rf_interrupts & UESB_INT_TX_FAILED_MSK)
{
}
if(rf_interrupts & UESB_INT_RX_DR_MSK)
{
uesb_read_rx_payload(&rx_payload);
NRF_GPIO->OUTCLR = 0xFF << 8;
NRF_GPIO->OUTSET = rx_payload.data[1] << 8;
}
}
int main(void)
{
uint8_t rx_addr_p0[] = {0x12, 0x34, 0x56, 0x78, 0x9A};
uint8_t rx_addr_p1[] = {0xBC, 0xDE, 0xF0, 0x12, 0x23};
uint8_t rx_addr_p2 = 0x66;
nrf_gpio_range_cfg_output(8, 31);
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
NRF_CLOCK->TASKS_HFCLKSTART = 1;
while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
uesb_config_t uesb_config = UESB_DEFAULT_CONFIG;
uesb_config.rf_channel = 5;
uesb_config.crc = UESB_CRC_16BIT;
uesb_config.dynamic_ack_enabled = 0;
uesb_config.payload_length = 8;
uesb_config.protocol = UESB_PROTOCOL_ESB_DPL;
uesb_config.bitrate = UESB_BITRATE_2MBPS;
uesb_config.mode = UESB_MODE_PRX;
uesb_config.event_handler = uesb_event_handler;
uesb_init(&uesb_config);
uesb_set_address(UESB_ADDRESS_PIPE0, rx_addr_p0);
uesb_set_address(UESB_ADDRESS_PIPE1, rx_addr_p1);
uesb_set_address(UESB_ADDRESS_PIPE2, &rx_addr_p2);
uesb_start_rx();
while (true)
{
}
}