搜索
bottom↓
回复: 13

有谁能提供通过SPI口向外部flash通讯的程序?谢了!急需!

[复制链接]

出0入0汤圆

发表于 2005-10-11 17:02:43 | 显示全部楼层 |阅读模式
cpu 为mega128,外部flash为AT45DB161B,有谁有成功的例子,希望能提供给我,先谢了!

出0入0汤圆

发表于 2005-10-11 18:01:22 | 显示全部楼层
请问楼主,AT45DB161B是多大的flash,大概多少RMB啊?

出0入0汤圆

发表于 2005-10-11 19:08:46 | 显示全部楼层
18.00

出0入0汤圆

 楼主| 发表于 2005-10-11 21:26:02 | 显示全部楼层
2MB字节,存储量较大的串行存储芯片,大概十几元,很便宜的。

我用马老师提供的一段SPI通讯程序调试的,可老是调不通,如果谁有成功的案例,不妨粘上来,谢谢了!

出0入0汤圆

发表于 2006-2-15 11:04:30 | 显示全部楼层
请问楼主,做得如何了;我也想该如何来做啊;可以讨论下么?

出0入0汤圆

发表于 2006-2-16 16:36:17 | 显示全部楼层
我想用AT25F2048来做,但也没人来讨论
头像被屏蔽

出0入0汤圆

发表于 2006-4-12 01:18:14 | 显示全部楼层
我在使用M25P64,MEGA162,SPI通信,调试没成功。



想请求技术支持。谢谢

出0入0汤圆

发表于 2006-4-12 07:04:36 | 显示全部楼层
点击此处下载armok01114386.rar





#define    AT1M   0x3

#define    AT2M   0x5

#define    AT4M   0x7

#define    AT8M   0x9

#define    AT16M  0xB

#define    AT32M  0xD

#define    AT64M  0xF

#define    AT128M 0x4

#define    AT256M 0x6

#define    AT512M 0x8



/*

  Function : sets CS low to high and high to low

  Arguments : none

  Returns : none

*/

void AT45_Reset(void);



/*

  Function : waits until memory is ready

  Arguments : none

  Returns : none

*/

void AT45_Ready(void);



/*

  Function : detects type of dataflash

  Arguments : none

  Returns :

    Hex   Binary  Device Density

    0x3   0 0 1 1 1M

    0x5   0 1 0 1 2M

    0x7   0 1 1 1 4M

    0x9   1 0 0 1 8M

    0xB   1 0 1 1 16M

    0xD   1 1 0 1 32M

    0xF   1 1 1 1 64M

    0x4   0 1 0 0 128M

    0x6   0 1 1 0 256M

    0x8   1 0 0 0 512M

*/

unsigned char AT45_DetectDevice(void);



/*

  Function : reads dataflash memory

  Arguments :

    address 32bit (r,PA12-PA0,BA9-BA0)

    r - reserved

    PA12-PA0 - specify page to be read

    BA9-BA0 - specify the starting byte address of page



    pointer_ram - pointer to array to be written with data

    n - number of bytes to be read

  Returns : none

*/

void AT45_ContinousArrayRead(unsigned long address, unsigned char *pointer_ram ,unsigned long n);



/*

  Function : writes buffer

  Arguments :

    buffer - has to be '1' or '2'

    address - specify the address of first byte in buffer to be written

    pointer_ram - pointer to array with data to be written

    n - number of bytes to write

  Returns : none

*/

void AT45_BufferWrite(unsigned char buffer, unsigned long address, unsigned char *pointer_ram ,unsigned long n);



/*

  Function : reads buffer

  Arguments : none

    buffer - has to be '1' or '2'

    address - specify the first byte in buffer to read

    pointer_ram - pointer to array to be written with data

    n - number of bytes to read

  Returns : none

*/

void AT45_BufferRead(unsigned char buffer, unsigned long address, unsigned char *pointer_ram ,unsigned long n);



/*

  Function : transfers data in buffer to main memory

  Arguments :

    erase - '1' transfers data with page erase, '0' transfers data without page erase

    buffer - has to be '1' or '2'

    address : PA12-PA0

      PA12-PA0 - address of page in memory to be written

  Returns : none

*/

void AT45_BufferToMainMemory(unsigned char erase, unsigned char buffer, unsigned long address);



/*

  Function : programs main memory

  Arguments :

    buffer - has to be '1' or '2'

    address 32bit (r,PA12-PA0,BA9-BA0)

      r - reserved

      PA12-PA0 - specify page to be written

      BFA9-BFA0 - select the first byte in page to be written

    pointer_ram - pointer to array with data to be written

    n - number of bytes to write

  Returns : none

*/

