NRF52_esb

Committer:
wkleunen
Date:
Thu Feb 04 10:36:44 2021 +0000
Revision:
1:66f95e364222
Parent:
0:a01a54c0dc90
Initial compile;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joshuajnoble 0:a01a54c0dc90 1 #include "mbed.h"
joshuajnoble 0:a01a54c0dc90 2
joshuajnoble 0:a01a54c0dc90 3 DigitalOut myled(LED1);
joshuajnoble 0:a01a54c0dc90 4
joshuajnoble 0:a01a54c0dc90 5 #include <stdbool.h>
joshuajnoble 0:a01a54c0dc90 6 #include <stdint.h>
joshuajnoble 0:a01a54c0dc90 7 #include <string.h>
joshuajnoble 0:a01a54c0dc90 8 //#include "nrf.h"
joshuajnoble 0:a01a54c0dc90 9 #include "micro_esb.h"
joshuajnoble 0:a01a54c0dc90 10 #include "uesb_error_codes.h"
joshuajnoble 0:a01a54c0dc90 11 #include "nrf_delay.h"
joshuajnoble 0:a01a54c0dc90 12 //#include "nrf_gpio.h"
joshuajnoble 0:a01a54c0dc90 13
wkleunen 1:66f95e364222 14
wkleunen 1:66f95e364222 15
joshuajnoble 0:a01a54c0dc90 16 static uesb_payload_t tx_payload, rx_payload;
joshuajnoble 0:a01a54c0dc90 17
joshuajnoble 0:a01a54c0dc90 18 void uesb_event_handler()
joshuajnoble 0:a01a54c0dc90 19 {
joshuajnoble 0:a01a54c0dc90 20 static uint32_t rf_interrupts;
joshuajnoble 0:a01a54c0dc90 21 static uint32_t tx_attempts;
joshuajnoble 0:a01a54c0dc90 22
joshuajnoble 0:a01a54c0dc90 23 uesb_get_clear_interrupts(&rf_interrupts);
joshuajnoble 0:a01a54c0dc90 24
joshuajnoble 0:a01a54c0dc90 25 if(rf_interrupts & UESB_INT_TX_SUCCESS_MSK)
joshuajnoble 0:a01a54c0dc90 26 {
joshuajnoble 0:a01a54c0dc90 27 }
joshuajnoble 0:a01a54c0dc90 28
joshuajnoble 0:a01a54c0dc90 29 if(rf_interrupts & UESB_INT_TX_FAILED_MSK)
joshuajnoble 0:a01a54c0dc90 30 {
wkleunen 1:66f95e364222 31 uesb_flush_tx();
joshuajnoble 0:a01a54c0dc90 32 }
joshuajnoble 0:a01a54c0dc90 33
joshuajnoble 0:a01a54c0dc90 34 if(rf_interrupts & UESB_INT_RX_DR_MSK)
joshuajnoble 0:a01a54c0dc90 35 {
joshuajnoble 0:a01a54c0dc90 36 uesb_read_rx_payload(&rx_payload);
joshuajnoble 0:a01a54c0dc90 37 NRF_GPIO->OUTCLR = 0xFUL << 8;
joshuajnoble 0:a01a54c0dc90 38 NRF_GPIO->OUTSET = (uint32_t)((rx_payload.data[2] & 0x0F) << 8);
joshuajnoble 0:a01a54c0dc90 39 }
joshuajnoble 0:a01a54c0dc90 40
wkleunen 1:66f95e364222 41 uesb_get_tx_attempts(&tx_attempts);
joshuajnoble 0:a01a54c0dc90 42 NRF_GPIO->OUTCLR = 0xFUL << 12;
joshuajnoble 0:a01a54c0dc90 43 NRF_GPIO->OUTSET = (tx_attempts & 0x0F) << 12;
joshuajnoble 0:a01a54c0dc90 44 }
joshuajnoble 0:a01a54c0dc90 45
joshuajnoble 0:a01a54c0dc90 46 int main(void)
joshuajnoble 0:a01a54c0dc90 47 {
joshuajnoble 0:a01a54c0dc90 48 uint8_t rx_addr_p0[] = {0x12, 0x34, 0x56, 0x78, 0x9A};
joshuajnoble 0:a01a54c0dc90 49 uint8_t rx_addr_p1[] = {0xBC, 0xDE, 0xF0, 0x12, 0x23};
joshuajnoble 0:a01a54c0dc90 50 uint8_t rx_addr_p2 = 0x66;
joshuajnoble 0:a01a54c0dc90 51
joshuajnoble 0:a01a54c0dc90 52 //nrf_gpio_range_cfg_output(8, 15);
joshuajnoble 0:a01a54c0dc90 53
joshuajnoble 0:a01a54c0dc90 54 NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
joshuajnoble 0:a01a54c0dc90 55 NRF_CLOCK->TASKS_HFCLKSTART = 1;
joshuajnoble 0:a01a54c0dc90 56 while(NRF_CLOCK->EVENTS_HFCLKSTARTED == 0);
joshuajnoble 0:a01a54c0dc90 57
joshuajnoble 0:a01a54c0dc90 58 uesb_config_t uesb_config = UESB_DEFAULT_CONFIG;
joshuajnoble 0:a01a54c0dc90 59 uesb_config.rf_channel = 5;
joshuajnoble 0:a01a54c0dc90 60 uesb_config.crc = UESB_CRC_16BIT;
joshuajnoble 0:a01a54c0dc90 61 uesb_config.retransmit_count = 6;
joshuajnoble 0:a01a54c0dc90 62 uesb_config.retransmit_delay = 500;
joshuajnoble 0:a01a54c0dc90 63 uesb_config.dynamic_ack_enabled = 0;
joshuajnoble 0:a01a54c0dc90 64 uesb_config.protocol = UESB_PROTOCOL_ESB_DPL;
joshuajnoble 0:a01a54c0dc90 65 uesb_config.bitrate = UESB_BITRATE_2MBPS;
joshuajnoble 0:a01a54c0dc90 66 uesb_config.event_handler = uesb_event_handler;
joshuajnoble 0:a01a54c0dc90 67
joshuajnoble 0:a01a54c0dc90 68 uesb_init(&uesb_config);
joshuajnoble 0:a01a54c0dc90 69
wkleunen 1:66f95e364222 70 nrf_esb_set_base_address_0(rx_addr_p0);
wkleunen 1:66f95e364222 71 nrf_esb_set_base_address_1(rx_addr_p1);
wkleunen 1:66f95e364222 72 //nrf_esb_set_base_address_2(&rx_addr_p2);
joshuajnoble 0:a01a54c0dc90 73
joshuajnoble 0:a01a54c0dc90 74 tx_payload.length = 8;
joshuajnoble 0:a01a54c0dc90 75 tx_payload.pipe = 0;
joshuajnoble 0:a01a54c0dc90 76 tx_payload.data[0] = 0x01;
joshuajnoble 0:a01a54c0dc90 77 tx_payload.data[1] = 0x00;
joshuajnoble 0:a01a54c0dc90 78 tx_payload.data[2] = 0x00;
joshuajnoble 0:a01a54c0dc90 79 tx_payload.data[3] = 0x00;
joshuajnoble 0:a01a54c0dc90 80 tx_payload.data[4] = 0x11;
joshuajnoble 0:a01a54c0dc90 81
joshuajnoble 0:a01a54c0dc90 82 while (true)
joshuajnoble 0:a01a54c0dc90 83 {
joshuajnoble 0:a01a54c0dc90 84 if(uesb_write_tx_payload(&tx_payload) == UESB_SUCCESS)
joshuajnoble 0:a01a54c0dc90 85 {
joshuajnoble 0:a01a54c0dc90 86 tx_payload.data[1]++;
joshuajnoble 0:a01a54c0dc90 87 }
joshuajnoble 0:a01a54c0dc90 88 nrf_delay_us(10000);
joshuajnoble 0:a01a54c0dc90 89 }
joshuajnoble 0:a01a54c0dc90 90 }
joshuajnoble 0:a01a54c0dc90 91