Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
ring
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pub
ring
Commits
62949338
There was a problem fetching the pipeline summary.
Commit
62949338
authored
8 years ago
by
Sam Calisch
Browse files
Options
Downloads
Patches
Plain Diff
update nrf24 ring
parent
1a29ff6f
Branches
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
radio/nrf24L01/nrf-ftdi-ring.c
+37
-76
37 additions, 76 deletions
radio/nrf24L01/nrf-ftdi-ring.c
radio/nrf24L01/ring.png
+0
-0
0 additions, 0 deletions
radio/nrf24L01/ring.png
radio/nrf24L01/ring2.png
+0
-0
0 additions, 0 deletions
radio/nrf24L01/ring2.png
with
37 additions
and
76 deletions
radio/nrf24L01/nrf-ftdi-ring.c
+
37
−
76
View file @
62949338
...
@@ -69,6 +69,7 @@ uint8_t read_register(uint8_t reg){
...
@@ -69,6 +69,7 @@ uint8_t read_register(uint8_t reg){
return
temp
;
return
temp
;
}
}
void
write_register
(
uint8_t
reg
,
uint8_t
val
){
void
write_register
(
uint8_t
reg
,
uint8_t
val
){
//must be in standby mode before calling this function!
PORTC
.
OUTCLR
=
SS_BM
;
//SS low
PORTC
.
OUTCLR
=
SS_BM
;
//SS low
_delay_us
(
1
);
_delay_us
(
1
);
SPIC
.
DATA
=
W_REGISTER
|
reg
;
while
(
!
(
SPIC
.
STATUS
&
SPI_IF_bm
))
{};
SPIC
.
DATA
=
W_REGISTER
|
reg
;
while
(
!
(
SPIC
.
STATUS
&
SPI_IF_bm
))
{};
...
@@ -77,18 +78,18 @@ void write_register(uint8_t reg, uint8_t val){
...
@@ -77,18 +78,18 @@ void write_register(uint8_t reg, uint8_t val){
_delay_us
(
1
);
_delay_us
(
1
);
}
}
USART_data_t
USART_data
;
USART_data_t
USART_data
;
uint8_t
token
=
0
;
//token to pass
uint8_t
token
=
0
;
//token to pass
uint8_t
tempval
=
0
;
uint8_t
tempval
=
0
;
const
int
pll_delay_us
=
130
;
const
int
pll_delay_us
=
130
;
const
int
ce_delay_us
=
10
;
void
check_registers
(
uint8_t
id
){
void
check_registers
(
uint8_t
id
){
//debug only
//
for
debug only
//enter standby so we can write to configuration register.
//enter standby so we can write to configuration register.
PORTC
.
OUTCLR
=
CE_BM
;
PORTC
.
OUTCLR
=
CE_BM
;
_delay_us
(
10
);
_delay_us
(
ce_delay_us
);
PORTC
.
OUTCLR
=
SS_BM
;
//SS low
PORTC
.
OUTCLR
=
SS_BM
;
//SS low
_delay_us
(
10
);
_delay_us
(
10
);
...
@@ -104,63 +105,16 @@ void check_registers(uint8_t id){
...
@@ -104,63 +105,16 @@ void check_registers(uint8_t id){
usart_send_byte
(
&
USART_data
,
config
);
usart_send_byte
(
&
USART_data
,
config
);
usart_send_byte
(
&
USART_data
,
token
);
usart_send_byte
(
&
USART_data
,
token
);
usart_send_byte
(
&
USART_data
,
10
);
usart_send_byte
(
&
USART_data
,
10
);
//interrupts
/*if (!(PORTC.IN & IRQ_BM)){
usart_send_byte(&USART_data,1);
}
//clear interrupt on MAX_RT
PORTC.OUTCLR = SS_BM; //SS low
_delay_ms(1);
SPIC.DATA = W_REGISTER | STATUS; while(!(SPIC.STATUS & SPI_IF_bm)) {};
SPIC.DATA |= MAX_RT; while(!(SPIC.STATUS & SPI_IF_bm)) {}; //write 1 to MAX_RT bit
PORTC.OUTSET = SS_BM; //SS high
_delay_ms(1);
//interrupts
if (!(PORTC.IN & IRQ_BM)){
usart_send_byte(&USART_data,2);
}*/
}
}
// nRF24L01+ must be in a standby or power down mode before writing to the configuration registers.
//overview
// - turn off autoretransmit
// - MAX_RT interrupts on IRQ
// - set interrupt service routine on rising edge of IRQ (RX_DR)
// - set interrupt service routing on USART RX
// - enter RX mode PRIM_RX = 1 (SPI transaction), CE = 1
// - When IRQ interupt,
// - enter standby (CE=0)
// - read payload (SPI transaction)
// - process data and put result in TX fifo
// - enter TX (PRIM_RX=0, CE=1 for more than 10 us) (130us)
// - clear IRQ by writing 1 to STATUS register RX_DR bit. (SPI transaction)
// - set CE=0 so we return to Standby when finished transmitting
// - set PRIM_RX=1 (SPI transaction). can we only do this from standby? (130us)
// - When USART interrupt,
// - enter standby (CE=0)
// - put token in TX fifo
// - enter TX (PRIM_RX=0, CE=1 for more than 10 us)
// - set CE=0 so we return to Standby when finished transmitting
// - set PRIM_RX=1 (SPI transaction) to enter RX can we only do this from standby? (130us)
//experiments
// RF_SETUP, RF_DR_LOW, RF_DR_HIGH. Default RF data rate is 250kbps ( 4 us per byte ).
// It can also be 1 Mbps (1 us per byte) and 2 Mbps (.5 us per byte)
// increase SPI rate. right now its running at clkper/128 = sysclk/128 = 250 kHz (4 us per byte)
void
rx_from_standby
(){
void
rx_from_standby
(){
//enter standby so we can write to configuration register.
//call this from standby to enter rx mode
PORTC
.
OUTCLR
=
CE_BM
;
//tempval = read_register(CONFIG);
_delay_us
(
10
);
//should be 10?
//write_register(CONFIG, tempval | PRIM_RX);
//enter RX mode: set PRIM_RX = 1
write_register
(
CONFIG
,
0x13
);
//replaces the spi read, but doesn't really speed things up much...
tempval
=
read_register
(
CONFIG
);
write_register
(
CONFIG
,
tempval
|
PRIM_RX
)
//set CE for at least 10 us
//set CE for at least 10 us
PORTC
.
OUTSET
=
CE_BM
;
PORTC
.
OUTSET
=
CE_BM
;
_delay_us
(
10
);
//should be 10
?
//
_delay_us(
ce_delay_us); //is this necessary
?
//wait for pll to settle
//wait for pll to settle
_delay_us
(
pll_delay_us
);
_delay_us
(
pll_delay_us
);
}
}
...
@@ -200,9 +154,9 @@ void setup(){
...
@@ -200,9 +154,9 @@ void setup(){
SPIC
.
INTCTRL
=
SPI_INTLVL_OFF_gc
;
SPIC
.
INTCTRL
=
SPI_INTLVL_OFF_gc
;
PORTC
.
DIRSET
=
PIN5_bm
|
PIN7_bm
;
//mosi and sck as outputs
PORTC
.
DIRSET
=
PIN5_bm
|
PIN7_bm
;
//mosi and sck as outputs
PORTC
.
OUTSET
=
SS_BM
;
//SS high
PORTC
.
OUTSET
=
SS_BM
;
//SS high
_delay_ms
(
5
);
//warm up
_delay_ms
(
5
);
//warm up
//nrf config
//turn off auto-retransmit
//turn off auto-retransmit
write_register
(
SETUP_RETR
,
0
);
write_register
(
SETUP_RETR
,
0
);
//turn off disable auto-acknowledge
//turn off disable auto-acknowledge
...
@@ -229,48 +183,54 @@ void setup(){
...
@@ -229,48 +183,54 @@ void setup(){
_delay_ms
(
1
);
//give time to start up
_delay_ms
(
1
);
//give time to start up
// and mask MAX_RT interrupts on IRQ
// and mask MAX_RT interrupts on IRQ
tempval
=
read_register
(
CONFIG
);
tempval
=
read_register
(
CONFIG
);
write_register
(
CONFIG
,
tempval
|
MAX_RT
)
write_register
(
CONFIG
,
tempval
|
MAX_RT
)
;
//clear all interrupts
//clear all interrupts
tempval
=
read_register
(
STATUS
);
tempval
=
read_register
(
STATUS
);
write_register
(
STATUS
,
tempval
|
MAX_RT
|
RX_DR
|
TX_DS
)
write_register
(
STATUS
,
tempval
|
MAX_RT
|
RX_DR
|
TX_DS
)
;
_delay_ms
(
1
);
_delay_ms
(
1
);
sei
();
sei
();
rx_from_standby
();
//enter standby so we can write to configuration register.
PORTC
.
OUTCLR
=
CE_BM
;
_delay_us
(
ce_delay_us
);
rx_from_standby
();
//enter rx mode
}
}
void
send_token
(){
//transition from RX to standby1 (CE=0)
PORTC
.
OUTCLR
=
CE_BM
;
_delay_us
(
10
);
void
send_token
(){
//call this from standby1
//put token in tx fifo
//put token in tx fifo
PORTC
.
OUTCLR
=
SS_BM
;
//SS low
PORTC
.
OUTCLR
=
SS_BM
;
//SS low
_delay_us
(
1
);
_delay_us
(
1
);
SPIC
.
DATA
=
W_TX_PAYLOAD
;
while
(
!
(
SPIC
.
STATUS
&
SPI_IF_bm
))
{};
SPIC
.
DATA
=
W_TX_PAYLOAD
;
while
(
!
(
SPIC
.
STATUS
&
SPI_IF_bm
))
{};
SPIC
.
DATA
=
token
;
while
(
!
(
SPIC
.
STATUS
&
SPI_IF_bm
))
{};
tempval
=
SPIC
.
DATA
;
//get status while we have it
SPIC
.
DATA
=
0
;
while
(
!
(
SPIC
.
STATUS
&
SPI_IF_bm
))
{};
PORTC
.
OUTSET
=
SS_BM
;
//SS high
PORTC
.
OUTSET
=
SS_BM
;
//SS high
_delay_us
(
1
);
_delay_us
(
1
);
tempval
=
read_register
(
CONFIG
);
//
tempval = read_register(CONFIG);
write_register
(
CONFIG
,
tempval
&
(
~
PRIM_RX
))
write_register
(
CONFIG
,
tempval
&
(
~
PRIM_RX
))
;
//pulse CE
for at least 10 us
//pulse CE
PORTC
.
OUTSET
=
CE_BM
;
_delay_us
(
10
);
PORTC
.
OUTCLR
=
CE_BM
;
PORTC
.
OUTSET
=
CE_BM
;
_delay_us
(
ce_delay_us
);
PORTC
.
OUTCLR
=
CE_BM
;
//wait for pll to settle
//wait for pll to settle
_delay_us
(
pll_delay_us
);
_delay_us
(
pll_delay_us
);
//wait until transmit complete
//wait until transmit complete
while
(
PORTC
.
IN
&
IRQ_BM
){}
while
(
PORTC
.
IN
&
IRQ_BM
){}
//clear IRQ -- need to be in standby.
//clear IRQ -- need to be in standby.
tempval
=
read_register
(
STATUS
);
tempval
=
read_register
(
STATUS
);
write_register
(
STATUS
,
tempval
|
TX_DS
)
write_register
(
STATUS
,
tempval
|
TX_DS
);
//enter standby so we can write to configuration register.
rx_from_standby
();
//return to RX mode
rx_from_standby
();
//return to RX mode
}
}
void
read_token
(){
void
read_token
(){
//call this from rx
//get token from rx fifo
//get token from rx fifo
PORTC
.
OUTCLR
=
SS_BM
;
//SS low
PORTC
.
OUTCLR
=
SS_BM
;
//SS low
_delay_us
(
1
);
_delay_us
(
1
);
SPIC
.
DATA
=
R_RX_PAYLOAD
;
while
(
!
(
SPIC
.
STATUS
&
SPI_IF_bm
))
{};
SPIC
.
DATA
=
R_RX_PAYLOAD
;
while
(
!
(
SPIC
.
STATUS
&
SPI_IF_bm
))
{};
tempval
=
SPIC
.
DATA
;
//get status while we have it
SPIC
.
DATA
=
0
;
while
(
!
(
SPIC
.
STATUS
&
SPI_IF_bm
))
{};
SPIC
.
DATA
=
0
;
while
(
!
(
SPIC
.
STATUS
&
SPI_IF_bm
))
{};
token
=
SPIC
.
DATA
;
token
=
SPIC
.
DATA
;
PORTC
.
OUTSET
=
SS_BM
;
//SS high
PORTC
.
OUTSET
=
SS_BM
;
//SS high
...
@@ -278,27 +238,28 @@ void read_token(){
...
@@ -278,27 +238,28 @@ void read_token(){
//transition from RX to standby1 (CE=0)
//transition from RX to standby1 (CE=0)
PORTC
.
OUTCLR
=
CE_BM
;
PORTC
.
OUTCLR
=
CE_BM
;
_delay_us
(
10
);
_delay_us
(
ce_delay_us
);
//clear IRQ
//clear IRQ
tempval
=
read_register
(
STATUS
);
write_register
(
STATUS
,
tempval
|
RX_DR
);
write_register
(
STATUS
,
tempval
|
RX_DR
)
//check_registers(66);
//check_registers(66);
}
}
int
main
(
void
)
{
int
main
(
void
)
{
setup
();
setup
();
while
(
1
){
while
(
1
){
//should be in rx mode here.
if
(
!
(
PORTC
.
IN
&
IRQ_BM
)){
if
(
!
(
PORTC
.
IN
&
IRQ_BM
)){
read_token
();
//in standby
read_token
();
//in standby
token
=
1
-
token
;
//transform
token
token
+
=
1
;
//increment
token
//check_registers(65);
//check_registers(65);
send_token
();
send_token
();
}
}
//w
hen we get signal from usart, send a token on nrf
//w
e use a signal on the usart to start the oscillation.
if
(
USART_RXBufferData_Available
(
&
USART_data
))
{
if
(
USART_RXBufferData_Available
(
&
USART_data
))
{
USART_RXBuffer_GetByte
(
&
USART_data
);
//clear usart buffer so we only fire once.
USART_RXBuffer_GetByte
(
&
USART_data
);
//clear usart buffer so we only fire once.
//transition from RX to standby1 (CE=0)
PORTC
.
OUTCLR
=
CE_BM
;
_delay_us
(
ce_delay_us
);
send_token
();
send_token
();
//check_registers(64);
//check_registers(64);
}
}
...
...
This diff is collapsed.
Click to expand it.
radio/nrf24L01/ring.png
+
0
−
0
View replaced file @
1a29ff6f
View file @
62949338
6.51 KiB
|
W:
|
H:
6.64 KiB
|
W:
|
H:
2-up
Swipe
Onion skin
This diff is collapsed.
Click to expand it.
radio/nrf24L01/ring2.png
0 → 100755
+
0
−
0
View file @
62949338
7.25 KiB
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment