OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 5629|回复: 6

驱动sx1262出现问题,跪请各位大佬给分析下。

[复制链接]

1

主题

4

帖子

0

精华

新手入门

积分
14
金钱
14
注册时间
2019-5-24
在线时间
3 小时
发表于 2019-7-10 21:04:41 | 显示全部楼层 |阅读模式
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 );


       
}





正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

558

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
164897
金钱
164897
注册时间
2010-12-1
在线时间
2100 小时
发表于 2019-7-11 02:11:19 | 显示全部楼层
回复

使用道具 举报

5

主题

56

帖子

0

精华

初级会员

Rank: 2

积分
117
金钱
117
注册时间
2018-7-27
在线时间
86 小时
发表于 2019-7-11 11:19:46 | 显示全部楼层
SPI不需要配置MISO吗
回复

使用道具 举报

1

主题

4

帖子

0

精华

新手入门

积分
14
金钱
14
注册时间
2019-5-24
在线时间
3 小时
 楼主| 发表于 2019-7-11 18:15:44 | 显示全部楼层

设置了,这是简单的SPI1,就是4567四个引脚。
回复

使用道具 举报

1

主题

4

帖子

0

精华

初级会员

Rank: 2

积分
73
金钱
73
注册时间
2019-4-18
在线时间
21 小时
发表于 2019-9-21 17:24:52 | 显示全部楼层
兄弟能否分享一下sx126x的驱动,我在网上实在找不到了。
回复

使用道具 举报

8

主题

61

帖子

0

精华

高级会员

Rank: 4

积分
682
金钱
682
注册时间
2019-4-24
在线时间
42 小时
发表于 2019-9-23 17:11:16 | 显示全部楼层
这个没什么好说的,四种输入模式都试一遍,试过就行了。
回复

使用道具 举报

0

主题

9

帖子

0

精华

新手上路

积分
33
金钱
33
注册时间
2019-12-11
在线时间
8 小时
发表于 2020-3-25 17:12:43 | 显示全部楼层
为啥sx126x资料那么少!我快吐了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2024-6-8 19:43

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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