OpenEdv-开源电子网

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

stm32F207+LTC1867卡在while (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE) == RESET);

[复制链接]

7

主题

21

帖子

0

精华

初级会员

Rank: 2

积分
54
金钱
54
注册时间
2014-12-17
在线时间
4 小时
发表于 2016-1-7 16:22:36 | 显示全部楼层 |阅读模式
10金钱
    stm32F207+LTC1867,采用SPI,分别连接PC10、PC11、PC12,程序卡在Data_L = AD1_ReadData();中的while (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE) == RESET);下面是程序卡的地方,附完整版程序,跪求大神帮助
void SPI1_Init(void)
{
        SPI_InitTypeDef SPI_InitStructure;
        GPIO_InitTypeDef GPIO_InitStructure;
       
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);//使能GPIOE时钟 CS
        RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);//使能GPIOB时钟
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);//使能SPI3时钟
        //MOSI  SCLK
         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10|GPIO_Pin_12;//PB3~5复用功能输出       
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
     GPIO_Init(GPIOC, &GPIO_InitStructure);//初始化
         //MISO
         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;//PB3~5复用功能输出       
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//复用功能
     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
     GPIO_Init(GPIOC, &GPIO_InitStructure);//初始化
       
         GPIO_PinAFConfig(GPIOC,GPIO_PinSource10,GPIO_AF_SPI3); //PB3复用为 SPI1
         GPIO_PinAFConfig(GPIOC,GPIO_PinSource11,GPIO_AF_SPI3); //PB4复用为 SPI1
         GPIO_PinAFConfig(GPIOC,GPIO_PinSource12,GPIO_AF_SPI3); //PB5复用为 SPI1
        //CS
         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;//PA5
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//输出
     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;//推挽输出
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;//100MHz
     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;//上拉
     GPIO_Init(GPIOA, &GPIO_InitStructure);//初始化
       
        //SST25VF064 片选
    AD_CS=1;
        SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
        SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
        SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
        SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
        SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
        SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
        SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
        SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
        SPI_InitStructure.SPI_CRCPolynomial = 7;
        SPI_Init(SPI3, &SPI_InitStructure);

        SPI_Cmd(SPI3, ENABLE);
}

/**************************************************************************
**Function name: AD_Conv
**Description  : ó??£?aSPI μ?·?ê?à′êμ??AD×a??
**Input        : which channel(0~7)
**Output       : none
**Return       : ADC's digital code
**************************************************************************/
u16 AD_Conv(u8 channel)
{
    u8 command=0x42;//01 0 0  0 100
    u16 AD_Value =0x0000;
        u8 i = 0;
    switch(channel)
    {
      case 0:  command = 0x42;break;
      case 1:  command = 0x62;break;
      case 2:  command = 0x4a;break;
      case 3:  command = 0x6a;break;
      case 4:  command = 0x52;break;
      case 5:  command = 0x72;break;
      case 6:  command = 0x5a;break;
      case 7:  command = 0x7a;break;
      default: command = 0x42;break;
    }
  command <<= 1;

//  SCK_L;
//  AD1_CS_H;
//  delay_us(5);
    AD_CS=0;
    delay_us(5);

   for(i=0;i<7;i++)
  {

    if(command & 0x80)
   {
   AD_SDI=1;
   }
   else
   {
   AD_SDI=0;
   }
   AD_SCK=0;
// delay_us(5);
  AD_SCK=1;
//  delay_us(5);
   command <<= 1;
  }

   AD_CS=1;
   delay_us(10);
   AD_CS=0;

   for(i=0;i<16;i++) //?áè?SPIêy?Y
  {
   AD_SCK=0;
   delay_us(2);
   if(AD_SDO)
   AD_Value |= 0x01;
   AD_Value <<= 1;
   AD_SCK=1;
   delay_us(2);
  }

   AD_CS=1;

   return AD_Value;
}

/**************************************************************************
**Function name: AD1_SPI_Conv
**Description  : ó?ó2?tSPI μ?·?ê?à′êμ??AD×a??
**Input        : which channel(0~7)
**Output       : none
**Return       : ADC's digital code
**************************************************************************/
u16 AD_SPI_Conv(u8 channel)
{
    u8 command=0x42;
    u16 AD_Value=0x00;
    u8 Data_H,Data_L;

    switch(channel)
    {
     case 0:  command = 0x42;break;
     case 1:  command = 0x62;break;
     case 2:  command = 0x4a;break;
     case 3:  command = 0x6a;break;
     case 4:  command = 0x52;break;
         case 5:  command = 0x72;break;
     case 6:  command = 0x5a;break;
     case 7:  command = 0x7a;break;
     default: command = 0x42;break;
    }
    command <<= 1;

   AD_CS=0;
   delay_us(10);
   AD1_WriteCmd(command);

   AD_CS=1;
   delay_us(10);
   AD_CS=0;

   Data_H = AD1_ReadData();
   SPI_I2S_ClearFlag(SPI3,SPI_I2S_FLAG_RXNE);
   delay_us(10);
   Data_L = AD1_ReadData();

   AD_CS=1;

   AD_Value = Data_H;
   AD_Value = (AD_Value<<8) + Data_L;

   return AD_Value;
}
/**************************************************************************
**Function name: SPI_WriteCmd
**Description  : SPI D′?üá?
**Input        : uint8_t command
**Output       : none
**Return       : none
**************************************************************************/
void AD1_WriteCmd(u8 command)
{
  while (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE) == RESET); //·¢?í?o′???±ê????
  SPI_I2S_SendData(SPI3, command);
}

/**************************************************************************
**Function name: AD1_ReadData
**Description  : AD2 read conversion data
**Input        : none
**Output       : none
**Return       : uint16_t
**************************************************************************/
u8 AD1_ReadData(void)
{
  while (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_RXNE) == RESET); //?ì2é???¨μ?SPI±ê????éè??ó?·?:?óêü?o′?·???±ê????     
  return SPI_I2S_ReceiveData(SPI3); //·μ??í¨1ySPIx×??ü?óê?μ?êy?Y
}

LTC1867 stm32F207.rar

17.84 MB, 下载次数: 503

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

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165524
金钱
165524
注册时间
2010-12-1
在线时间
2116 小时
发表于 2016-1-7 23:02:41 | 显示全部楼层
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165524
金钱
165524
注册时间
2010-12-1
在线时间
2116 小时
发表于 2016-1-7 23:02:41 | 显示全部楼层
帮顶.
回复

使用道具 举报

7

主题

21

帖子

0

精华

初级会员

Rank: 2

积分
54
金钱
54
注册时间
2014-12-17
在线时间
4 小时
 楼主| 发表于 2016-1-8 08:29:55 | 显示全部楼层
顶啊,就是很奇怪, Data_H = AD1_ReadData();没有任何问题,但是Data_L = AD1_ReadData();就不行了、、、为什么啊。。。
回复

使用道具 举报

9

主题

103

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
228
金钱
228
注册时间
2016-7-4
在线时间
47 小时
发表于 2016-7-18 13:53:42 | 显示全部楼层
我也遇到过,但解决了,链接查看:http://www.openedv.com/thread-78102-1-1.html
回复

使用道具 举报

1

主题

32

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
399
金钱
399
注册时间
2018-5-1
在线时间
145 小时
发表于 2018-6-4 21:46:59 | 显示全部楼层
楼主解决了么
回复

使用道具 举报

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

本版积分规则



关闭

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

正点原子公众号

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

GMT+8, 2025-5-30 21:26

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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