STM32开发笔记91: SX1268驱动程序设计(发送模式)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/qingwufeiyang12346/article/details/100529414

单片机型号:STM32L053R8T6


本系列开发日志,将详述SX1268驱动程序的整个设计过程,本篇介绍发送模式的相关驱动程序。

一、TX模式

In TX mode after ramping-up the Power-Amplifier (PA) transmits the data buffer. In TX mode the circuit can operate in
different sub-modes: single mode or single with timeout mode.(在TX模式下,功率放大器(PA)启动后便可以传输数据缓冲区中的数据。在TX模式下电路可以工作不同的子模式:单模式或单超时模式

The timeout in Tx mode can be used as a security to ensure that if for any reason the Tx is aborted or does not succeed (ie. the TxDone IRQ never is never triggered), the TxTimeout will prevent the system from waiting for an undefined amount of time. Using the timeout while in Tx mode removes the need to use resources from the host MCU to perform the same task.(在Tx模式下的超时可以用作一种安全措施,以确保如果由于任何原因Tx被中止或没有成功(例如:TxDone IRQ永远不会被触发),TxTimeout将防止系统等待一个未定义的时间量。在Tx模式下使用超时可以避免使用主机MCU中的资源来执行相同的任务。

In TX mode, BUSY will go low as soon as the PA has ramped-up and transmission of preamble starts.(在发送模式,功率放大器启动并传输前导码时,BUSY引脚就会变为低电平

可以通过SetTxParams函数设置PA的输出能量和启动时间(10us到3.4ms)

二、SetTxParams函数

能量的单位是dBm,有2个范围:

  • -17到14dBm,步长为1db,低能量PA被选中
  • -9到22dBm,步长为1db,高能量PA被选中

通过SetPaConfig函数的参数deviceSel选择低能量PA或者高能量PA,缺省为低能量PA,14dBm被选中。

PA启动时间见下表:

三、SetPaConfig函数

其具有4个参数,第3-4参数为固定值,不需理会。1和2的具体取值,可参考下表,最后1列表示SetTxParam函数中设定的数值。

四、OCP寄存器

有了上述准备后,还需注意数据文档中的一些内容,原文如下:

However, to avoid consuming too much energy, the user is free to configure the Over Current Protection (OCP) register manually. At Reset, the OCP is configured to limit the current at 60 mA.(为了避免过大的能量损耗,我们还可手动配置OCP即初期,在复位后,其配置为最大60mA

The OCP is configurable by steps of 2.5 mA and the default value is re-configured automatically each time the function SetPaConfig(...) is called. If the user wants to adjust the OCP value, it is necessary to change the register as a second step after
calling the function SetPaConfig(...).(OCP的步长为2.5mA,每次调用SetPaConfig函数会自动重新配置。假如用户想调整OCP值,需要在SetPaConfig后,改变OCP寄存器的值

OCP与硬件设计相关,不同的硬件设计对应不同的硬件电路,查看E22-400M22S数据手册可知,其最大发射功率22dBm,所以我们可以按照22dBm进行配置。

五、程序实现

typedef enum
{
    RADIO_RAMP_10_US                        = 0x00,
    RADIO_RAMP_20_US                        = 0x01,
    RADIO_RAMP_40_US                        = 0x02,
    RADIO_RAMP_80_US                        = 0x03,
    RADIO_RAMP_200_US                       = 0x04,
    RADIO_RAMP_800_US                       = 0x05,
    RADIO_RAMP_1700_US                      = 0x06,
    RADIO_RAMP_3400_US                      = 0x07,
}RadioRampTimes_t;
void SX126xSetPaConfig(uint8_t paDutyCycle, uint8_t hpMax);	
void SX126xSetTxParams(int8_t power, RadioRampTimes_t rampTime);
void CSX1268::SX126xSetPaConfig(uint8_t paDutyCycle, uint8_t hpMax)
{
	uint8_t buf[4];

	buf[0] = paDutyCycle;
	buf[1] = hpMax;
	buf[2] = 0x00;
	buf[3] = 0x01;
	SX126xWriteCommand(RADIO_SET_PACONFIG, buf, 4 );
}
void CSX1268::SX126xSetTxParams(int8_t power, RadioRampTimes_t rampTime)
{
	uint8_t buf[2];
	SX126xSetPaConfig(0x04, 0x07);
	if(power > 22)
	{
			power = 22;
	}
	else if(power < -9)
	{
			power = -9;
	}
	SX126xWriteRegister(REG_OCP, 0x38); 
	buf[0] = power;
	buf[1] = ( uint8_t )rampTime;
	SX126xWriteCommand(RADIO_SET_TXPARAMS, buf, 2);
}

 

原创性文章,转载请注明出处CSDN:http://blog.csdn.net/qingwufeiyang12346

 

 

 

 

 

 

猜你喜欢

转载自blog.csdn.net/qingwufeiyang12346/article/details/100529414