void AT45_MainMemoryProgram(unsigned char buffer, unsigned long address, unsigned char *pointer_ram ,unsigned long n);



/*

  Function : transfers page from main memory to buffer

  Arguments :

    buffer - has to be '1' or '2'

    address PA12-PA0

      PA12-PA0 - specify page to transfer

  Returns : none

*/

void AT45_MainMemoryToBufferTransfer(unsigned char buffer, unsigned long address);



/*

  Function : compares buffer with selected page in main memory

  Arguments :

    buffer - has to be '1' or '2'   

    address PA12-PA0

      PA12-PA0 - specify page to compare

  Returns :

    '1' - data in page MATCH data in buffer

    '0' - data in page does NOT MATCH data in buffer

*/

unsigned char AT45_MainMemoryToBufferCompare(unsigned char buffer, unsigned long address);



/*

  Function : rewrites contents in selected page

  Arguments :

    buffer - has to be '1' or '2'   

    address PA12-PA0

      PA12-PA0 - specify page to be rewritten

  Returns : none

*/

void AT45_AutoPageRewrite(unsigned char buffer, unsigned long address);



/*

  Function : erase selected page

  Arguments :

    address PA12-PA0

      PA12-PA0 - specify page to be erased

  Returns : none

*/

void AT45_PageErase(unsigned long address);



/*

  Function : erase selected block (8 pages)

  Arguments :

    address PA12-PA3

      PA12-PA3 - specify block to be erased

  Returns : none

*/

void AT45_BlockErase(unsigned long address);

出0入0汤圆

发表于 2006-4-12 07:13:01 | 显示全部楼层
看看带 语法着色 的代码:



http://www.vwtool.com/temp/dataflash.htm

出0入0汤圆

发表于 2006-7-25 09:21:57 | 显示全部楼层
To shangdawei:

  包里缺spi.c

出0入0汤圆

发表于 2006-8-10 16:09:51 | 显示全部楼层
各位仁兄:

       怎么向SPI口控制的AT45DB写入中文字库HZK16?请各位多多开导。

出0入0汤圆

发表于 2006-8-11 08:54:48 | 显示全部楼层
swust 兄的问题我哦也在想啊,通过串口的话需要使用PC的某种协议啊,否则太容易出错啦

出0入0汤圆

发表于 2006-10-28 17:20:00 | 显示全部楼层
我用mega64与AT45DB011B通讯,不知道我要一下读264字节的时候该怎么写,

void Read_Flash_Page(unsigned int nPageIndex)

{

        unsigned int        i;

        ///< 从flash中读取数据

        SPI_CS_EN();

        SPDR = 0xD2;

        while(!(SPSR & 0x80));

        SPDR = (char)(nPageIndex >> 7);

        while(!(SPSR & 0x80));

        SPDR = (char)(nPageIndex << 1);

        while(!(SPSR & 0x80));

        SPDR = 0x00;

        while(!(SPSR & 0x80));

        ///< 等待32个clk

        SPDR = 0x00;

        while(!(SPSR & 0x80));

        SPDR = 0x00;

        while(!(SPSR & 0x80));

        SPDR = 0x00;

        while(!(SPSR & 0x80));

        SPDR = 0x00;

        while(!(SPSR & 0x80));

        for(i = 0; i < 264; i ++)

        {

                while(!(SPSR & 0x80));       

                g_bBuffer = SPDR;

                g_nSendDatacnt++;

        }

         LED1_OFF();

        SPI_CS_UNEN();

}

程序跑进for(i = 0; i < 264; i ++)

        {

                while(!(SPSR & 0x80));       

                g_bBuffer = SPDR;

                g_nSendDatacnt++;

        }

之后,就出不来了,在这里我想问高手们一个问题,单片机是怎么知道有收到数据的?平时我没对spi操作的时候,sck不是一直是保持低或者高的吗?那我刚刚写完命令字,sck应该保持电平才对,这时候flash发送数据出来,没有sck怎么发送?还是miso平时是释放状态,从机要发送数据的时候,会将miso拉高或者拉低?楼主你也在做这方面的东西,大家一起讨论一下如何?能否给个联系方式,我的msn:  Zhougm1981@hotmail.com

出0入0汤圆

发表于 2006-10-28 17:36:30 | 显示全部楼层
TO all

1:AT45DB系列的驱动可以到atmel.com查找相关的application note.

2:AT25F2048系列Flash只能擦写1万次,也是刚推出的,所以目前用的人不是很多



如果需要申请样片,请和我联系
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-10 04:30

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

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