/*!
* \file sx126x.c
*
* \brief SX126x driver implementation
*
* \copyright Revised BSD License, see section \ref LICENSE.
*
* \code
* ______ _
* / _____) _ | |
* ( (____ _____ ____ _| |_ _____ ____| |__
* \____ \| ___ | (_ _) ___ |/ ___) _ \
* _____) ) ____| | | || |_| ____( (___| | | |
* (______/|_____)_|_|_| \__)_____)\____)_| |_|
* (C)2013-2017 Semtech
*
* \endcode
*
* \author Miguel Luis ( Semtech )
*
* \author Gregory Cristian ( Semtech )
*/
#include "sys.h"
SX126x_t SX126x;
/*!
* \brief Radio registers definition
*/
typedef struct
{
uint16_t Addr; //!< The address of the register
uint8_t Value; //!< The value of the register
}RadioRegisters_t;
/*!
* \brief Holds the internal operating mode of the radio
*/
static RadioOperatingModes_t OperatingMode;
/*!
* \brief Stores the current packet type set in the radio
*/
static RadioPacketTypes_t PacketType;
/*!
* \brief Stores the last frequency error measured on LoRa received packet
*/
volatile uint32_t FrequencyError = 0;
/*!
* \brief Hold the status of the Image calibration
*/
static bool ImageCalibrated = false;
/*
* SX126x DIO IRQ callback functions prototype
*/
/*!
* \brief DIO 0 IRQ callback
*/
void SX126xOnDioIrq( void );
/*!
* \brief DIO 0 IRQ callback
*/
void SX126xSetPollingMode( void );
/*!
* \brief DIO 0 IRQ callback
*/
void SX126xSetInterruptMode( void );
/*
* \brief Process the IRQ if handled by the driver
*/
void SX126xProcessIrqs( void );
extern uint8_t gPaOptSetting;
void SX126xInit( DioIrqHandler dioIrq )
{
SX126xReset( );
SX126xIoIrqInit( dioIrq );
SX126xWakeup( );
if(0x10 == SX126xReadRegister( 0x6bE))
{
if(0x21 == SX126xReadRegister( 0x6bF))
{
}
else
{
printf("sx1262 SPI error! \r\n");
while(1);
}
}
else
{
printf("sx1262 SPI error! \r\n");
while(1);
}
SX126xSetStandby( STDBY_RC );
//printf("sx1262 SPI ok! \r\n");
//#ifdef CONFIG_32M_TCXO
//{
CalibrationParams_t calibParam;
SX126xSetDio3AsTcxoCtrl( TCXO_CTRL_3_3V, SX126xGetBoardTcxoWakeupTime( ) << 6 ); // convert from ms to SX126x time base
calibParam.Value = 0x7F;
SX126xCalibrate( calibParam );
//}
//#endif
SX126xSetDio2AsRfSwitchCtrl( true );
OperatingMode = MODE_STDBY_RC;
}
RadioOperatingModes_t SX126xGetOperatingMode( void )
{
return OperatingMode;
}
void SX126xSetOperatingMode( RadioOperatingModes_t mode )
{
OperatingMode = mode;
#if defined( USE_RADIO_DEBUG )
switch( mode )
{
case MODE_TX:
SX126xDbgPinTxWrite( 1 );
SX126xDbgPinRxWrite( 0 );
break;
case MODE_RX:
case MODE_RX_DC:
SX126xDbgPinTxWrite( 0 );
SX126xDbgPinRxWrite( 1 );
break;
default:
SX126xDbgPinTxWrite( 0 );
SX126xDbgPinRxWrite( 0 );
break;
}
#endif
}
void SX126xCheckDeviceReady( void )
{
if( ( SX126xGetOperatingMode( ) == MODE_SLEEP ) || ( SX126xGetOperatingMode( ) == MODE_RX_DC ) )
{
SX126xWakeup( );
// Switch is turned off when device is in sleep mode and turned on is all other modes
SX126xAntSwOn( );
}
SX126xWaitOnBusy( );
}
void SX126xSetPayload( uint8_t *payload, uint8_t size )
{
SX126xWriteBuffer( 0x00, payload, size );
}
uint8_t SX126xGetPayload( uint8_t *buffer, uint8_t *size, uint8_t maxSize )
{
uint8_t offset = 0;
SX126xGetRxBufferStatus( size, &offset );
if( *size > maxSize )
{
return 1;
}
SX126xReadBuffer( offset, buffer, *size );
return 0;
}
void SX126xSendPayload( uint8_t *payload, uint8_t size, uint32_t timeout )
{
SX126xSetPayload( payload, size );
SX126xSetTx( timeout );
}
uint8_t SX126xSetSyncWord( uint8_t *syncWord )
{
SX126xWriteRegisters( REG_LR_SYNCWORDBASEADDRESS, syncWord, 8 );
return 0;
}
void SX126xSetCrcSeed( uint16_t seed )
{
uint8_t buf[2];
buf[0] = ( uint8_t )( ( seed >> 8 ) & 0xFF );
buf[1] = ( uint8_t )( seed & 0xFF );
switch( SX126xGetPacketType( ) )
{
case PACKET_TYPE_GFSK:
SX126xWriteRegisters( REG_LR_CRCSEEDBASEADDR, buf, 2 );
break;
default:
break;
}
}
void SX126xSetCrcPolynomial( uint16_t polynomial )
{
uint8_t buf[2];
buf[0] = ( uint8_t )( ( polynomial >> 8 ) & 0xFF );
buf[1] = ( uint8_t )( polynomial & 0xFF );
switch( SX126xGetPacketType( ) )
{
case PACKET_TYPE_GFSK:
SX126xWriteRegisters( REG_LR_CRCPOLYBASEADDR, buf, 2 );
break;
default:
break;
}
}
void SX126xSetWhiteningSeed( uint16_t seed )
{
uint8_t regValue = 0;
switch( SX126xGetPacketType( ) )
{
case PACKET_TYPE_GFSK:
regValue = SX126xReadRegister( REG_LR_WHITSEEDBASEADDR_MSB ) & 0xFE;
regValue = ( ( seed >> 8 ) & 0x01 ) | regValue;
SX126xWriteRegister( REG_LR_WHITSEEDBASEADDR_MSB, regValue ); // only 1 bit.
SX126xWriteRegister( REG_LR_WHITSEEDBASEADDR_LSB, ( uint8_t )seed );
break;
default:
break;
}
}
uint32_t SX126xGetRandom( void )
{
uint8_t buf[] = { 0, 0, 0, 0 };
// Set radio in continuous reception
SX126xSetRx( 0 );
DelayMs( 1 );
SX126xReadRegisters( RANDOM_NUMBER_GENERATORBASEADDR, buf, 4 );
SX126xSetStandby( STDBY_RC );
return ( (uint32_t)buf[0] << 24 ) | ( (uint32_t)buf[1] << 16 ) | ( (uint32_t)buf[2] << 8 ) | (uint32_t)buf[3];
}
void SX126xSetSleep( SleepParams_t sleepConfig )
{
SX126xAntSwOff( );
SX126xWriteCommand( RADIO_SET_SLEEP, &sleepConfig.Value, 1 );
OperatingMode = MODE_SLEEP;
}
void SX126xSetStandby( RadioStandbyModes_t standbyConfig )
{
SX126xWriteCommand( RADIO_SET_STANDBY, ( uint8_t* )&standbyConfig, 1 );
if( standbyConfig == STDBY_RC )
{
OperatingMode = MODE_STDBY_RC;
}
else
{
OperatingMode = MODE_STDBY_XOSC;
}
}
void SX126xSetFs( void )
{
SX126xWriteCommand( RADIO_SET_FS, 0, 0 );
OperatingMode = MODE_FS;
}
void SX126xSetTx( uint32_t timeout )
{
uint8_t buf[3];
OperatingMode = MODE_TX;
buf[0] = ( uint8_t )( ( timeout >> 16 ) & 0xFF );
buf[1] = ( uint8_t )( ( timeout >> 8 ) & 0xFF );
buf[2] = ( uint8_t )( timeout & 0xFF );
SX126xWriteCommand( RADIO_SET_TX, buf, 3 );
}
void SX126xSetRx( uint32_t timeout )
{
uint8_t buf[3];
OperatingMode = MODE_RX;
buf[0] = ( uint8_t )( ( timeout >> 16 ) & 0xFF );
buf[1] = ( uint8_t )( ( timeout >> 8 ) & 0xFF );
buf[2] = ( uint8_t )( timeout & 0xFF );
SX126xWriteCommand( RADIO_SET_RX, buf, 3 );
}
void SX126xSetRxBoosted( uint32_t timeout )
{
uint8_t buf[3];
OperatingMode = MODE_RX;
SX126xWriteRegister( REG_RX_GAIN, 0x96 ); // max LNA gain, increase current by ~2mA for around ~3dB in sensivity
buf[0] = ( uint8_t )( ( timeout >> 16 ) & 0xFF );
buf[1] = ( uint8_t )( ( timeout >> 8 ) & 0xFF );
buf[2] = ( uint8_t )( timeout & 0xFF );
SX126xWriteCommand( RADIO_SET_RX, buf, 3 );
}
void SX126xSetRxDutyCycle( uint32_t rxTime, uint32_t sleepTime )
{
uint8_t buf[6];
buf[0] = ( uint8_t )( ( rxTime >> 16 ) & 0xFF );
buf[1] = ( uint8_t )( ( rxTime >> 8 ) & 0xFF );
buf[2] = ( uint8_t )( rxTime & 0xFF );
buf[3] = ( uint8_t )( ( sleepTime >> 16 ) & 0xFF );
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
sx1262 asr6500s.zip (138个子文件)
prj.Debug.cspy.bat 1KB
prj.pbd.browse 662KB
sx126x.c 21KB
bsp.c 15KB
stm8l15x_it.c 12KB
sys.c 6KB
sx1262-board.c 4KB
interrupt.c 610B
prj.dbgdt 62KB
prj.dep 9KB
sx1276task.pbi.dep 2KB
lorawan.pbi.dep 2KB
stm8l15x_it.pbi.dep 2KB
stm8l15x_syscfg.pbi.dep 2KB
stm8l15x_flash.pbi.dep 2KB
stm8l15x_usart.pbi.dep 2KB
stm8l15x_gpio.pbi.dep 2KB
stm8l15x_exti.pbi.dep 2KB
stm8l15x_tim4.pbi.dep 2KB
stm8l15x_clk.pbi.dep 2KB
stm8l15x_spi.pbi.dep 2KB
stm8l15x_pwr.pbi.dep 2KB
stm8l15x_dma.pbi.dep 2KB
stm8l15x_adc.pbi.dep 2KB
stm8l15x_rtc.pbi.dep 2KB
sx1262.pbi.dep 2KB
sx1276.pbi.dep 2KB
stm8l15x_itc.pbi.dep 2KB
rf_task.pbi.dep 2KB
rf.pbi.dep 2KB
ntc.pbi.dep 2KB
sx1262-board.pbi.dep 2KB
sx126x.pbi.dep 2KB
interrupt.pbi.dep 1KB
bsp.pbi.dep 1KB
sys.pbi.dep 1KB
prj.dnx 4KB
prj.ewd 16KB
prj.ewp 59KB
prj.ewt 162KB
prj.eww 157B
iostm8l051f3.h 265KB
sx126x.h 38KB
bsp.h 10KB
sx126x-board.h 4KB
stm8l15x_it.h 4KB
stm8l15x_conf.h 3KB
sys.h 1KB
prj.hex 17KB
lnkstm8l051f3.icf 4KB
prj.map 33KB
build.ninja 815B
.ninja_deps 16B
.ninja_log 2KB
sx126x.o 105KB
stm8l15x_rtc.o 95KB
bsp.o 83KB
sx1262.o 79KB
stm8l15x_clk.o 54KB
stm8l15x_usart.o 53KB
sx1262-board.o 52KB
stm8l15x_tim4.o 47KB
stm8l15x_adc.o 45KB
stm8l15x_flash.o 45KB
stm8l15x_spi.o 38KB
stm8l15x_dma.o 30KB
stm8l15x_gpio.o 26KB
stm8l15x_exti.o 23KB
stm8l15x_syscfg.o 23KB
sys.o 22KB
stm8l15x_pwr.o 21KB
rf.o 16KB
stm8l15x_itc.o 15KB
interrupt.o 14KB
lorawan.o 13KB
prj.out 127KB
prj.pbd 662KB
prj_part3.pbi 713KB
prj_part4.pbi 708KB
sx1276task.pbi 700KB
sx1262.pbi 648KB
stm8l15x_rtc.pbi 647KB
prj_part1.pbi 646KB
sx126x.pbi 639KB
sx1276.pbi 626KB
rf.pbi 624KB
bsp.pbi 621KB
prj_part0.pbi 620KB
rf_task.pbi 620KB
sx1262-board.pbi 619KB
sys.pbi 618KB
prj_part2.pbi 615KB
ntc.pbi 614KB
stm8l15x_clk.pbi 605KB
stm8l15x_usart.pbi 604KB
stm8l15x_adc.pbi 601KB
stm8l15x_flash.pbi 600KB
stm8l15x_dma.pbi 599KB
stm8l15x_exti.pbi 599KB
stm8l15x_tim4.pbi 599KB
共 138 条
- 1
- 2
资源评论
- 磊子2021-02-20正在研究ASR6500S,资料很有参考价值!
lnwechag
- 粉丝: 47
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- IMG_20240425_120538.jpg
- My Complete Genome_6k Base-Pairs of Phenotype SNPs_Complete Raw Data.zip
- qt 的mqtt测试demo
- 移动应用开发教程-zip.zip
- mosquitto-2.018-install-windows-x64
- FTPServer FTP 服务器,绿色免安装,单文件
- 梦畅语音点名软件,上课点名
- 利用ADNI数据集和标签,在tensorflow框架上使用tensorlayer接口,通过架构u-net实现海马体的分割
- Kutools for Word v9.0 office word 插件
- 修复Windows 10 LTSC 2021资源占用率高
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功