Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
watt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Sam Calisch
watt
Commits
401fb9f9
Commit
401fb9f9
authored
Aug 30, 2017
by
Sam Calisch
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ok, radio now transmitting between pairs
parent
126d469e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
279 additions
and
91 deletions
+279
-91
bc832-watt/fw/watt-bc832-recv/watt-bc832-recv.ino
bc832-watt/fw/watt-bc832-recv/watt-bc832-recv.ino
+109
-0
bc832-watt/fw/watt-bc832/watt-bc832.ino
bc832-watt/fw/watt-bc832/watt-bc832.ino
+114
-91
bc832-watt/host/watt_host.py
bc832-watt/host/watt_host.py
+56
-0
No files found.
bc832-watt/fw/watt-bc832-recv/watt-bc832-recv.ino
0 → 100644
View file @
401fb9f9
#define N_SAMPLES 12
#define PACKET_BASE_ADDRESS_LENGTH (2UL) //Packet base address length field size in bytes
static
uint8_t
packet
=
52
;
//declare a buffer for our packet to use with easydma
const
uint8_t
pin_rx
=
8
;
const
uint8_t
pin_tx
=
6
;
uint16_t
last_tx_time
=
0
;
uint16_t
tx_period
=
100
;
//ms
static
int16_t
data_buffer
[
N_SAMPLES
]
=
{
0
};
//
//RADIO
//
void
radio_setup
(){
NRF_RADIO
->
POWER
=
RADIO_POWER_POWER_Disabled
;
//turn off radio to reset registers
delay
(
10
);
NRF_RADIO
->
POWER
=
RADIO_POWER_POWER_Enabled
;
//turn on radio
delay
(
10
);
NRF_RADIO
->
TXPOWER
=
(
RADIO_TXPOWER_TXPOWER_Pos3dBm
<<
RADIO_TXPOWER_TXPOWER_Pos
);
NRF_RADIO
->
FREQUENCY
=
7UL
;
// Frequency bin 7, 2407MHz
NRF_RADIO
->
MODE
=
(
RADIO_MODE_MODE_Nrf_2Mbit
<<
RADIO_MODE_MODE_Pos
);
NRF_RADIO
->
PREFIX0
=
((
uint32_t
)
0xC0
<<
0
);
// Prefix byte of address 0
NRF_RADIO
->
BASE0
=
0x01234567UL
;
// Base address for prefix 0
NRF_RADIO
->
TXADDRESS
=
0x00UL
;
// Set device address 0 to use when transmitting
NRF_RADIO
->
RXADDRESSES
=
0x01UL
;
// Enable device address 0 to use to select which addresses to receive
// Packet configuration
NRF_RADIO
->
PCNF0
=
(
0
<<
RADIO_PCNF0_S1LEN_Pos
)
|
(
0
<<
RADIO_PCNF0_S0LEN_Pos
)
|
(
0
<<
RADIO_PCNF0_LFLEN_Pos
);
NRF_RADIO
->
PCNF1
=
(
RADIO_PCNF1_WHITEEN_Disabled
<<
RADIO_PCNF1_WHITEEN_Pos
)
|
(
1
<<
RADIO_PCNF1_STATLEN_Pos
)
|
(
RADIO_PCNF1_ENDIAN_Big
<<
RADIO_PCNF1_ENDIAN_Pos
)
|
(
2
<<
RADIO_PCNF1_BALEN_Pos
);
NRF_RADIO
->
CRCCNF
=
(
RADIO_CRCCNF_LEN_Disabled
<<
RADIO_CRCCNF_LEN_Pos
);
// Number of checksum bits
NRF_RADIO
->
MODECNF0
|=
RADIO_MODECNF0_RU_Fast
<<
RADIO_MODECNF0_RU_Pos
;
//turn on fast ramp up
NRF_RADIO
->
SHORTS
=
0
;
//turn off all shortcuts, for debug
NRF_RADIO
->
PACKETPTR
=
(
uint32_t
)
&
packet
;
//set pointer to packet buffer
//start HFCLK
NRF_CLOCK
->
TASKS_HFCLKSTART
=
1
;
while
(
!
(
NRF_CLOCK
->
HFCLKSTAT
&
CLOCK_HFCLKSTAT_STATE_Msk
));
//wait for hfclk to start
delay
(
10
);
}
void
radio_wait_for_end
(){
while
(
!
(
NRF_RADIO
->
EVENTS_END
));
NRF_RADIO
->
EVENTS_END
=
0
;
}
//clear end event
void
radio_wait_for_ready
(){
while
(
!
(
NRF_RADIO
->
EVENTS_READY
));
NRF_RADIO
->
EVENTS_READY
=
0
;
}
//clear ready event
void
radio_disable
(){
NRF_RADIO
->
EVENTS_DISABLED
=
0
;
//clear disabled event
NRF_RADIO
->
TASKS_DISABLE
=
1
;
while
(
!
(
NRF_RADIO
->
EVENTS_DISABLED
));
}
void
radio_send
(){
NRF_RADIO
->
EVENTS_READY
=
0
;
//clear ready event
NRF_RADIO
->
TASKS_TXEN
=
1
;
//trigger tx enable task
delayMicroseconds
(
15
);
//radio_wait_for_ready(); //only generated when actually switching to tx mode
NRF_RADIO
->
TASKS_START
=
1
;
//start
radio_wait_for_end
();
}
void
radio_recv
(){
NRF_RADIO
->
EVENTS_READY
=
0
;
//clear ready event
NRF_RADIO
->
TASKS_RXEN
=
1
;
//trigger rx enable task
delayMicroseconds
(
15
);
//radio_wait_for_ready(); //only generated when actually switching to rx mode
NRF_RADIO
->
TASKS_START
=
1
;
radio_wait_for_end
();
}
//
//UARTE
//
void
uarte_setup
(){
//uart with dma
NRF_UARTE0
->
PSEL
.
TXD
=
(
pin_tx
<<
UARTE_PSEL_TXD_PIN_Pos
)
&
UARTE_PSEL_TXD_PIN_Msk
;
NRF_UARTE0
->
PSEL
.
RXD
=
(
pin_rx
<<
UARTE_PSEL_RXD_PIN_Pos
)
&
UARTE_PSEL_RXD_PIN_Msk
;
NRF_UARTE0
->
CONFIG
=
((
UART_CONFIG_PARITY_Excluded
<<
UARTE_CONFIG_PARITY_Pos
)
&
UARTE_CONFIG_PARITY_Msk
)
|
((
UARTE_CONFIG_HWFC_Disabled
<<
UARTE_CONFIG_HWFC_Pos
)
&
UARTE_CONFIG_HWFC_Msk
);
NRF_UARTE0
->
BAUDRATE
=
UART_BAUDRATE_BAUDRATE_Baud1M
;
NRF_UARTE0
->
ENABLE
=
(
UARTE_ENABLE_ENABLE_Enabled
<<
UARTE_ENABLE_ENABLE_Pos
)
&
UARTE_ENABLE_ENABLE_Msk
;
NRF_UARTE0
->
TXD
.
MAXCNT
=
N_SAMPLES
;
}
void
setup
()
{
uarte_setup
();
radio_setup
();
Serial
.
begin
(
1000000
);
while
(
true
){
if
(
millis
()
-
last_tx_time
>
tx_period
){
radio_recv
();
Serial
.
println
(
packet
);
//debug for ascii
//data_buffer[0] = packet;
//data_buffer[1] = packet;
//data_buffer[2] = packet;
//data_buffer[3] = 10;
//start a transmission of the tx buffer
//NRF_UARTE0->TXD.PTR = (uint32_t)(&data_buffer); //reset pointer to start of buffer
//NRF_UARTE0->TASKS_STARTTX = 1; //trigger start task
last_tx_time
=
millis
();
}
}
}
void
loop
()
{}
bc832-watt/fw/watt-bc832/watt-bc832.ino
View file @
401fb9f9
#define N_SAMPLES 12
#define PACKET_BASE_ADDRESS_LENGTH (2UL) //Packet base address length field size in bytes
static
uint8_t
packet
=
12
;
//declare a buffer for our packet to use with easydma
const
uint8_t
pin_rx
=
8
;
const
uint8_t
pin_tx
=
6
;
int16_t
values
=
0
;
//place to storage current and voltage values
uint16_t
last_tx_time
=
0
;
uint16_t
tx_period
=
100
;
//ms
static
uint8_t
txBuffer
[
20
]
=
{
0
};
static
uint8_t
rxBuffer
[
20
]
=
{
0
};
static
int16_t
data_buffer
[
N_SAMPLES
]
=
{
0
};
//
//ADC
//
void
adc_setup
(){
//configure SAADC resolution
NRF_SAADC
->
RESOLUTION
=
SAADC_RESOLUTION_VAL_10bit
;
...
...
@@ -13,19 +21,19 @@ void adc_setup(){
// (( 2047 << SAADC_SAMPLERATE_CC_Pos) & SAADC_SAMPLERATE_CC_Msk);
//enable oversampling -- do not combine with scan mode!
//NRF_SAADC->OVERSAMPLE = (SAADC_OVERSAMPLE_OVERSAMPLE_Over256x << SAADC_OVERSAMPLE_OVERSAMPLE_Pos) & SAADC_OVERSAMPLE_OVERSAMPLE_Msk ;
//
NRF_SAADC->OVERSAMPLE = (SAADC_OVERSAMPLE_OVERSAMPLE_Bypass << SAADC_OVERSAMPLE_OVERSAMPLE_Pos) & SAADC_OVERSAMPLE_OVERSAMPLE_Msk ;
NRF_SAADC
->
OVERSAMPLE
=
(
SAADC_OVERSAMPLE_OVERSAMPLE_Bypass
<<
SAADC_OVERSAMPLE_OVERSAMPLE_Pos
)
&
SAADC_OVERSAMPLE_OVERSAMPLE_Msk
;
//enable SAADC
NRF_SAADC
->
ENABLE
=
(
SAADC_ENABLE_ENABLE_Enabled
<<
SAADC_ENABLE_ENABLE_Pos
);
//set result pointer
NRF_SAADC
->
RESULT
.
PTR
=
(
uint32_t
)
&
values
;
NRF_SAADC
->
RESULT
.
MAXCNT
=
1
;
// One sample
NRF_SAADC
->
RESULT
.
PTR
=
(
uint32_t
)
(
&
data_buffer
)
;
NRF_SAADC
->
RESULT
.
MAXCNT
=
N_SAMPLES
;
// number of samples
//set channel 0 resistor network, gain, reference, sample time, and mode
NRF_SAADC
->
CH
[
0
].
CONFIG
=
((
SAADC_CH_CONFIG_RESP_Bypass
<<
SAADC_CH_CONFIG_RESP_Pos
)
&
SAADC_CH_CONFIG_RESP_Msk
)
|
((
SAADC_CH_CONFIG_RESP_Bypass
<<
SAADC_CH_CONFIG_RESN_Pos
)
&
SAADC_CH_CONFIG_RESN_Msk
)
|
((
SAADC_CH_CONFIG_GAIN_Gain1
<<
SAADC_CH_CONFIG_GAIN_Pos
)
&
SAADC_CH_CONFIG_GAIN_Msk
)
|
((
SAADC_CH_CONFIG_REFSEL_Internal
<<
SAADC_CH_CONFIG_REFSEL_Pos
)
&
SAADC_CH_CONFIG_REFSEL_Msk
)
|
((
SAADC_CH_CONFIG_TACQ_
3
us
<<
SAADC_CH_CONFIG_TACQ_Pos
)
&
SAADC_CH_CONFIG_TACQ_Msk
)
|
((
SAADC_CH_CONFIG_TACQ_
5
us
<<
SAADC_CH_CONFIG_TACQ_Pos
)
&
SAADC_CH_CONFIG_TACQ_Msk
)
|
((
SAADC_CH_CONFIG_BURST_Disabled
<<
SAADC_CH_CONFIG_BURST_Pos
)
&
SAADC_CH_CONFIG_BURST_Msk
)
|
((
SAADC_CH_CONFIG_MODE_Diff
<<
SAADC_CH_CONFIG_MODE_Pos
)
&
SAADC_CH_CONFIG_MODE_Msk
);
//configure Channel 0 to use A0 as positive, A1 as negative
...
...
@@ -33,108 +41,123 @@ void adc_setup(){
NRF_SAADC
->
CH
[
0
].
PSELN
=
SAADC_CH_PSELP_PSELP_AnalogInput1
;
//set channel 1 resistor network, gain, reference, sample time, and mode
//
NRF_SAADC->CH[1].CONFIG = ((SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESP_Pos) & SAADC_CH_CONFIG_RESP_Msk)
//
| ((SAADC_CH_CONFIG_RESP_Bypass << SAADC_CH_CONFIG_RESN_Pos) & SAADC_CH_CONFIG_RESN_Msk)
//
| ((SAADC_CH_CONFIG_GAIN_Gain4 << SAADC_CH_CONFIG_GAIN_Pos) & SAADC_CH_CONFIG_GAIN_Msk)
//
| ((SAADC_CH_CONFIG_REFSEL_Internal << SAADC_CH_CONFIG_REFSEL_Pos) & SAADC_CH_CONFIG_REFSEL_Msk)
// | ((SAADC_CH_CONFIG_TACQ_10
us << SAADC_CH_CONFIG_TACQ_Pos) & SAADC_CH_CONFIG_TACQ_Msk)
//
| ((SAADC_CH_CONFIG_BURST_Disabled << SAADC_CH_CONFIG_BURST_Pos) & SAADC_CH_CONFIG_BURST_Msk)
//
| ((SAADC_CH_CONFIG_MODE_Diff << SAADC_CH_CONFIG_MODE_Pos) & SAADC_CH_CONFIG_MODE_Msk);
NRF_SAADC
->
CH
[
1
].
CONFIG
=
((
SAADC_CH_CONFIG_RESP_Bypass
<<
SAADC_CH_CONFIG_RESP_Pos
)
&
SAADC_CH_CONFIG_RESP_Msk
)
|
((
SAADC_CH_CONFIG_RESP_Bypass
<<
SAADC_CH_CONFIG_RESN_Pos
)
&
SAADC_CH_CONFIG_RESN_Msk
)
|
((
SAADC_CH_CONFIG_GAIN_Gain4
<<
SAADC_CH_CONFIG_GAIN_Pos
)
&
SAADC_CH_CONFIG_GAIN_Msk
)
|
((
SAADC_CH_CONFIG_REFSEL_Internal
<<
SAADC_CH_CONFIG_REFSEL_Pos
)
&
SAADC_CH_CONFIG_REFSEL_Msk
)
|
((
SAADC_CH_CONFIG_TACQ_5
us
<<
SAADC_CH_CONFIG_TACQ_Pos
)
&
SAADC_CH_CONFIG_TACQ_Msk
)
|
((
SAADC_CH_CONFIG_BURST_Disabled
<<
SAADC_CH_CONFIG_BURST_Pos
)
&
SAADC_CH_CONFIG_BURST_Msk
)
|
((
SAADC_CH_CONFIG_MODE_Diff
<<
SAADC_CH_CONFIG_MODE_Pos
)
&
SAADC_CH_CONFIG_MODE_Msk
);
//configure Channel 1 to use A2 as positive, A4 as negative
//NRF_SAADC->CH[1].PSELP = SAADC_CH_PSELP_PSELP_AnalogInput2;
//NRF_SAADC->CH[1].PSELN = SAADC_CH_PSELP_PSELP_AnalogInput4;
NRF_SAADC
->
CH
[
1
].
PSELP
=
SAADC_CH_PSELP_PSELP_AnalogInput2
;
NRF_SAADC
->
CH
[
1
].
PSELN
=
SAADC_CH_PSELP_PSELP_AnalogInput4
;
}
void
take_adc_samples
(){
//start task
NRF_SAADC
->
TASKS_START
=
0x01UL
;
while
(
!
NRF_SAADC
->
EVENTS_STARTED
);
NRF_SAADC
->
EVENTS_STARTED
=
0x00UL
;
for
(
int
i
=
0
;
i
<
N_SAMPLES
;
i
++
){
//sample task channel 0
NRF_SAADC
->
TASKS_SAMPLE
=
0x01UL
;
while
(
!
NRF_SAADC
->
EVENTS_DONE
);
NRF_SAADC
->
EVENTS_DONE
=
0x00UL
;
//sample task channel 1
NRF_SAADC
->
TASKS_SAMPLE
=
0x01UL
;
while
(
!
NRF_SAADC
->
EVENTS_DONE
);
NRF_SAADC
->
EVENTS_DONE
=
0x00UL
;
}
NRF_SAADC
->
TASKS_STOP
=
0x01UL
;
while
(
!
NRF_SAADC
->
EVENTS_STOPPED
);
NRF_SAADC
->
EVENTS_STOPPED
=
0x00UL
;
}
void
timer_setup
(){
//configure adc sample rate via PPI and timer1
//set timer mode
NRF_TIMER1
->
MODE
=
(
TIMER_MODE_MODE_Timer
<<
TIMER_MODE_MODE_Pos
)
&
TIMER_MODE_MODE_Msk
;
NRF_TIMER1
->
TASKS_CLEAR
=
1
;
//clear tasks
//set prescalar = 4 for 1MHz tick frequency, 9 for 31.25kHz
NRF_TIMER1
->
PRESCALER
=
(
9
<<
TIMER_PRESCALER_PRESCALER_Pos
)
&
TIMER_PRESCALER_PRESCALER_Msk
;
NRF_TIMER1
->
BITMODE
=
TIMER_BITMODE_BITMODE_16Bit
;
//set CC = 1000 for 1kHz overflow frequency
NRF_TIMER1
->
CC
[
0
]
=
(
10000
<<
TIMER_CC_CC_Pos
)
&
TIMER_CC_CC_Msk
;
//set shortcut between compare0 and clear
NRF_TIMER1
->
SHORTS
=
((
TIMER_SHORTS_COMPARE0_CLEAR_Enabled
<<
TIMER_SHORTS_COMPARE0_CLEAR_Pos
)
&
TIMER_SHORTS_COMPARE0_CLEAR_Msk
);
//connect compare0 event to adc
//for now, how about we just send something over serial?
//enable interrupt for COMPARE[0] event
//NVIC_DisableIRQ(TIMER1_IRQn);
//NVIC_ClearPendingIRQ(TIMER1_IRQn);
//NVIC_SetPriority(TIMER1_IRQn, 3); //lower priority to avoid conflict with soft device
//NVIC_EnableIRQ(TIMER1_IRQn);
//NRF_TIMER1->INTENSET = ((TIMER_INTENSET_COMPARE0_Set << TIMER_INTENSET_COMPARE0_Pos) & TIMER_INTENSET_COMPARE0_Msk);
//NRF_TIMER1->TASKS_START = 1;
//
//RADIO
//
void
radio_setup
(){
NRF_RADIO
->
POWER
=
RADIO_POWER_POWER_Disabled
;
//turn off radio to reset registers
delay
(
10
);
NRF_RADIO
->
POWER
=
RADIO_POWER_POWER_Enabled
;
//turn on radio
delay
(
10
);
NRF_RADIO
->
TXPOWER
=
(
RADIO_TXPOWER_TXPOWER_Pos3dBm
<<
RADIO_TXPOWER_TXPOWER_Pos
);
NRF_RADIO
->
FREQUENCY
=
7UL
;
// Frequency bin 7, 2407MHz
NRF_RADIO
->
MODE
=
(
RADIO_MODE_MODE_Nrf_2Mbit
<<
RADIO_MODE_MODE_Pos
);
NRF_RADIO
->
PREFIX0
=
((
uint32_t
)
0xC0
<<
0
);
// Prefix byte of address 0
NRF_RADIO
->
BASE0
=
0x01234567UL
;
// Base address for prefix 0
NRF_RADIO
->
TXADDRESS
=
0x00UL
;
// Set device address 0 to use when transmitting
NRF_RADIO
->
RXADDRESSES
=
0x01UL
;
// Enable device address 0 to use to select which addresses to receive
// Packet configuration
NRF_RADIO
->
PCNF0
=
(
0
<<
RADIO_PCNF0_S1LEN_Pos
)
|
(
0
<<
RADIO_PCNF0_S0LEN_Pos
)
|
(
0
<<
RADIO_PCNF0_LFLEN_Pos
);
NRF_RADIO
->
PCNF1
=
(
RADIO_PCNF1_WHITEEN_Disabled
<<
RADIO_PCNF1_WHITEEN_Pos
)
|
(
1
<<
RADIO_PCNF1_STATLEN_Pos
)
|
(
RADIO_PCNF1_ENDIAN_Big
<<
RADIO_PCNF1_ENDIAN_Pos
)
|
(
2
<<
RADIO_PCNF1_BALEN_Pos
);
NRF_RADIO
->
CRCCNF
=
(
RADIO_CRCCNF_LEN_Disabled
<<
RADIO_CRCCNF_LEN_Pos
);
// Number of checksum bits
NRF_RADIO
->
MODECNF0
|=
RADIO_MODECNF0_RU_Fast
<<
RADIO_MODECNF0_RU_Pos
;
//turn on fast ramp up
NRF_RADIO
->
SHORTS
=
0
;
//turn off all shortcuts, for debug
NRF_RADIO
->
PACKETPTR
=
(
uint32_t
)
&
packet
;
//set pointer to packet buffer
//start HFCLK
NRF_CLOCK
->
TASKS_HFCLKSTART
=
1
;
while
(
!
(
NRF_CLOCK
->
HFCLKSTAT
&
CLOCK_HFCLKSTAT_STATE_Msk
));
//wait for hfclk to start
delay
(
10
);
}
void
uart_setup
(){
//serial for debug
//TODO: switch to UARTE (uart with dma)
void
radio_wait_for_end
(){
while
(
!
(
NRF_RADIO
->
EVENTS_END
));
NRF_RADIO
->
EVENTS_END
=
0
;}
//clear end event
void
radio_wait_for_ready
(){
while
(
!
(
NRF_RADIO
->
EVENTS_READY
));
NRF_RADIO
->
EVENTS_READY
=
0
;}
//clear ready event
void
radio_disable
(){
NRF_RADIO
->
EVENTS_DISABLED
=
0
;
//clear disabled event
NRF_RADIO
->
TASKS_DISABLE
=
1
;
while
(
!
(
NRF_RADIO
->
EVENTS_DISABLED
));
}
void
radio_send
(){
NRF_RADIO
->
EVENTS_READY
=
0
;
//clear ready event
NRF_RADIO
->
TASKS_TXEN
=
1
;
//trigger tx enable task
delayMicroseconds
(
15
);
//radio_wait_for_ready(); //only generated when actually switching to tx mode
NRF_RADIO
->
TASKS_START
=
1
;
//start
radio_wait_for_end
();
}
void
radio_recv
(){
NRF_RADIO
->
EVENTS_READY
=
0
;
//clear ready event
NRF_RADIO
->
TASKS_RXEN
=
1
;
//trigger rx enable task
delayMicroseconds
(
15
);
//radio_wait_for_ready(); //only generated when actually switching to rx mode
NRF_RADIO
->
TASKS_START
=
1
;
radio_wait_for_end
();
}
//
//UARTE
//
void
uarte_setup
(){
//uart with dma
NRF_UARTE0
->
PSEL
.
TXD
=
(
pin_tx
<<
UARTE_PSEL_TXD_PIN_Pos
)
&
UARTE_PSEL_TXD_PIN_Msk
;
NRF_UARTE0
->
PSEL
.
RXD
=
(
pin_rx
<<
UARTE_PSEL_RXD_PIN_Pos
)
&
UARTE_PSEL_RXD_PIN_Msk
;
NRF_UARTE0
->
CONFIG
=
((
UART_CONFIG_PARITY_Excluded
<<
UARTE_CONFIG_PARITY_Pos
)
&
UARTE_CONFIG_PARITY_Msk
)
|
((
UARTE_CONFIG_HWFC_Disabled
<<
UARTE_CONFIG_HWFC_Pos
)
&
UARTE_CONFIG_HWFC_Msk
);
NRF_UARTE0
->
BAUDRATE
=
UART
E_BAUDRATE_BAUDRATE_Baud115200
;
NRF_UARTE0
->
BAUDRATE
=
UART
_BAUDRATE_BAUDRATE_Baud1M
;
NRF_UARTE0
->
ENABLE
=
(
UARTE_ENABLE_ENABLE_Enabled
<<
UARTE_ENABLE_ENABLE_Pos
)
&
UARTE_ENABLE_ENABLE_Msk
;
//NRF_UARTE0->RXD.PTR = (uint32_t)((uint8_t *) rxBuffer);
//NRF_UARTE0->RXD.MAXCNT = sizeof(rxBuffer);
//NRF_UARTE0->TASKS_STARTRX = 1;
//NRF_UART0->EVENTS_RXDRDY = 0x0UL;
//NRF_UART0->EVENTS_TXDRDY = 0x0UL;
//NRF_UART0->TASKS_STARTRX = 0x1UL;
//NRF_UART0->TASKS_STARTTX = 0x1UL;
NRF_UARTE0
->
TXD
.
MAXCNT
=
N_SAMPLES
;
}
void
setup
()
{
uart_setup
();
//adc_setup();
//timer_setup();
//start a conversion
/*NRF_SAADC->TASKS_START = 0x01UL;
while (!NRF_SAADC->EVENTS_STARTED); NRF_SAADC->EVENTS_STARTED = 0x00UL;
//Serial.println("started");
NRF_SAADC->TASKS_SAMPLE = 0x01UL;
while (!NRF_SAADC->EVENTS_END); NRF_SAADC->EVENTS_END = 0x00UL;
//Serial.println("ended");
NRF_SAADC->TASKS_STOP = 0x01UL;
while (!NRF_SAADC->EVENTS_STOPPED); NRF_SAADC->EVENTS_STOPPED = 0x00UL;
*/
txBuffer
[
0
]
=
50
;
txBuffer
[
1
]
=
10
;
//uarte_setup();
adc_setup
();
radio_setup
();
while
(
true
){
NRF_UARTE0
->
TXD
.
PTR
=
(
uint32_t
)((
uint8_t
*
)
txBuffer
);
NRF_UARTE0
->
TXD
.
MAXCNT
=
2
;
//sizeof(txBuffer);
NRF_UARTE0
->
TASKS_STARTTX
=
1
;
if
(
millis
()
-
last_tx_time
>
tx_period
){
take_adc_samples
();
//start a transmission of the tx buffer
//NRF_UARTE0->TXD.PTR = (uint32_t)(&data_buffer); //reset pointer to start of buffer
//NRF_UARTE0->TASKS_STARTTX = 1; //trigger start task
radio_send
();
last_tx_time
=
millis
();
//NRF_UART0->TXD = 50; //data
//while(!NRF_UART0->EVENTS_TXDRDY); NRF_UART0->EVENTS_TXDRDY = 0x0UL;
//NRF_UART0->TXD = 10; //newline
//while(!NRF_UART0->EVENTS_TXDRDY); NRF_UART0->EVENTS_TXDRDY = 0x0UL;
delay
(
100
);
}
}
/*void TIMER1_IRQHandler(void){
if(NRF_TIMER1->EVENTS_COMPARE[0] != 0)
{
NRF_TIMER1->EVENTS_COMPARE[0] = 0;
//serial message
NRF_UART0->TXD = 51;
while(!NRF_UART0->EVENTS_TXDRDY); NRF_UART0->EVENTS_TXDRDY = 0x0UL;
NRF_UART0->TXD = 10;
while(!NRF_UART0->EVENTS_TXDRDY); NRF_UART0->EVENTS_TXDRDY = 0x0UL;
}
}
*/
}
void
loop
()
{}
bc832-watt/host/watt_host.py
0 → 100644
View file @
401fb9f9
#!/usr/bin/env python
from
numpy
import
cumsum
,
asarray
,
arange
from
math
import
*
import
serial
,
time
import
struct
import
sys
import
socket
n_samples
=
6
def
read_int16
(
bytes
,
signed
=
False
):
try
:
n
=
struct
.
unpack
(
"<h"
,
bytearray
(
bytes
))[
0
]
if
signed
else
struct
.
unpack
(
"<H"
,
bytearray
(
bytes
))[
0
]
return
n
except
:
print
"not properly formatted bytes: "
,
list
(
bytes
)
return
None
def
read
(
ser
=
None
):
if
ser
is
None
:
print
"No serial connection!"
else
:
#line = bytearray()
c
=
ser
.
read
(
4
*
n_samples
)
data
=
[
read_int16
(
c
[
x
:
x
+
2
],
signed
=
True
)
for
x
in
xrange
(
0
,
4
*
n_samples
,
2
)]
print
data
def
main
():
try
:
ser
=
serial
.
Serial
(
port
=
'/dev/tty.usbserial-FT9L3KWR'
,
baudrate
=
1000000
,
timeout
=
1.
)
ser
.
isOpen
()
print
"Established serial connection."
except
(
OSError
):
#no serial port
print
"Couldn't find the serial port, entering debug mode."
ser
=
None
ser
.
flush
()
#clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#clientsocket.bind(('localhost', 8080))
#print "Established socket"
while
True
:
#connection, address = serversocket.accept()
try
:
data
=
read
(
ser
=
ser
)
except
(
KeyboardInterrupt
):
break
#if data:
# clientsocket.send(data)
print
"quitting"
if
__name__
==
'__main__'
:
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment