找回密码
 注册
查看: 165|回复: 1
打印 上一主题 下一主题

STM32单片机+SX1278官方源码分享

  [复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2022-5-31 10:25 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

EDA365欢迎您登录!

您需要 登录 才可以下载或查看,没有帐号?注册

x
自带收发功能,支持SX1272/1276/1278
1 L" r7 x' X1 V8 |7 r2 b8 |, @" J
5 {+ k. G, f  E$ Q
  • #include <string.h>
  • #include <stdint.h>
  • #include <stdbool.h>
  • #include "platform.h"
  • #include "led.h"
  • #if USE_UART
  • #include "uart.h"
  • #endif
  • #include "radio.h"
  • #define BUFFER_SIZE                                 9 // Define the payload size here
  • static uint16_t BufferSize = BUFFER_SIZE;                        // RF buffer size
  • static uint8_t Buffer[BUFFER_SIZE];                                        // RF buffer
  • static uint8_t EnableMaster = true;                                 // Master/Slave selection
  • tRadioDriver *Radio = NULL;
  • const uint8_t PingMsg[] = "PING";
  • const uint8_t PongMsg[] = "PONG";
  • /*
  • * Manages the master operation
  • */
  • void OnMaster( void )
  • {
  •     uint8_t i;
  •     switch( Radio->Process( ) )
  •     {
  •     case RF_RX_TIMEOUT:
  •         // Send the next PING frame
  •         Buffer[0] = 'P';
  •         Buffer[1] = 'I';
  •         Buffer[2] = 'N';
  •         Buffer[3] = 'G';
  •         for( i = 4; i < BufferSize; i++ )
  •         {
  •             Buffer = i - 4;
  •         }
  •         Radio->SetTxPacket( Buffer, BufferSize );
  •         break;
  •     case RF_RX_DONE:
  •         Radio->GetRxPacket( Buffer, ( uint16_t* )&BufferSize );
  •         if( BufferSize > 0 )
  •         {
  •             if( strncmp( ( const char* )Buffer, ( const char* )PongMsg, 4 ) == 0 )
  •             {
  •                 // Indicates on a LED that the received frame is a PONG
  •                 LedToggle( LED_GREEN );
  •                 // Send the next PING frame
  •                 Buffer[0] = 'P';
  •                 Buffer[1] = 'I';
  •                 Buffer[2] = 'N';
  •                 Buffer[3] = 'G';
  •                 // We fill the buffer with numbers for the payload
  •                 for( i = 4; i < BufferSize; i++ )
  •                 {
  •                     Buffer = i - 4;
  •                 }
  •                 Radio->SetTxPacket( Buffer, BufferSize );
  •             }
  •             else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 )
  •             { // A master already exists then become a slave
  •                 EnableMaster = false;
  •                 LedOff( LED_RED );
  •             }
  •         }
  •         break;
  •     case RF_TX_DONE:
  •         // Indicates on a LED that we have sent a PING
  •         LedToggle( LED_RED );
  •         Radio->StartRx( );
  •         break;
  •     default:
  •         break;
  •     }
  • }
  • /*
  • * Manages the slave operation
  • */
  • void OnSlave( void )
  • {
  •     uint8_t i;
  •     switch( Radio->Process( ) )
  •     {
  •     case RF_RX_DONE:
  •         Radio->GetRxPacket( Buffer, ( uint16_t* )&BufferSize );
  •         if( BufferSize > 0 )
  •         {
  •             if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 )
  •             {
  •                 // Indicates on a LED that the received frame is a PING
  •                 LedToggle( LED_GREEN );
  •                // Send the reply to the PONG string
  •                 Buffer[0] = 'P';
  •                 Buffer[1] = 'O';
  •                 Buffer[2] = 'N';
  •                 Buffer[3] = 'G';
  •                 // We fill the buffer with numbers for the payload
  •                 for( i = 4; i < BufferSize; i++ )
  •                 {
  •                     Buffer = i - 4;
  •                 }
  •                 Radio->SetTxPacket( Buffer, BufferSize );
  •             }
  •         }
  •         break;
  •     case RF_TX_DONE:
  •         // Indicates on a LED that we have sent a PONG
  •         LedToggle( LED_RED );
  •         Radio->StartRx( );
  •         break;
  •     default:
  •         break;
  •     }
  • }
  • /*
  • * Main application entry point.
  • */
  • int main( void )
  • {
  •     BoardInit( );
  •     Radio = RadioDriverInit( );
  •     Radio->Init( );
  •     Radio->StartRx( );
  •     while( 1 )
  •     {
  •         if( EnableMaster == true )
  •         {
  •             OnMaster( );
  •         }
  •         else
  •         {
  •             OnSlave( );
  •         }
  • #if( PLATFORM == SX12xxEiger ) && ( USE_UART == 1 )
  •         UartProcess( );
  •         {
  •             uint8_t data = 0;
  •             if( UartGetChar( &data ) == UART_OK )
  •             {
  •                 UartPutChar( data );
  •             }
  •         }
  • #endif
  •     }
  • #ifdef __GNUC__
  •     return 0;
  • #endif
  • }: G/ C4 V+ a0 H! ^9 g# Y$ U

( _: Q1 L, _8 m- G! o4 ]5 V# O
1 h: [9 J6 W/ `/ M' Y
$ i) m: `- P: O

该用户从未签到

2#
发表于 2022-5-31 13:54 | 只看该作者
怎么分析程序呢?这么长的行数。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

推荐内容上一条 /1 下一条

EDA365公众号

关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

GMT+8, 2025-6-3 08:04 , Processed in 0.062500 second(s), 23 queries , Gzip On.

深圳市墨知创新科技有限公司

地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

快速回复 返回顶部 返回列表