[其他ST产品] 卡壳啦!卡壳啦!有人用过m25p16吗?

[复制链接]
 楼主| kfawj 发表于 2008-7-25 16:27 | 显示全部楼层 |阅读模式
S -----> Gnd
W -----> Vcc
Hold --> Vcc

无论是读ID,还是读数据区,D线就是没有数据输出!

(stm32f103)
 楼主| kfawj 发表于 2008-7-26 08:45 | 显示全部楼层

不会吧?!!!!!!!!

哪位用过帮助指点一二呀?
是不是把程序贴上来?
香水城 发表于 2008-7-26 08:48 | 显示全部楼层

你的线路图呢?你的程序呢?

 楼主| kfawj 发表于 2008-7-26 17:34 | 显示全部楼层

收到!周一,贴上!

芯片我已经换了一片了,还是不行。
(我怕与调液晶似的,就换一片)
(真没有想到液晶是坏的)
 楼主| kfawj 发表于 2008-7-28 08:42 | 显示全部楼层

头文件(m25p16.h)

#ifndef __M25P16
#define __M25P16
#include "stm32f10x_GPIO.h"

/****************************************************
 S -----> Gnd
 W -----> Vcc
 Hold --> Vcc
 ****************************************************/
#define M25P16_C         GPIOC,GPIO_Pin_10
#define M25P16_D         GPIOC,GPIO_Pin_11
#define M25P16_Q         GPIOC,GPIO_Pin_12

#define M25P16_WREN       0x06
#define M25P16_WRDI       0x04
#define M25P16_RDID       0x9F
#define M25P16_RDSR       0x05
#define M25P16_WRSR       0x01
#define M25P16_READ       0x03
#define M25P16_Fast_READ  0x0B
#define M25P16_PP         0x02
#define M25P16_SE         0xD8
#define M25P16_BE         0xC7
#define M25P16_DP         0xB9
#define M25P16_RES        0xAB

void M25P16_WR(u8 Dat);
u8 M25P16_RD(void);
void M25P16_RD_Bytes(u8 Page, u16 Addr, u8 *Dat, u8 Len);
void M25P16_WR_Bytes(u8 Page, u16 Addr, u8 *Dat, u8 Len);
#endif
 楼主| kfawj 发表于 2008-7-28 08:43 | 显示全部楼层

程序部分(m25p16.c)比较简单

#include "M25p16.h"

void M25P16_WR(u8 Dat)
{
  u8 i,j;
  j=Dat;
  for(i=0;i<8;i++){
    if(j & 0x80)
      GPIO_SetBits(M25P16_D);
    else
      GPIO_ResetBits(M25P16_D);
    GPIO_ResetBits(M25P16_C);
    GPIO_SetBits(M25P16_C);
    j <<= 1;
  }
}

u8 M25P16_RD(void)
{
  u8 i,j;
  j=0;
  for(i=0;i<8;i++){
    j <<= 1;
    GPIO_ResetBits(M25P16_C);
    if(GPIO_ReadInputDataBit(M25P16_Q))
      j |= 0x01;
    else
      j &= 0xFE;
    GPIO_SetBits(M25P16_C);
  }
  return j;
}

/*******************************************************
  Write Len Datas on the Address of the page
  Page 0x00~0x1F
  Addr 0x0000~0xFFFF
  Len  0x01~0xFF
 *******************************************************/
void M25P16_WR_Bytes(u8 Page, u16 Addr, u8 *Dat, u8 Len)
{
  u8 i;
  u8 AddH,AddL;
  u8 DLen;
  u8 *p;
  
  AddH = Addr >>8;
  AddL = Addr & 0x00FF;
  DLen = Len;
  p = Dat;
  
  M25P16_WR(M25P16_WREN);
  M25P16_WR(M25P16_PP);
  M25P16_WR(Page);
  M25P16_WR(AddH);
  M25P16_WR(AddL);
  for(i=0;i<DLen;i++){
    M25P16_WR(*p);
    p++;
  }
  M25P16_WR(M25P16_WRDI);
}

/*******************************************************
  Read Len Datas on the Address of the page
  Page 0x00~0x1F
  Addr 0x0000~0xFFFF
  Len  0x01~0xFF
 *******************************************************/
void M25P16_RD_Bytes(u8 Page, u16 Addr, u8 *Dat, u8 Len)
{
  u8 i;
  u8 AddH,AddL;
  u8 DLen;
  u8 *p;
  
  AddH = Addr >>8;
  AddL = Addr & 0x00FF;
  DLen = Len;
  p = Dat;
   
  //M25P16_WR(M25P16_WREN);
  M25P16_WR(M25P16_READ);
  M25P16_WR(Page);
  M25P16_WR(AddH);
  M25P16_WR(AddL);
  for(i=0;i<DLen;i++){
    *p = M25P16_RD();    
    p++;
  }
  //M25P16_WR(M25P16_WRDI);
}
 楼主| kfawj 发表于 2008-7-28 10:19 | 显示全部楼层

应该不用电路图了吧

各位帮助看一下,
程序是不是有问题呀?
Q端(C12)设为悬浮输入,弱上拉,弱下拉,复合推挽,复合极漏均无回数。

郁闷……
(不会是芯片不好吧)我已经换过一片m25p16啦。
yur12345 发表于 2008-7-28 15:22 | 显示全部楼层

s 不能接GND吧

s 不能直接接GND,接IO
 楼主| kfawj 发表于 2008-7-28 16:32 | 显示全部楼层

哦……?

你指的是网上的一个程序吗?
我好像看到过类似图。
另外,我的程序是不是存在问题呢?
 楼主| kfawj 发表于 2008-7-29 11:19 | 显示全部楼层

对啦!

to yur12345:这种做法是不是想屏蔽c上的干扰,或是误动作呢?
还是出于什么原因要控制S(片选)呢?
yur12345 发表于 2008-7-29 13:09 | 显示全部楼层

只知道写操作要用S

PP:
Chip Select (S) must be driven High after the
eighth bit of the last data byte has been latched in,
otherwise the Page Program (PP) instruction is not
executed.
CE,BE 也一样。

读不知有没有影响。

另:
CLK<20M。

fC fC
  Clock Frequency for the following instructions: FAST_READ,
  PP, SE, BE, RES, WREN, WRDI, RDID, RDSR, WRSR
  D.C. 50 MHz

fR 
  Clock Frequency for READ instructions D.C. 20 MHz
 楼主| kfawj 发表于 2008-7-30 09:22 | 显示全部楼层

啊?

S还要用呀。
我又要去找空闲的IO啦。
原以为spi三根线就够啦。
谢谢楼上。调试成功。
但好像等待(WEL,WIP)标志位时间长了一点。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

44

主题

293

帖子

2

粉丝
快速回复 在线客服 返回列表 返回顶部