你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

单片机IO口模拟SPI,读取不到发回来的数,确认管脚上有高...

[复制链接]
any_014 提问时间:2015-8-10 16:16 /
阅读主题, 点击返回1楼
收藏 评论13 发布时间:2015-8-10 16:16
13个回答
any_014 回答时间:2015-8-19 09:20:17
觉得也有可能是经过高速光耦,有一定的延时,读取的时刻不对。
enjoyfreescal 回答时间:2015-8-19 17:04:42
any_014 发表于 2015-8-18 17:28
程序已上传,在一口,能抽空帮我看下吗?
自己感觉是没问题的,也许是自己检查不出来... ...

PB4默认是JTAG口需要重映射。
  1. #include "gpio.h"

  2. void GPIO_Config(void)
  3. {
  4.         GPIO_InitTypeDef GPIO_InitStructure;
  5.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);//使能复用时钟
  6.         GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);//JTAG 口IO重映射
  7.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
  8.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
  9.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;       
  10.         GPIO_Init(GPIOA, &GPIO_InitStructure);
  11.        
  12.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_5;
  13.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  14.         GPIO_Init(GPIOB, &GPIO_InitStructure);
  15.        
  16.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  17.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  18.         GPIO_Init(GPIOB, &GPIO_InitStructure);
  19.        
  20.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
  21.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
  22.         GPIO_Init(GPIOD, &GPIO_InitStructure);
  23. }
复制代码
any_014 回答时间:2015-8-22 15:24:03
enjoyfreescal 发表于 2015-8-19 17:04
PB4默认是JTAG口需要重映射。

谢谢回复,查了下,确实是默认JATG模式。
然后就修改了下,但还是没什么用。
  1. void GPIO_Config(void)
  2. {
  3.         GPIO_InitTypeDef GPIO_InitStructure;
  4.         RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD | RCC_APB2Periph_AFIO, ENABLE);
  5.        
  6.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
  7.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
  8.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;       
  9.         GPIO_Init(GPIOA, &GPIO_InitStructure);
  10.        
  11.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2;
  12.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_OD;
  13.         GPIO_Init(GPIOD, &GPIO_InitStructure);
  14.        
  15.         GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE);
  16.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_5;
  17.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  18.         GPIO_Init(GPIOB, &GPIO_InitStructure);
  19.        
  20.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
  21.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  22.         GPIO_Init(GPIOB, &GPIO_InitStructure);       
  23. }
复制代码
enjoyfreescal 回答时间:2015-8-24 16:06:40
any_014 发表于 2015-8-22 15:24
谢谢回复,查了下,确实是默认JATG模式。
然后就修改了下,但还是没什么用。
...

还要开启在Debug模式时,使能相应IO口,DBGMCU->CR &= ~0x00000020;
12

所属标签

相似问题

关于意法半导体
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
招聘信息
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
关注我们
st-img 微信公众号
st-img 手机版