OpenEdv-开源电子网

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

写SPI的时候,程序一直卡死在一个等待位上,求解决!

[复制链接]

5

主题

18

帖子

0

精华

初级会员

Rank: 2

积分
58
金钱
58
注册时间
2013-5-4
在线时间
0 小时
发表于 2013-5-12 15:15:17 | 显示全部楼层 |阅读模式
u8 SPI_SendByte(u8 byte)
{
  /* Loop while DR register in not emplty */
  while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_TXE) == RESET);

  /* Send byte through the SPI2 peripheral */
  SPI_I2S_SendData(SPI1, byte);

  /* Wait to receive a byte */
   while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);

  /* Return the byte read from the SPI bus */
  return SPI_I2S_ReceiveData(SPI1);
}

程序就一直卡在   while (SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);   这,软件硬件模拟都通不过,我是用SPI写一个CC1101的驱动,求指教!
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

头像被屏蔽

2

主题

164

帖子

1

精华

禁止访问

积分
1316
金钱
1316
注册时间
2012-5-13
在线时间
127 小时
发表于 2013-5-12 15:33:06 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

5

主题

18

帖子

0

精华

初级会员

Rank: 2

积分
58
金钱
58
注册时间
2013-5-4
在线时间
0 小时
 楼主| 发表于 2013-5-12 15:40:39 | 显示全部楼层
回复【2楼】qq371833846:
---------------------------------
/* Enable SPI1 and GPIO clocks */
RCC_APB1PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
嗯嗯 已经开了!
回复 支持 反对

使用道具 举报

头像被屏蔽

2

主题

164

帖子

1

精华

禁止访问

积分
1316
金钱
1316
注册时间
2012-5-13
在线时间
127 小时
发表于 2013-5-12 22:28:14 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

5

主题

18

帖子

0

精华

初级会员

Rank: 2

积分
58
金钱
58
注册时间
2013-5-4
在线时间
0 小时
 楼主| 发表于 2013-5-14 14:03:46 | 显示全部楼层
回复【4楼】qq371833846:
---------------------------------
SPI_InitTypeDef  SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;


RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB , ENABLE);

/* Configure SPI1 pins: SCK and MOSI */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* MISO*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Configure I/O for Flash Chip select (NSS)*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

/* Configure I/O for C6,PC7,GD0,GD2  */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7| GPIO_Pin_6;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
//GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
/* Deselect the FLASH: Chip Select high */
//SPI_FLASH_CS_HIGH();


/* Enable SPI1 and GPIO clocks */
RCC_APB1PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);


/* SPI1 configuration */
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//SPI_Direction_2Lines_RxOnly;//SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);

/* Enable SPI1  */
SPI_Cmd(SPI1, ENABLE);
回复 支持 反对

使用道具 举报

23

主题

292

帖子

0

精华

高级会员

Rank: 4

积分
501
金钱
501
注册时间
2013-9-17
在线时间
17 小时
发表于 2013-11-30 03:31:38 | 显示全部楼层
回复【5楼】a111204508_c:
---------------------------------
问题是否解决 了   分享
闷鱼闷闷不乐吃焖鱼
回复 支持 反对

使用道具 举报

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

本版积分规则



关闭

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

正点原子公众号

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

GMT+8, 2025-7-8 11:47

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

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