In this article:
Hardware interface related API.
Module pins
Module I/O pin definitions.
enumModulePinDef
| Values | Descriptions |
|---|---|
| PIN_BAND | read-only |
| PIN_ADC1 | |
| PIN_ADC0 | |
| PIN_PULSE1 | |
| PIN_PULSE0 | |
| PIN_UART0_RTS | |
| PIN_GPIO2 | |
| PIN_GPIO3 | |
| PIN_RF_EN | read-only |
| PIN_SPI_CS | |
| PIN_SPI_SCK | |
| PIN_SPI_MISO | |
| PIN_SPI_MOSI | |
| PIN_GPIO0_WKUP | |
| PIN_GPIO4 | |
| PIN_GPIO5 | |
| PIN_GPIO6 | |
| PIN_GPIO1_WKUP | |
| PIN_UART1_RX | |
| PIN_UART1_TX | |
| PIN_I2C_SCL | |
| PIN_I2C_SDA | |
| PIN_GPIO8 | |
| PIN_GPIO7 | |
| PIN_UART0_CTS | |
| PIN_UART0_TX | |
| PIN_UART0_RX | |
| PIN_LEUART_RX | |
| PIN_LEUART_TX | |
| PIN_MAX |
Module pin definitions.
ADC
PinNum can be PIN_ADC0 or PIN_ADC1.
enumADCReference
| Values | Descriptions |
|---|---|
| ADC_REF_VIO | use VIO_REF as reference voltage |
| ADC_REF_2V5 | use 2.5V as reference voltage |
| ADC_REF_1V25 | use 1.25V as reference voltage |
Reference voltages.
intADCGetVoltage(uint8_t PinNum,ADCReferenceReference,uint32_t * mV)
Get the converted voltage (mV) from the MCU ADC port.
Returns 0 if read succeeds and -1 if read fails.
intADCGetValue(uint8_t PinNum,ADCReferenceReference,uint16_t * Value)
Get raw value from the ADC port (0 - 0xFFF).
Returns 0 if read succeeds and -1 if read fails.
I²C master
enumI2COption
| Values | Descriptions |
|---|---|
| I2C_DEFAULT_OPTIONS | |
| I2C_FAST_MODE | ~400 kbit/s, default standard mode (~100 kbit/s) |
I²C options, can be ORed.
intI2CInit(void)
Initialise I²C bus.
Returns 0 if initialisation succeeds and -1 if initialisation fails.
intI2CInitEx(uint32_t Option)
Initialise I²C bus with options.
Returns 0 if initialisation succeeds and -1 if initialisation fails.
voidI2CDeinit(void)
Deinitialise I²C bus.
intI2CWrite(uint16_t DeviceAddress,const uint8_t * Command,size_t CommandLength)
Write to an I²C device synchronously.
Returns 0 if write succeeds and -1 if read fails.
intI2CRead(uint16_t DeviceAddress,const uint8_t * Command,size_t CommandLength,uint8_t * Rx,size_t RxLength)
Read from an I²C device.
Returns 0 if read succeeds and -1 if read fails.
SPI master
enumSPIBaudrate
| Values | Descriptions |
|---|---|
| SPI_BAUDRATE_DEFAULT | default SPI baudrate |
| SPI_BAUDRATE_MAX | maximum SPI baudrate |
SPI baudrate.
intSPIInit(uint32_t BaudRate)
Initialise SPI master.
Returns 0 if initialisation succeeds and -1 if initialisation fails.
voidSPIDeinit(void)
Deinitialise SPI master.
intSPIWrite(const uint8_t * Tx,size_t Length)
Write to an SPI device synchronously.
Returns 0 if write succeeds and -1 if write fails.
intSPITransfer(const uint8_t * Tx,uint8_t * Rx,size_t Length)
SPI data transfer.
Returns 0 if transfer succeeds and -1 if transfer fails.
GPIO
PinNum can be any pin in ModulePinDef.
enumGPIOLevel
| Values | Descriptions |
|---|---|
| GPIO_LOW | |
| GPIO_HIGH |
GPIO level.
enumGPIOPull
| Values | Descriptions |
|---|---|
| GPIO_NO_PULL | no module internal pull up or pull down |
| GPIO_PULL_UP | module internal pull up |
| GPIO_PULL_DOWN | module internal pull down |
GPIO internal pull up/down.
intGPIOSetModeInput(uint8_t PinNum,GPIOPullPull)
Set a GPIO to input mode and the internal pull up/down.
Returns 0 if succeeded and -1 if failed.
intGPIOSetModeOutput(uint8_t PinNum)
Set a GPIO to output mode.
Returns 0 if succeeded and -1 if failed.
intGPIOSetHigh(uint8_t PinNum)
Set a GPIO output high.
Returns 0 if succeeded and -1 if failed.
intGPIOSetLow(uint8_t PinNum)
Set a GPIO output low.
Returns 0 if succeeded and -1 if failed.
intGPIOGet(uint8_t PinNum)
Get input level of a GPIO.
Returns GPIOLevel if succeeded and -1 if failed.
intGPIOSetWakeupLevel(uint8_t PinNum,GPIOLevelLevel)
Set level polarity of a GPIO pin with wakeup capability for next wakeup.
Make sure to set the GPIO to input mode. Returns 0 if succeeded and -1 if failed.
intGPIODisableWakeup(uint8_t PinNum)
Disable wakeup capability of a GPIO pin.
UART
enumUARTInterface
| Values | Descriptions |
|---|---|
| UART_0 | can be used for firmware update via the bootloader |
| UART_1 | used by GNSS |
| LEUART | low energy, only supports baudrate up to 9600 |
UART interfaces.
void *UARTInit(UARTInterfaceUARTNum,uint32_t BaudRate,uint32_t Options)
Initialise a uart interface, options are not supported and should be 0.
UARTNum is the UART number defined by enum UARTInterface. Returns the handle if succeeded and NULL if failed.
voidUARTDeinit(void * Handle)
Deintialise a UART interface.
intUARTWrite(void * Handle,const uint8_t * Tx,size_t Length)
Write to a UART interface synchronously.
Returns 0 if write succeeds and -1 if read fails.
intUARTRead(void * Handle,uint8_t * Rx,size_t Length)
Read from input buffer of a UART interface.
The buffer size is 50 bytes. Returns number of bytes read back and -1 if read fails.
Pulse counter
enumPulseCounterOption
| Values | Descriptions |
|---|---|
| PCNT_DEFAULT_OPTIONS | |
| PCNT_EDGE_FALLING | count on falling edge, default rising edge |
| PCNT_DEBOUNCE_DISABLE | disable hardware debouncing, default enabled for about 160us |
| PCNT_PULL_UP | enable pull-up, default pull-down |
Pulse counter bit-wise options, can be ORed.
intPulseCounterInit(uint32_t Limit,uint32_t Options)
Initialise the pulse counter and configure the event generation logic.
Event is generated when pulse count hits multiple of Limit. Limit can be set to 0 to 256, or multiple of 256. Set Limit to 0 to disable event generation. Options are used to configure the pulse counter. Set option to 0 to count on rising edge, and enable debouncing. Returns 0 if succeeded and -1 if failed.
uint64_tPulseCounterGet(void)
Get the total count of the pulse counter.
Returns the total count.
voidPulseCounterDeinit(void)
Deinitialise the pulse counter.
Satellite radio RF test
enumRFTestTxType
| Values | Descriptions |
|---|---|
| TX_TYPE_TONE | transmit tone, i.e. CW |
| TX_TYPE_PRBS | transmit pseudorandom binary sequence |
RF test Tx type.
intRFTestTxStart(uint32_t Frequency,uint8_t TxType,bool IsBurst)
Start the RF Tx test.
The default LED is on when transmitting. The antenna port should be connected to a load when testing. Frequency is in Hertz. TxType can be tone or pseudorandom binary sequence defined by RFTestTxType. When testing in burst mode, the radio is on for 260ms and off for 1740ms. Otherwise the radio transmits continuously. Returns 0 if succeeded and -1 if failed.
voidRFTestTxStop(void)
Stop the RF Tx test.
intRFTestRxStart(uint32_t Frequency)
Turn on the satellite radio receiver.
Frequency is in Hertz. Returns 0 if succeeded and -1 if failed.
intRFTestRxRSSI(int32_t * RSSI)
Get current RSSI from radio receiver.
RSSI is in dBm. Returns 0 if succeeded and -1 if failed.
voidRFTestRxStop(void)
Stop the RF Rx test.
Satellite radio statistics
voidRxStatsGet(void * Stats)
Get satellite radio receiver (downlink) statistics. Two values are returned in SDK 2+:
/// Rx stats type, both counters exclude messages sent to the device by the user
typedef struct {
uint16_t attempts; ///< Number of attempts made to receive a packet
uint16_t successes; ///< Number of successful packets
} RxStats_t;
and three in SDK 1.5.6:
typedef struct {
uint16_t attempts; ///< Number of attempts made to receive a packet
uint16_t unverified; ///< Number of packets failed signature verification
uint16_t verified; ///< Number of successful packets
} RxStats_t;
User NVRAM (persistent storage)
#defineNVRAM_MEM_SIZE2048
voidNvramClear()
Clear the NVRAM.
NVRAM should be cleared before overwriting the existing contents. The NVRAM is filled with 0xFF after being cleared.
intNvramWrite(uint32_t Offset,const uint8_t * Buf,size_t Length)
Write buffer contents to NVRAM, starting from offset.
Returns 0 if succeeded and -1 if failed.
