[ZLG-MCU] 关FM25CL64读写问题

[复制链接]
 楼主| linhai1986 发表于 2009-7-4 16:17 | 显示全部楼层 |阅读模式
我在SPI总线上挂了四片Flash,一片铁电FM25CL64,使用相同的程序读写Flash都正确,写铁电就是无法读出,我用示波器也观看波形,发送数据的时序波形都正确,可是读数据总是0xFF,芯片也换过了,问题依旧,大家看看最有可能出问题的是哪啊,谢谢! 
 楼主| linhai1986 发表于 2009-7-7 21:34 | 显示全部楼层

自己顶一下

  
Harvard 发表于 2016-4-25 14:40 | 显示全部楼层
遇到楼主一样的 问题  求教解决办法 ..
Harvard 发表于 2016-4-25 14:40 | 显示全部楼层
  1. /********************************************************************************
  2. *        项目名称:        SCC290
  3. *   文件名称:   drv_FM25CL64.c
  4. *        DATE:                2014
  5. *        AUTHOR:                Shine
  6. *        要点:                 
  7. *                               
  8. * -----------------------------------------------------------------------------*
  9. *********************************************************************************/
  10. #include "config.h"

  11. void FM25CL64_NOP(void )
  12. {
  13.     u08 i = 0 ;
  14.     for( i=0; i<200;i++ )
  15.     {
  16.         ;
  17.     }
  18. }



  19. /*
  20. *   函数: void FM25CL64_init( void )

  21. *   输入:
  22. *   输出:
  23. *   说明: 对于没有WP保护和HOLD控制需求的应用,初始化wp hold 2引脚.
  24. */
  25. void FM25CL64_init( void )
  26. {   
  27.     _delay_ms(2);
  28.     FM25CL64_WP = 1 ;
  29.     FM25CL64_HOLD= 1;

  30. }




  31. /*
  32. *  向FM25CL64写入一个字节
  33. */
  34. unsigned char In_FM25CL64_Byte()
  35. {
  36.     unsigned char in=0,i;
  37.     for(i=0;i<8;i++)
  38.     {
  39.         FM25CL64_SCK=0;
  40.         FM25CL64_NOP();
  41.         FM25CL64_NOP();
  42.         FM25CL64_NOP();
  43.         FM25CL64_SCK=1;
  44.         in=in<<1;
  45.         if( FM25CL64_SO )
  46.         {
  47.             in|=0x01;
  48.         }
  49.     }
  50.    
  51.     return(in);
  52. }

  53. /*
  54. *   从FRAM读取一个字节
  55. */
  56. void Out_FM25CL64_Byte(unsigned char byte)
  57. {
  58.     unsigned char i=0;
  59.     for(i=0;i<8;i++)
  60.     {
  61.         FM25CL64_SCK=0;
  62.         FM25CL64_NOP();
  63.         FM25CL64_NOP();
  64.         FM25CL64_NOP();
  65.         FM25CL64_SI= (byte&0x80);
  66.         FM25CL64_SCK=1;
  67.         byte<<=1;
  68.     }
  69.         FM25CL64_SCK=0;
  70.         FM25CL64_SI=0;
  71.     return;
  72. }

  73. /*
  74. *   读取FRAM的状态
  75. *
  76. */
  77. unsigned char ReadState()
  78. {
  79.     unsigned char r;
  80.     FM25CL64_SCK=0;
  81.     FM25CL64_CS=0;
  82.     Out_FM25CL64_Byte(FM25CL64_RDSR_INST);
  83.     FM25CL64_NOP();
  84.     FM25CL64_NOP();
  85.     FM25CL64_NOP();
  86.     r=In_FM25CL64_Byte();
  87.     FM25CL64_SCK=0;
  88.     FM25CL64_NOP();
  89.     FM25CL64_NOP();
  90.     FM25CL64_NOP();
  91.     FM25CL64_CS=1;
  92.     return(r);
  93. }

  94. /*
  95. * 检查读状态
  96. */
  97. void wip_poll()
  98. {
  99.     unsigned char i=0,r;
  100.     do
  101.     {
  102.         r=ReadState();
  103.         i++;
  104.     }
  105.     while((r&0x01)&&i<0x99);
  106. }

  107. /* 写入使能 */
  108. void WriteEnable( void )
  109. {
  110.     FM25CL64_SCK=0;
  111.     FM25CL64_CS=0;
  112.     Out_FM25CL64_Byte(FM25CL64_WREN_INST);
  113.     FM25CL64_SCK=0;
  114.     FM25CL64_CS=1;
  115.     return;
  116. }
  117. /*
  118. *
  119. */
  120. void WriteState(void)
  121. {
  122.     WriteEnable();
  123.     FM25CL64_SCK=0;
  124.     FM25CL64_CS=0;
  125.     Out_FM25CL64_Byte(FM25CL64_WRSR_INST);
  126.     Out_FM25CL64_Byte(FM25CL64_STATUS_REG);
  127.     FM25CL64_SCK=0;
  128.     FM25CL64_CS=1;
  129.     wip_poll();
  130. }

  131. /* 读取存储单元的内容,一个字节 */
  132. unsigned char Read_FM25CL64_Byte(unsigned int address)
  133. {
  134.     unsigned char dat;
  135.     FM25CL64_SCK=0;
  136.     FM25CL64_CS=0;
  137.     FM25CL64_NOP();
  138.     Out_FM25CL64_Byte(FM25CL64_READ_INST);
  139.     FM25CL64_NOP();
  140.     FM25CL64_NOP();
  141.     Out_FM25CL64_Byte((address&0xff00)>>8);
  142.     FM25CL64_NOP();
  143.     FM25CL64_NOP();
  144.     Out_FM25CL64_Byte(address&0x00ff);
  145.     FM25CL64_NOP();
  146.     FM25CL64_NOP();
  147.     dat=In_FM25CL64_Byte();
  148.     FM25CL64_SCK=0;
  149.     FM25CL64_CS=1;
  150.     return(dat);
  151. }

  152. /* 读取存储单元的内容,多个字节 */
  153. void Read_FM25CL64_nByte(unsigned int address,unsigned char  *dat,unsigned char number)
  154. {
  155.     unsigned char i;
  156.     FM25CL64_SCK=0;
  157.     FM25CL64_CS=0;
  158.     FM25CL64_NOP();
  159.     Out_FM25CL64_Byte(FM25CL64_READ_INST);
  160.     FM25CL64_NOP();
  161.     FM25CL64_NOP();
  162.     Out_FM25CL64_Byte((address&0xff00)>>8);
  163.     FM25CL64_NOP();
  164.     FM25CL64_NOP();
  165.     Out_FM25CL64_Byte(address&0x00ff);
  166.     FM25CL64_NOP();
  167.     FM25CL64_NOP();
  168.     for(i=0;i<number;i++)
  169.     {
  170.         *(dat+i)=In_FM25CL64_Byte();
  171.     }
  172.     FM25CL64_SCK=0;
  173.     FM25CL64_CS=1;
  174.     return;
  175. }

  176. /* 写入一个数据到指定位置 */
  177. void Write_FM25CL64_Byte(unsigned int address,unsigned char dat)
  178. {                                                                 
  179.     WriteEnable();
  180.     FM25CL64_SCK=0;
  181.     FM25CL64_CS=0;
  182.     Out_FM25CL64_Byte(FM25CL64_WRITE_INST);
  183.     FM25CL64_NOP();
  184.     FM25CL64_NOP();
  185.     Out_FM25CL64_Byte((address&0xff00)>>8);
  186.     FM25CL64_NOP();
  187.     FM25CL64_NOP();
  188.     Out_FM25CL64_Byte(address&0x00ff);
  189.     FM25CL64_NOP();
  190.     FM25CL64_NOP();
  191.     Out_FM25CL64_Byte(dat);
  192.     FM25CL64_SCK=0;
  193.     FM25CL64_CS=1;
  194.     wip_poll();
  195.     return;
  196. }

  197. /* 写入多个字节到指定位置 */
  198. void Write_FM25CL64_nByte(unsigned int address,unsigned char  *dat,unsigned char number)
  199. {
  200.     unsigned char i;
  201.     WriteEnable();
  202.     FM25CL64_SCK=0;
  203.     FM25CL64_CS=0;
  204.    
  205.     Out_FM25CL64_Byte(FM25CL64_WRITE_INST);
  206.     FM25CL64_NOP();
  207.     FM25CL64_NOP();
  208.     Out_FM25CL64_Byte((address&0xff00)>>8);
  209.     FM25CL64_NOP();
  210.     FM25CL64_NOP();
  211.     Out_FM25CL64_Byte(address&0x00ff);
  212.     FM25CL64_NOP();
  213.     FM25CL64_NOP();
  214.     for(i=0;i<number;i++)
  215.     {
  216.         Out_FM25CL64_Byte(*(dat+i));
  217.     }
  218.    
  219.     FM25CL64_SCK=0;
  220.     FM25CL64_CS=1;
  221.     wip_poll();
  222.     return;
  223. }

Harvard 发表于 2016-4-25 14:41 | 显示全部楼层
说明下.这个代码来源于网络 ,之前在c8051f单片机可以正常使用. 换了ARM M0单片机,就出现问题了
您需要登录后才可以回帖 登录 | 注册

本版积分规则

172

主题

1451

帖子

0

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