久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4687|回復: 2
打印 上一主題 下一主題
收起左側

STM32單片機+SX1278官方源碼分享

[復制鏈接]
跳轉到指定樓層
樓主
ID:234051 發表于 2019-5-17 16:52 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
自帶收發功能,支持SX1272/1276/1278

  1. #include <string.h>
  2. #include <stdint.h>
  3. #include <stdbool.h>
  4. #include "platform.h"
  5. #include "led.h"

  6. #if USE_UART
  7. #include "uart.h"
  8. #endif

  9. #include "radio.h"


  10. #define BUFFER_SIZE                                 9 // Define the payload size here


  11. static uint16_t BufferSize = BUFFER_SIZE;                        // RF buffer size
  12. static uint8_t Buffer[BUFFER_SIZE];                                        // RF buffer

  13. static uint8_t EnableMaster = true;                                 // Master/Slave selection

  14. tRadioDriver *Radio = NULL;

  15. const uint8_t PingMsg[] = "PING";
  16. const uint8_t PongMsg[] = "PONG";

  17. /*
  18. * Manages the master operation
  19. */
  20. void OnMaster( void )
  21. {
  22.     uint8_t i;

  23.     switch( Radio->Process( ) )
  24.     {
  25.     case RF_RX_TIMEOUT:
  26.         // Send the next PING frame
  27.         Buffer[0] = 'P';
  28.         Buffer[1] = 'I';
  29.         Buffer[2] = 'N';
  30.         Buffer[3] = 'G';
  31.         for( i = 4; i < BufferSize; i++ )
  32.         {
  33.             Buffer[i] = i - 4;
  34.         }
  35.         Radio->SetTxPacket( Buffer, BufferSize );
  36.         break;
  37.     case RF_RX_DONE:
  38.         Radio->GetRxPacket( Buffer, ( uint16_t* )&BufferSize );

  39.         if( BufferSize > 0 )
  40.         {
  41.             if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 )
  42.             {
  43.                 // Indicates on a LED that the received frame is a PONG
  44.                 LedToggle( LED_GREEN );

  45.                 // Send the next PING frame            
  46.                 Buffer[0] = 'P';
  47.                 Buffer[1] = 'I';
  48.                 Buffer[2] = 'N';
  49.                 Buffer[3] = 'G';
  50.                 // We fill the buffer with numbers for the payload
  51.                 for( i = 4; i < BufferSize; i++ )
  52.                 {
  53.                     Buffer[i] = i - 4;
  54.                 }
  55.                 Radio->SetTxPacket( Buffer, BufferSize );
  56.             }
  57.             else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 )
  58.             { // A master already exists then become a slave
  59.                 EnableMaster = false;
  60.                 LedOff( LED_RED );
  61.             }
  62.         }            
  63.         break;
  64.     case RF_TX_DONE:
  65.         // Indicates on a LED that we have sent a PING
  66.         LedToggle( LED_RED );
  67.         Radio->StartRx( );
  68.         break;
  69.     default:
  70.         break;
  71.     }
  72. }

  73. /*
  74. * Manages the slave operation
  75. */
  76. void OnSlave( void )
  77. {
  78.     uint8_t i;

  79.     switch( Radio->Process( ) )
  80.     {
  81.     case RF_RX_DONE:
  82.         Radio->GetRxPacket( Buffer, ( uint16_t* )&BufferSize );

  83.         if( BufferSize > 0 )
  84.         {
  85.             if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 )
  86.             {
  87.                 // Indicates on a LED that the received frame is a PING
  88.                 LedToggle( LED_GREEN );

  89.                // Send the reply to the PONG string
  90.                 Buffer[0] = 'P';
  91.                 Buffer[1] = 'O';
  92.                 Buffer[2] = 'N';
  93.                 Buffer[3] = 'G';
  94.                 // We fill the buffer with numbers for the payload
  95.                 for( i = 4; i < BufferSize; i++ )
  96.                 {
  97.                     Buffer[i] = i - 4;
  98.                 }

  99.                 Radio->SetTxPacket( Buffer, BufferSize );
  100.             }
  101.         }
  102.         break;
  103.     case RF_TX_DONE:
  104.         // Indicates on a LED that we have sent a PONG
  105.         LedToggle( LED_RED );
  106.         Radio->StartRx( );
  107.         break;
  108.     default:
  109.         break;
  110.     }
  111. }


  112. /*
  113. * Main application entry point.
  114. */
  115. int main( void )
  116. {
  117.     BoardInit( );

  118.     Radio = RadioDriverInit( );

  119.     Radio->Init( );

  120.     Radio->StartRx( );

  121.     while( 1 )
  122.     {
  123.         if( EnableMaster == true )
  124.         {
  125.             OnMaster( );
  126.         }
  127.         else
  128.         {
  129.             OnSlave( );
  130.         }   
  131. #if( PLATFORM == SX12xxEiger ) && ( USE_UART == 1 )

  132.         UartProcess( );

  133.         {
  134.             uint8_t data = 0;
  135.             if( UartGetChar( &data ) == UART_OK )
  136.             {
  137.                 UartPutChar( data );
  138.             }
  139.         }
  140. #endif        
  141.     }
  142. #ifdef __GNUC__
  143.     return 0;
  144. #endif
  145. }
復制代碼
全部資料51hei下載地址:
semtech驅動源碼SX12xxDrivers-2.0.0.7z (577.25 KB, 下載次數: 109)

評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:453198 發表于 2020-12-17 11:08 | 只看該作者
這是stm32的程序
回復

使用道具 舉報

板凳
ID:246744 發表于 2021-11-3 00:04 | 只看該作者
十分感謝分享代碼,學習了~~~
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产精品视频免费观看 | 亚洲免费在线 | 国产精品久久久久久久久久免费看 | 欧美精品二区 | 免费精品视频在线观看 | 午夜a√ | 99热.com| 一区二区国产精品 | av中文字幕在线 | 中文字幕成人 | 天天草av | www.精品一区 | 伊人网国产 | 刘亦菲国产毛片bd | 成人无遮挡毛片免费看 | 伊人伊人| 91色视频在线观看 | 久久成人国产精品 | 色999视频 | 国产高清精品一区二区三区 | 日韩三级一区 | 久久久人成影片一区二区三区 | 色综合中文 | 国产精品伦理一区 | 成人国产精品久久 | 午夜精品久久久久久 | 日韩一区在线视频 | 麻豆久久久久久久 | 免费超碰 | 亚洲精品女优 | 黑人久久| 日本不卡高字幕在线2019 | 国产一区二区三区四区三区四 | 午夜影院在线观看版 | 成人av在线播放 | 天天插天天搞 | 日韩视频精品在线 | 亚洲视频在线免费观看 | 一区二区三区日本 | 国产午夜在线观看 | 日本黄色大片免费 |