View Source Nrf24.Transciever (nrf24 v1.0.0)

Module for communicating with nRF24L01+ transciever.

It sets up device, by default, to work in ShockBurst mode with ACK (auto acknowledgement) and CRC check enabled.

Link to this section Summary

Functions

Turns auto-acknowledgement on and off.

Returns a channel on which tranciever is working.

Function prints out status of registers. Useful mostly for debugging purposes.

Reads received data of payload_size size.

Resets device to initial settings.

Resets RX and TX FIFO interrupts and maximum number of TX retrasmits.

Sends data of 1-32 bytes length. Always uses auto acknowledgment.

Sets a channel on which tranciever will receive/send data.

Sets CRC length. Allowed values are 1 or 2.

Sets the size of data to be received on the given pipe.

Sets pipe's address, payload size and enables pipe in en_rxaddr register.

Sets 5-byte address for pipes 0 and 1 (values between 0 and 255) and single byte address for pipes 2-5.

Configures transciever to receive data.

Sets a number of retransmits before trasmit is considered as failed.

Set auto Retransmit Delay ‘0000’ – Wait 250μS ‘0001’ – Wait 500μS ‘0010’ – Wait 750μS ........ ‘1111’ – Wait 4000μS (Delay defined from end of transmission to start of next transmission)

Sets data speed rate.

Sets address on which transciever will transmit data. Trasmit address is 5-bytes long and if auto-acknowledgement is turned on it has to be the same as address of the pipe 0.

Configures transciever to send data.

Configures transciever for receiving data, resets status and powers on transciever.

Powers off transciever and sets CE pin to low.

Link to this section Functions

Link to this function

ack(spi, pipe_no, on \\ true)

View Source

Turns auto-acknowledgement on and off.

Link to this function

disable_pipe(spi, pipe_no)

View Source
Link to this function

enable_pipe(spi, pipe_no)

View Source

Returns a channel on which tranciever is working.

Link to this function

read_data(spi, payload_size)

View Source

Reads received data of payload_size size.

If data is received on any pipe corresponding value in the status register will be set to pipe number and function will read data from FIFO register.

Function returns map with pipe no on which data was received and received value.

Link to this function

read_register(spi, reg, bytes_no \\ 1)

View Source

Resets device to initial settings.

Resets RX and TX FIFO interrupts and maximum number of TX retrasmits.

Link to this function

send_data(spi, data, csn_pin, ce_pin)

View Source

Sends data of 1-32 bytes length. Always uses auto acknowledgment.

Link to this function

set_channel(spi, channel)

View Source

Sets a channel on which tranciever will receive/send data.

Link to this function

set_crc_length(spi, length)

View Source

Sets CRC length. Allowed values are 1 or 2.

Link to this function

set_payload_size(spi, pipe_no, payload_size)

View Source

Sets the size of data to be received on the given pipe.

Link to this function

set_pipe(spi, pipe_no, options \\ [])

View Source

Sets pipe's address, payload size and enables pipe in en_rxaddr register.

For pipes 0 and 1 dddress must be 5 bytes length binary, i.e.

<<0xe1, 0xc0, 0x00, 0x01, 0xa0>>

For simpler, easier to remember case, address can be just a five-characters string, i.e.

"Rcvr1"

For pipes 2 to 5 address must be binary consisting of only one integer between 0 and 255.

<<0xce>>

Anything else including binary of different size will fallback to default pipe address.

options

Options

  • :address - Pipe address. For first two pipes (0 and 1) it is expected to be 5 integers binary and for pipes 2 to 5 one integer binary. Anything else will just use default pipe addresses.

  • :payload_size - Pipe payload size in bytes.

  • :auto_acknowledgement - If false auto acknowledgement for the pipe will be disabled. If nil auto acknowledgement will be enabled by default.

example

Example

# Enable pipe1 with address 0x0a0b0c0d0e and 6 bytes
# payload size
{:ok, spi} = Circuits.SPI.open("spidev0.0")
address = <<0x0a, 0x0b, 0x0c, 0x0d, 0x0e>>
Nrf24.set_pipe(spi, 1, address: address, payload_size: 6)

# Enable pipe 4 with addres 0xa7 and 12 bytes payload size
Nrf24.set_pipe(spi, 4, address: <<0xa7>>, payload_size: 12)
Link to this function

set_pipe_address(spi, pipe_no, address)

View Source

Sets 5-byte address for pipes 0 and 1 (values between 0 and 255) and single byte address for pipes 2-5.

For pipes 0 and 1 it is good practice to set mnemonic pipe address

set_pipe_address(spi, 0, "Recv1")

but address can also be set with 5-byte binary

set_pipe_address(spi, 1, <<0xe7, 0xa0, 0x17, 0x13, 0x25>>)

For pipes 2-5 address is just integer between 0 and 255

set_pipe_address(spi, 4, 147)

Configures transciever to receive data.

Link to this function

set_retransmit_count(spi, count)

View Source

Sets a number of retransmits before trasmit is considered as failed.

Link to this function

set_retransmit_delay(spi, delay)

View Source

Set auto Retransmit Delay ‘0000’ – Wait 250μS ‘0001’ – Wait 500μS ‘0010’ – Wait 750μS ........ ‘1111’ – Wait 4000μS (Delay defined from end of transmission to start of next transmission)

Please take care when setting this parameter. If the ACK payload is more than 15 byte in 2Mbps mode the ARD must be 500μS or more, if the ACK payload is more than 5byte in 1Mbps mode the ARD must be 500μS or more. In 250kbps mode (even when the payload is not in ACK) the ARD must be 500μS or more.

Sets data speed rate.

  • :low - speed 250Kbps
  • :medium - speed 1Mbps
  • :high - speed 2Mbps
Link to this function

set_transmit_address(spi, address)

View Source

Sets address on which transciever will transmit data. Trasmit address is 5-bytes long and if auto-acknowledgement is turned on it has to be the same as address of the pipe 0.

Configures transciever to send data.

Link to this function

start_listening(spi, ce_pin_no)

View Source

Configures transciever for receiving data, resets status and powers on transciever.

This function must be called before data is received.

Link to this function

start_sending(spi, address)

View Source
Link to this function

stop_listening(spi, ce_pin_no)

View Source

Powers off transciever and sets CE pin to low.

Call this function after data is received.

Link to this function

write_register(spi, reg, value)

View Source