Si4463 Radio Library for AVR and Arduino
1.0
|
#include <stdint.h>
#include "Si446x_config.h"
Go to the source code of this file.
Data Structures | |
struct | si446x_info_t |
Data structure for storing chip info from Si446x_getInfo() More... | |
Macros | |
#define | SI446X_MAX_PACKET_LEN 128 |
Maximum packet length. More... | |
#define | SI446X_MAX_TX_POWER 127 |
Maximum TX power (+20dBm/100mW) More... | |
#define | SI446X_WUT_RUN 1 |
Wake the microcontroller when the WUT expires. More... | |
#define | SI446X_WUT_BATT 2 |
Take a battery measurement when the WUT expires. More... | |
#define | SI446X_WUT_RX 4 |
Go into RX mode for LDC time (not supported yet!) More... | |
#define | SI446X_GPIO_PULL_EN 0x40 |
Pullup enable for GPIO pins. More... | |
#define | SI446X_GPIO_PULL_DIS 0x00 |
Pullup disable for GPIO pins. More... | |
#define | SI446X_NIRQ_PULL_EN 0x40 |
Pullup enable for NIRQ pin. More... | |
#define | SI446X_NIRQ_PULL_DIS 0x00 |
Pullup disable for NIRQ pin. More... | |
#define | SI446X_SDO_PULL_EN 0x40 |
Pullup enable for SDO pin. More... | |
#define | SI446X_SDO_PULL_DIS 0x00 |
Pullup disable for SDO pin. More... | |
#define | SI446X_PIN_PULL_EN 0x40 |
Pullup enable for any pin. More... | |
#define | SI446X_PIN_PULL_DIS 0x00 |
Pullup disable for any pin. More... | |
#define | SI446X_GPIO_DRV_HIGH 0x00 |
GPIO drive strength high. More... | |
#define | SI446X_GPIO_DRV_MED_HIGH 0x20 |
GPIO drive strength medium-high. More... | |
#define | SI446X_GPIO_DRV_MED_LOW 0x40 |
GPIO drive strength medium-low. More... | |
#define | SI446X_GPIO_DRV_LOW 0x60 |
GPIO drive strength low. More... | |
#define | SI446X_PROP_GROUP_GLOBAL 0x00 |
Property group global. More... | |
#define | SI446X_PROP_GROUP_INT 0x01 |
Property group interrupts. More... | |
#define | SI446X_PROP_GROUP_FRR 0x02 |
Property group fast response registers. More... | |
#define | SI446X_PROP_GROUP_PREAMBLE 0x10 |
Property group preamble. More... | |
#define | SI446X_PROP_GROUP_SYNC 0x11 |
Property group sync. More... | |
#define | SI446X_PROP_GROUP_PKT 0x12 |
Property group packet config. More... | |
#define | SI446X_PROP_GROUP_MODEM 0x20 |
Property group modem. More... | |
#define | SI446X_PROP_GROUP_MODEM_CHFLT 0x21 |
Property group RX coefficients. More... | |
#define | SI446X_PROP_GROUP_PA 0x22 |
Property group power amp. More... | |
#define | SI446X_PROP_GROUP_SYNTH 0x23 |
Property group synthesizer. More... | |
#define | SI446X_PROP_GROUP_MATCH 0x30 |
Property group address match. More... | |
#define | SI446X_PROP_GROUP_FREQ_CONTROL 0x40 |
Property group frequency control. More... | |
#define | SI446X_PROP_GROUP_RX_HOP 0x50 |
Property group RX hop. More... | |
#define | SI446X_PROP_GROUP_PTI 0xF0 |
Property group packet trace interface. More... | |
#define | SI446X_CBS_SENT _BV(5+8) |
Enable/disable packet sent callback. More... | |
#define | SI446X_CBS_RXBEGIN _BV(0) |
Enable/disable packet receive begin callback. More... | |
#define | SI446X_NO_INTERRUPT() |
Disable Si446x interrupts for code inside this block. More... | |
Functions | |
void | Si446x_init (void) |
Initialise, must be called before anything else! More... | |
void | Si446x_getInfo (si446x_info_t *info) |
Get chip info, see si446x_info_t. More... | |
int16_t | Si446x_getRSSI (void) |
Get the current RSSI, the chip needs to be in receive mode for this to work. More... | |
void | Si446x_setTxPower (uint8_t pwr) |
Set the transmit power. The output power does not follow the pwr value, see the Si446x datasheet for a pretty graph. More... | |
void | Si446x_setupCallback (uint16_t callbacks, uint8_t state) |
Enable or disable callbacks. This is mainly to configure what events should wake the microcontroller up. More... | |
void | Si446x_read (void *buff, uint8_t len) |
Read received data from FIFO. More... | |
uint8_t | Si446x_TX (void *packet, uint8_t len, uint8_t channel, si446x_state_t onTxFinish) |
Transmit a packet. More... | |
void | Si446x_RX (uint8_t channel) |
Enter receive mode. More... | |
void | Si446x_setLowBatt (uint16_t voltage) |
Set the low battery voltage alarm. More... | |
void | Si446x_setupWUT (uint8_t r, uint16_t m, uint8_t ldc, uint8_t config) |
Configure the wake up timer. More... | |
void | Si446x_disableWUT (void) |
Disable the wake up timer. More... | |
uint8_t | Si446x_sleep (void) |
Enter sleep mode. More... | |
si446x_state_t | Si446x_getState (void) |
Get the radio status. More... | |
uint16_t | Si446x_adc_gpio (uint8_t pin) |
Read pin ADC value. More... | |
uint16_t | Si446x_adc_battery (void) |
Read supply voltage. More... | |
float | Si446x_adc_temperature (void) |
Read temperature. More... | |
void | Si446x_writeGPIO (si446x_gpio_t pin, uint8_t value) |
Configure GPIO/NIRQ/SDO pin. More... | |
uint8_t | Si446x_readGPIO (void) |
Read GPIO pin states. More... | |
uint8_t | Si446x_dump (void *buff, uint8_t group) |
Get all values of a property group. More... | |
void | Si446x_SERVICE (void) |
If interrupts are disabled (::SI446X_INTERRUPTS in Si446x_config.h) then this function should be called as often as possible to process any events. More... | |
uint8_t | Si446x_irq_off (void) |
When using interrupts use this to disable them for the Si446x. More... | |
void | Si446x_irq_on (uint8_t origVal) |
When using interrupts use this to re-enable them for the Si446x. More... | |
#define SI446X_CBS_RXBEGIN _BV(0) |
Enable/disable packet receive begin callback.
#define SI446X_CBS_SENT _BV(5+8) |
Enable/disable packet sent callback.
#define SI446X_GPIO_DRV_HIGH 0x00 |
GPIO drive strength high.
#define SI446X_GPIO_DRV_LOW 0x60 |
GPIO drive strength low.
#define SI446X_GPIO_DRV_MED_HIGH 0x20 |
GPIO drive strength medium-high.
#define SI446X_GPIO_DRV_MED_LOW 0x40 |
GPIO drive strength medium-low.
#define SI446X_GPIO_PULL_DIS 0x00 |
Pullup disable for GPIO pins.
#define SI446X_GPIO_PULL_EN 0x40 |
Pullup enable for GPIO pins.
#define SI446X_MAX_PACKET_LEN 128 |
Maximum packet length.
#define SI446X_MAX_TX_POWER 127 |
Maximum TX power (+20dBm/100mW)
#define SI446X_NIRQ_PULL_DIS 0x00 |
Pullup disable for NIRQ pin.
#define SI446X_NIRQ_PULL_EN 0x40 |
Pullup enable for NIRQ pin.
#define SI446X_NO_INTERRUPT | ( | ) |
Disable Si446x interrupts for code inside this block.
When communicating with other SPI devices on the same bus as the radio then you should wrap those sections in a SI446X_NO_INTERRUPT() block, this will stop the Si446x interrupt from running and trying to use the bus at the same time. This macro is based on the code from avr/atomic.h, and wraps the Si446x_irq_off() and Si446x_irq_on() functions instead of messing with global interrupts. It is safe to return, break or continue inside an SI446X_NO_INTERRUPT() block.
Example:
Si446x_RX(63);
SI446X_NO_INTERRUPT()
{
OLED.write("blah", 2, 10); // Communicate with SPI OLED display
}
#define SI446X_PIN_PULL_DIS 0x00 |
Pullup disable for any pin.
#define SI446X_PIN_PULL_EN 0x40 |
Pullup enable for any pin.
#define SI446X_PROP_GROUP_FREQ_CONTROL 0x40 |
Property group frequency control.
#define SI446X_PROP_GROUP_FRR 0x02 |
Property group fast response registers.
#define SI446X_PROP_GROUP_GLOBAL 0x00 |
Property group global.
#define SI446X_PROP_GROUP_INT 0x01 |
Property group interrupts.
#define SI446X_PROP_GROUP_MATCH 0x30 |
Property group address match.
#define SI446X_PROP_GROUP_MODEM 0x20 |
Property group modem.
#define SI446X_PROP_GROUP_MODEM_CHFLT 0x21 |
Property group RX coefficients.
#define SI446X_PROP_GROUP_PA 0x22 |
Property group power amp.
#define SI446X_PROP_GROUP_PKT 0x12 |
Property group packet config.
#define SI446X_PROP_GROUP_PREAMBLE 0x10 |
Property group preamble.
#define SI446X_PROP_GROUP_PTI 0xF0 |
Property group packet trace interface.
#define SI446X_PROP_GROUP_RX_HOP 0x50 |
Property group RX hop.
#define SI446X_PROP_GROUP_SYNC 0x11 |
Property group sync.
#define SI446X_PROP_GROUP_SYNTH 0x23 |
Property group synthesizer.
#define SI446X_SDO_PULL_DIS 0x00 |
Pullup disable for SDO pin.
#define SI446X_SDO_PULL_EN 0x40 |
Pullup enable for SDO pin.
#define SI446X_WUT_BATT 2 |
Take a battery measurement when the WUT expires.
#define SI446X_WUT_RUN 1 |
Wake the microcontroller when the WUT expires.
#define SI446X_WUT_RX 4 |
Go into RX mode for LDC time (not supported yet!)
enum si446x_gpio_mode_t |
GPIO pin modes (see the Si446x API docs for what they all mean)
enum si446x_gpio_t |
GPIOs for passing to Si446x_writeGPIO(), or for masking when reading from Si446x_readGPIO()
Enumerator | |
---|---|
SI446X_GPIO0 | GPIO 1. |
SI446X_GPIO1 | GPIO 2. |
SI446X_GPIO2 | GPIO 3. |
SI446X_GPIO3 | GPIO 4. |
SI446X_NIRQ | NIRQ. |
SI446X_SDO | SDO. |
enum si446x_nirq_mode_t |
NIRQ pin modes (see the Si446x API docs for what they all mean)
enum si446x_sdo_mode_t |
SDO pin modes (see the Si446x API docs for what they all mean)
enum si446x_state_t |
Radio states, returned from Si446x_getState()
Enumerator | |
---|---|
SI446X_STATE_NOCHANGE | |
SI446X_STATE_SLEEP | This will never be returned since SPI activity will wake the radio into SI446X_STATE_SPI_ACTIVE. |
SI446X_STATE_SPI_ACTIVE | |
SI446X_STATE_READY | |
SI446X_STATE_READY2 | Will return as SI446X_STATE_READY. |
SI446X_STATE_TX_TUNE | Will return as SI446X_STATE_TX. |
SI446X_STATE_RX_TUNE | Will return as SI446X_STATE_RX. |
SI446X_STATE_TX | |
SI446X_STATE_RX |
uint16_t Si446x_adc_battery | ( | void | ) |
Read supply voltage.
uint16_t Si446x_adc_gpio | ( | uint8_t | pin | ) |
Read pin ADC value.
[pin] | The GPIO pin number (0 - 3) |
float Si446x_adc_temperature | ( | void | ) |
Read temperature.
void Si446x_disableWUT | ( | void | ) |
Disable the wake up timer.
uint8_t Si446x_dump | ( | void * | buff, |
uint8_t | group | ||
) |
Get all values of a property group.
[buff] | Pointer to memory to place group values, if this is NULL then nothing will be dumped, just the group size is returned |
[group] | The group to dump |
void Si446x_getInfo | ( | si446x_info_t * | info | ) |
Get chip info, see si446x_info_t.
[info] | Pointer to allocated si446x_info_t struct to place data into |
int16_t Si446x_getRSSI | ( | void | ) |
Get the current RSSI, the chip needs to be in receive mode for this to work.
si446x_state_t Si446x_getState | ( | void | ) |
void Si446x_init | ( | void | ) |
Initialise, must be called before anything else!
uint8_t Si446x_irq_off | ( | void | ) |
When using interrupts use this to disable them for the Si446x.
Ideally you should wrap sensitive sections with SI446X_NO_INTERRUPT() instead, as it automatically deals with this function and Si446x_irq_on()
void Si446x_irq_on | ( | uint8_t | origVal | ) |
When using interrupts use this to re-enable them for the Si446x.
Ideally you should wrap sensitive sections with SI446X_NO_INTERRUPT() instead, as it automatically deals with this function and Si446x_irq_off()
[origVal] | The original interrupt status returned from Si446x_irq_off() |
void Si446x_read | ( | void * | buff, |
uint8_t | len | ||
) |
Read received data from FIFO.
[buff] | Pointer to buffer to place data |
[len] | Number of bytes to read, make sure not to read more bytes than what the FIFO has stored. The number of bytes that can be read is passed in the ::SI446X_CB_RXCOMPLETE() callback. |
uint8_t Si446x_readGPIO | ( | void | ) |
Read GPIO pin states.
void Si446x_RX | ( | uint8_t | channel | ) |
Enter receive mode.
Entering RX mode will abort any transmissions happening at the time
[channel] | Channel to listen to (0 - 255) |
void Si446x_SERVICE | ( | void | ) |
If interrupts are disabled (::SI446X_INTERRUPTS in Si446x_config.h) then this function should be called as often as possible to process any events.
void Si446x_setLowBatt | ( | uint16_t | voltage | ) |
Set the low battery voltage alarm.
The ::SI44653_CB_LOWBATT() callback will be ran when the supply voltage drops below this value. The WUT must be configured with Si446x_setupWUT() to enable periodically checking the battery level.
[voltage] | The low battery threshold in millivolts (1050 - 3050). |
void Si446x_setTxPower | ( | uint8_t | pwr | ) |
Set the transmit power. The output power does not follow the pwr
value, see the Si446x datasheet for a pretty graph.
0 = -32dBm (<1uW)
7 = 0dBm (1mW)
12 = 5dBm (3.2mW)
22 = 10dBm (10mW)
40 = 15dBm (32mW)
100 = 20dBm (100mW)
[pwr] | A value from 0 to 127 |
void Si446x_setupCallback | ( | uint16_t | callbacks, |
uint8_t | state | ||
) |
Enable or disable callbacks. This is mainly to configure what events should wake the microcontroller up.
[callbacks] | The callbacks to configure (multiple callbacks should be bitewise OR'd together) |
[state] | Enable or disable the callbacks passed in callbacks parameter (1 = Enable, 0 = Disable) |
void Si446x_setupWUT | ( | uint8_t | r, |
uint16_t | m, | ||
uint8_t | ldc, | ||
uint8_t | config | ||
) |
Configure the wake up timer.
This function will also reset the timer.
The Wake Up Timer (WUT) can be used to periodically run a number of features:
SI446X_WUT_RUN Simply wake up the microcontroller when the WUT expires and run the ::SI446X_CB_WUT() callback.
SI446X_WUT_BATT Check battery voltage - If the battery voltage is below the threshold set by Si446x_setLowBatt() then wake up the microcontroller and run the ::SI44653_CB_LOWBATT() callback.
SI446X_WUT_RX Enter receive mode for a length of time determinded by the ldc and r parameters (NOT SUPPORTED YET! dont use this option)
For more info see the GLOBAL_WUT_M, GLOBAL_WUT_R and GLOBAL_WUT_LDC properties in the Si446x API docs.
[r] | Exponent value for WUT and LDC (Maximum valus is 20) |
[m] | Mantissia value for WUT |
[ldc] | Mantissia value for LDC (NOT SUPPORTED YET, just pass 0 for now) |
[config] | Which WUT features to enable SI446X_WUT_RUN SI446X_WUT_BATT SI446X_WUT_RX These can be bitwise OR'ed together to enable multiple features. |
uint8_t Si446x_sleep | ( | void | ) |
Enter sleep mode.
If WUT is enabled then the radio will keep the internal 32KHz RC enabled with a current consumption of 740nA, otherwise the current consumption will be 40nA without WUT. Sleep will fail if the radio is currently transmitting.
uint8_t Si446x_TX | ( | void * | packet, |
uint8_t | len, | ||
uint8_t | channel, | ||
si446x_state_t | onTxFinish | ||
) |
Transmit a packet.
[packet] | Pointer to packet data |
[len] | Number of bytes to transmit, maximum of SI446X_MAX_PACKET_LEN |
[channel] | Channel to transmit data on (0 - 255) |
[onTxFinish] | What state to enter when the packet has finished transmitting. Usually SI446X_STATE_SLEEP or SI446X_STATE_RX |
void Si446x_writeGPIO | ( | si446x_gpio_t | pin, |
uint8_t | value | ||
) |
Configure GPIO/NIRQ/SDO pin.
[pin] | The pin, this can only take a single pin (don't use bitwise OR), see si446x_gpio_t |
[value] | The new pin mode, this can be bitwise OR'd with the SI446X_PIN_PULL_EN option, see si446x_gpio_mode_t si446x_nirq_mode_t si446x_sdo_mode_t |