新手入门 
 
	- 积分
 - 14
 
        - 金钱
 - 14 
 
       - 注册时间
 - 2019-5-24
 
      - 在线时间
 - 3 小时
 
 
 
 | 
 
2金钱 
   SPI在给sx1262发命令时出现问题。对1262而言,对sx1262复位后,芯片需要自己进行配置一段时间,这时候我可以通过BUSY引脚检查是否配置完成。BUSY若高就继续等待,但是在对BUSY引脚配置时发现了第一个问题。在官方例程中用的是L系列STM,所以把sx1262的BUSY引脚配置成了INPUT模式。但在我这个f103中,输入模式有四种(浮空,上拉下拉以及模拟),不知道选哪一种,通过测试只有配置成下拉,我才能跳出等待BUSY的循环。。。。随后对1262配置,尝试发送读寄存器操作码,发现读不出寄存器状态,读到都是0xff,我严重怀疑没有将命令发给1262,但示波器显示发的数据正确。。这是我配置的SPI口: void SpiInit(void ) 
 { 
         /*1、定义结构体------------------------------------------------------------*/ 
         SPI_InitTypeDef  SPI_InitStructure; 
         GPIO_InitTypeDef GPIO_InitStructure; 
          
          
         /*2、使能SPI1的时钟--(GPIOA\B口以及SPI使能)---------------------------------*/ 
         RCC_APB2PeriphClockCmd ( RCC_APB2Periph_GPIOA, ENABLE ); 
     RCC_APB2PeriphClockCmd ( RCC_APB2Periph_SPI1 , ENABLE ); 
          
          
         /*3、GPIO configuration-----------------------------------------------------*/ 
         GPIO_InitStructure.GPIO_Pin = NSS_PIN;               //配置NSS引脚 
         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 
         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
         GPIO_Init(NSS_IOPORT, &GPIO_InitStructure); 
     GPIO_SetBits(GPIOA , NSS_PIN);                          //默认拉高 
//          
//          
//         GPIO_InitStructure.GPIO_Pin = SPI_PIN_SCK | SPI_PIN_MOSI; 
//         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 
//         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
          
         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 ;    /*可精简---------*/ 
         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 
         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
         GPIO_Init( GPIOA,&GPIO_InitStructure);    //GPIOA的初始化 
          
         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;    /*可精简---------*/ 
         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 
         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
         GPIO_Init( GPIOA,&GPIO_InitStructure); 
          
         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;   /*可精简---------*/ 
         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; 
         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
         GPIO_Init( GPIOA,&GPIO_InitStructure); 
          
         
         
        //禁用JTAG 
         RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO, ENABLE );/*开启AFIO时钟*/ 
         GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); 
          
          
          
         /*SPI configuration-----------------------------------------------------*/ 
         SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;        //设置全双工通信 
         SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;                         //8位数据帧格式 
         SPI_InitStructure.SPI_Mode = SPI_Mode_Master;                             //设置主机从机模式 
         SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;                                //时钟线空闲低电平 
     SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;                              //第一个时钟沿(上升沿)采样,和SX1278一致 
         SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; 
         SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;      //72MHz八分频 
         SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;                        //高字节先传 
         SPI_InitStructure.SPI_CRCPolynomial = 7; 
         SPI_Init(SPI1, &SPI_InitStructure);         //根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器 
          
         SPI_Cmd(SPI1, ENABLE);   //开启SPI1 
          
         } 
 
 
 
以及BUSY口: 
 
 
void sx126x_IoInit(void) 
{ 
         
        GPIO_InitTypeDef         GPIO_InitStructure; 
 
        RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE ); 
 
 
         
 
        // Configure RESET as output 置1默认为高 
        GPIO_InitStructure.GPIO_Pin = RESET_PIN; 
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
        GPIO_Init(RESET_IOPORT, &GPIO_InitStructure ); 
        GPIO_SetBits(RESET_IOPORT,RESET_PIN); 
 
 
        // Configure radio DIO1 as inputs// Configure DIO1 
        GPIO_InitStructure.GPIO_Pin =  DIO1_PIN; 
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; 
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
        GPIO_Init( DIO1_IOPORT, &GPIO_InitStructure ); 
 
 
        // Configure radio BUSY as inputs// Configure BUSY 
        GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_1; 
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; 
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 
        GPIO_Init( GPIOB, &GPIO_InitStructure ); 
 
 
         
} 
 
 
 
 
 
 |   
 
 
 
 
 
 |