1

我正在使用 Keil 和 CubeMX 在 stm32f103c8(bluepill)中开发我的项目,我想使用 nrf24l01 发射器,为此我寻找了一个正是我想做的教程。问题是,当我这样做时,我注意到无线电收发器不发送或接收,我在互联网上看到有些人对我正在使用的这张卡有问题,只是我这让我无法使用这个库。我留下了一个视频链接,该视频显示了我在库之外所做的相同步骤。确切地说,该功能nrf24_write是不起作用的功能。我希望你能帮助我,因为我一直在试图理解为什么它不能工作好几天。

链接视频:

https://www.youtube.com/watch?v=O2dg2Eo7vo8

链接库:

https://github.com/MYaqoobEmbedded/STM32-Tutorials/tree/master/Tutorial%2024%20-%20NRF24L01%20Radio%20Transceiver

主要代码:

    /* Includes ------------------------------------------------------------------*/
#include "main.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "MY_NRF24.h"
#include "stdio.h"
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
 
/* USER CODE END PTD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
 
/* USER CODE END PM */
 
/* Private variables ---------------------------------------------------------*/
SPI_HandleTypeDef hspi1;
 
UART_HandleTypeDef huart1;
 
/* USER CODE BEGIN PV */
 
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_SPI1_Init(void);
static void MX_USART1_UART_Init(void);
/* USER CODE BEGIN PFP */
 
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
uint64_t TxpipeAddrs = 0x324e6f6465;
char myTxData[32]; //= "Hello World!";
char AckPayload[32];
/* USER CODE END 0 */
 
/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
    myTxData[0]= 0;
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_SPI1_Init();
  MX_USART1_UART_Init();
  /* USER CODE BEGIN 2 */
    NRF24_begin(GPIOB, GPIO_PIN_8, GPIO_PIN_9, hspi1);
    nrf24_DebugUART_Init(huart1);
    
    
    
    //**** TRANSMIT - ACK ****//
    
    NRF24_setPALevel(RF_PWR_HIGH);
    NRF24_openWritingPipe(TxpipeAddrs);
 
    NRF24_setAutoAck(true);
    NRF24_setChannel(52);
    NRF24_setPayloadSize(32);
    NRF24_setDataRate(RF24_2MBPS);
    
    NRF24_enableDynamicPayloads();
    NRF24_enableAckPayload();
    NRF24_stopListening();
    HAL_Delay(1000);
    printRadioSettings();
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */
        if(NRF24_write(myTxData, 32))
        {
            NRF24_read(AckPayload, 32);
            HAL_UART_Transmit(&huart1, (uint8_t *)"Transmitted Successfully\r\n", strlen("Transmitted Successfully\r\n"), 10);
            
            char myDataack[80];
            sprintf(myDataack, "AckPayload:  %s \r\n", AckPayload);
            HAL_UART_Transmit(&huart1, (uint8_t *)myDataack, strlen(myDataack), 10);
        }else{
                    HAL_UART_Transmit(&huart1, (uint8_t *)"Transmitted Failed\r\n", strlen("Transmitted Failed\r\n"), 10);}
        myTxData[0]= myTxData[0] + 1;
        HAL_Delay(1000);
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}
4

0 回答 0