新手入门
- 积分
- 12
- 金钱
- 12
- 注册时间
- 2020-9-8
- 在线时间
- 4 小时
|
楼主 |
发表于 2020-10-26 14:55:35
|
显示全部楼层
我试了一下可以进入TXDone中断了, TXDone是通过EXTI1_IRQHandler中断进去的,但第一次进去后,lora状态设置成了Sleep模式,然后就会不停地进入EXTI1_IRQHandler中断,请问这是怎么回事呢。?
EXTI1_IRQHandler代码如下:
void EXTI1_IRQHandler( void )//SX1276ÖD¶ÏÏßIDO0éÏéyÑØìø±ä½øèë
{
volatile uint8_t irqFlags = 0;
switch( SX1276.Settings.State )
{
case RF_RX_RUNNING:
// RxDone interrupt
switch( SX1276.Settings.Modem )
{
case MODEM_FSK:
if( SX1276.Settings.Fsk.CrcOn == true )
{
irqFlags = SX1276Read( REG_IRQFLAGS2 );
if( ( irqFlags & RF_IRQFLAGS2_CRCOK ) != RF_IRQFLAGS2_CRCOK )
{
// Clear Irqs
SX1276Write( REG_IRQFLAGS1, RF_IRQFLAGS1_RSSI |
RF_IRQFLAGS1_PREAMBLEDETECT |
RF_IRQFLAGS1_SYNCADDRESSMATCH );
SX1276Write( REG_IRQFLAGS2, RF_IRQFLAGS2_FIFOOVERRUN );
if( SX1276.Settings.Fsk.RxContinuous == false )
{
SX1276.Settings.State = RF_IDLE;
TimerStart( &RxTimeoutSyncWord );
}
else
{
// Continuous mode restart Rx chain
SX1276Write( REG_RXCONFIG, SX1276Read( REG_RXCONFIG ) | RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK );
}
TimerStop( &RxTimeoutTimer );
if( ( RadioEvents != NULL ) && ( RadioEvents->RxError != NULL ) )
{
RadioEvents->RxError( );
}
SX1276.Settings.FskPacketHandler.PreambleDetected = false;
SX1276.Settings.FskPacketHandler.SyncWordDetected = false;
SX1276.Settings.FskPacketHandler.NbBytes = 0;
SX1276.Settings.FskPacketHandler.Size = 0;
break;
}
}
// Read received packet size
if( ( SX1276.Settings.FskPacketHandler.Size == 0 ) && ( SX1276.Settings.FskPacketHandler.NbBytes == 0 ) )
{
if( SX1276.Settings.Fsk.FixLen == false )
{
SX1276ReadFifo( ( uint8_t* )&SX1276.Settings.FskPacketHandler.Size, 1 );
}
else
{
SX1276.Settings.FskPacketHandler.Size = SX1276Read( REG_PAYLOADLENGTH );
}
SX1276ReadFifo( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes, SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
SX1276.Settings.FskPacketHandler.NbBytes += ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
}
else
{
SX1276ReadFifo( RxTxBuffer + SX1276.Settings.FskPacketHandler.NbBytes, SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
SX1276.Settings.FskPacketHandler.NbBytes += ( SX1276.Settings.FskPacketHandler.Size - SX1276.Settings.FskPacketHandler.NbBytes );
}
if( SX1276.Settings.Fsk.RxContinuous == false )
{
SX1276.Settings.State = RF_IDLE;
TimerStart( &RxTimeoutSyncWord );
}
else
{
// Continuous mode restart Rx chain
SX1276Write( REG_RXCONFIG, SX1276Read( REG_RXCONFIG ) | RF_RXCONFIG_RESTARTRXWITHOUTPLLLOCK );
}
TimerStop( &RxTimeoutTimer );
if( ( RadioEvents != NULL ) && ( RadioEvents->RxDone != NULL ) )
{
RadioEvents->RxDone( RxTxBuffer, SX1276.Settings.FskPacketHandler.Size, SX1276.Settings.FskPacketHandler.RssiValue, 0 );
}
SX1276.Settings.FskPacketHandler.PreambleDetected = false;
SX1276.Settings.FskPacketHandler.SyncWordDetected = false;
SX1276.Settings.FskPacketHandler.NbBytes = 0;
SX1276.Settings.FskPacketHandler.Size = 0;
break;
case MODEM_LORA:
{
int8_t snr = 0;
// Clear Irq
SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_RXDONE );
irqFlags = SX1276Read( REG_LR_IRQFLAGS );
if( ( irqFlags & RFLR_IRQFLAGS_PAYLOADCRCERROR_MASK ) == RFLR_IRQFLAGS_PAYLOADCRCERROR )
{
// Clear Irq
SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_PAYLOADCRCERROR );
if( SX1276.Settings.LoRa.RxContinuous == false )
{
SX1276.Settings.State = RF_IDLE;
}
TimerStop( &RxTimeoutTimer );
if( ( RadioEvents != NULL ) && ( RadioEvents->RxError != NULL ) )
{
RadioEvents->RxError( );
}
break;
}
SX1276.Settings.LoRaPacketHandler.SnrValue = SX1276Read( REG_LR_PKTSNRVALUE );
if( SX1276.Settings.LoRaPacketHandler.SnrValue & 0x80 ) // The SNR sign bit is 1
{
// Invert and divide by 4
snr = ( ( ~SX1276.Settings.LoRaPacketHandler.SnrValue + 1 ) & 0xFF ) >> 2;
snr = -snr;
}
else
{
// Divide by 4
snr = ( SX1276.Settings.LoRaPacketHandler.SnrValue & 0xFF ) >> 2;
}
int16_t rssi = SX1276Read( REG_LR_PKTRSSIVALUE );
if( snr < 0 )
{
if( SX1276.Settings.Channel > RF_MID_BAND_THRESH )
{
SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_HF + rssi + ( rssi >> 4 ) +
snr;
}
else
{
SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_LF + rssi + ( rssi >> 4 ) +
snr;
}
}
else
{
if( SX1276.Settings.Channel > RF_MID_BAND_THRESH )
{
SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_HF + rssi + ( rssi >> 4 );
}
else
{
SX1276.Settings.LoRaPacketHandler.RssiValue = RSSI_OFFSET_LF + rssi + ( rssi >> 4 );
}
}
SX1276.Settings.LoRaPacketHandler.Size = SX1276Read( REG_LR_RXNBBYTES );
SX1276ReadFifo( RxTxBuffer, SX1276.Settings.LoRaPacketHandler.Size );
if( SX1276.Settings.LoRa.RxContinuous == false )
{
SX1276.Settings.State = RF_IDLE;
}
TimerStop( &RxTimeoutTimer );
if( ( RadioEvents != NULL ) && ( RadioEvents->RxDone != NULL ) )
{
RadioEvents->RxDone( RxTxBuffer, SX1276.Settings.LoRaPacketHandler.Size, SX1276.Settings.LoRaPacketHandler.RssiValue, SX1276.Settings.LoRaPacketHandler.SnrValue );
}
}
break;
default:
break;
}
break;
case RF_TX_RUNNING:
TimerStop( &TxTimeoutTimer );
// TxDone interrupt
switch( SX1276.Settings.Modem )
{
case MODEM_LORA:
// Clear Irq
SX1276Write( REG_LR_IRQFLAGS, RFLR_IRQFLAGS_TXDONE );
// Intentional fall through
case MODEM_FSK:
default:
SX1276.Settings.State = RF_IDLE;
if( ( RadioEvents != NULL ) && ( RadioEvents->TxDone != NULL ) )
{
RadioEvents->TxDone( );
}
break;
}
break;
default:
break;
}
} |
|