移植lorawan_node

移植lorawan节点 于stm32L系列

cubemx效率不言而喻,直接生成spi,uart,clock配置

移植lorawan-node的文件夹,主要有system文件夹,基本不需要改动,然后移植mac文件夹,不需要改动,最后移植boad文件夹,需要rtc-board.c,1276-board.c,其中rtc主要要打开rtc的LSE时钟源,1276-board.c需要实现SpiInout

uint16_t SpiInOut( Spi_t *obj, uint16_t outData )
{
	uint16_t rxData ;
	HAL_SPI_TransmitReceive( &hspi1, ( uint8_t * ) &outData, ( uint8_t* ) &rxData, 1, HAL_MAX_DELAY);
	return rxData;
}

信号强度差的时候需要注意 ,RFSW问题。

附上模块初始化的代码

 HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_USART1_UART_Init();
  MX_SPI1_Init();
  SX1276IoInit();
   RtcInit(  );
   LoRaMacPrimitives.MacMcpsConfirm = McpsConfirm;
   LoRaMacPrimitives.MacMcpsIndication = McpsIndication;
   LoRaMacPrimitives.MacMlmeConfirm = MlmeConfirm;
   LoRaMacPrimitives.MacMlmeIndication = MlmeIndication;
   //LoRaMacCallbacks.GetBatteryLevel = BoardGetBatteryLevel;
   LoRaMacInitialization( &LoRaMacPrimitives, &LoRaMacCallbacks, ACTIVE_REGION );
   
   mibReq.Type = MIB_ADR;
   mibReq.Param.AdrEnable = 1;
   LoRaMacMibSetRequestConfirm( &mibReq );

   mibReq.Type = MIB_PUBLIC_NETWORK;
   mibReq.Param.EnablePublicNetwork = LORAWAN_PUBLIC_NETWORK;
   LoRaMacMibSetRequestConfirm( &mibReq );
   
   mibReq.Type = MIB_DEVICE_CLASS;
   mibReq.Param.Class = CLASS_C;
   LoRaMacMibSetRequestConfirm( &mibReq );
   
   MlmeReq_t mlmeReq;
   mlmeReq.Type = MLME_JOIN;

   mlmeReq.Req.Join.DevEui = DevEui;
   mlmeReq.Req.Join.AppEui = AppEui;
   mlmeReq.Req.Join.AppKey = AppKey;
   mlmeReq.Req.Join.Datarate = DR_0;
   
    if( LoRaMacMlmeRequest( &mlmeReq ) == LORAMAC_STATUS_OK )
	{
	}



你可能感兴趣的:(移植lorawan_node)