搜索
bottom↓
回复: 280

ZIGBEE开发STEP BY STEP

[复制链接]

出0入0汤圆

发表于 2008-2-18 13:51:58 | 显示全部楼层 |阅读模式
年前终于拿到自己做的ZIGBEE应用板子!现在拿出来晒一下!!
1

本方案采用ATMEGA128+RTL8019+AT45DB161+XBEEPRO+SD2201时钟模块!!
2

阿莫论坛20周年了!感谢大家的支持与爱护!!

曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……

出0入0汤圆

 楼主| 发表于 2008-2-18 13:58:51 | 显示全部楼层
下面是ZIGBEE的一些资料!
点击此处打开ourdev_215297.pdf(文件大小:154K)
2
3
点击此处打开ourdev_215300.pdf(文件大小:492K)
5

出0入0汤圆

 楼主| 发表于 2008-2-18 14:03:56 | 显示全部楼层
下面发一些ZIGBEE的实物图片!!
1
2
3
4
5

出0入0汤圆

 楼主| 发表于 2008-2-18 14:08:52 | 显示全部楼层
板子原理图
点击此处打开ZIGBEE2NET.pdf(文件大小:614K)
2
3
4
5
6

出0入0汤圆

 楼主| 发表于 2008-2-18 14:13:35 | 显示全部楼层
1.硬件调试:
首先焊接电源模块LM2576-5V和LM1117-3.3V,用万用表测试输出电压是否正确!!
完成后开始将ATMEGA128 RTL8019AS,32KRAM BS62LV256以及复位电路,ISP,JTAG,串口电路MAX232等焊接!
头像被屏蔽

出0入0汤圆

发表于 2008-2-18 14:17:53 | 显示全部楼层
谢谢共享。先置COOL1

既然标题是“Step by Step”,应该还会有更多的资料或代码上传? 期待啊。。

出0入0汤圆

发表于 2008-2-18 15:24:25 | 显示全部楼层
板子原理图打开里面是pcb图,麻烦楼主看一下

出0入0汤圆

发表于 2008-2-18 20:21:46 | 显示全部楼层
楼主啊,你这个焊接调试好的板子多少钱啊 ?

出0入0汤圆

发表于 2008-2-18 21:27:50 | 显示全部楼层
这个zigbee的模块很贵的,用不起!我手上就有3套完整的,大概在06年来推的时候送的,用的是Freescale的方案,pro版有效距离可以达到3KM(不确定,但是至少有1.5KM),大概10K的量要10几个美金一个

出0入0汤圆

 楼主| 发表于 2008-2-19 09:37:02 | 显示全部楼层
2.硬件测试串口,RAM,RTL8019AS已经正确
测试代码如下!
点击此处下载ourdev_215637.rar(文件大小:223K)

串口0 115200
输出如下!
9:46:10> now uart1 !
9:46:10> delay 1s!
9:46:11> now uart0!
9:46:11>
9:46:11>  RAMTEST START !
9:46:11> -----POINTER  READ AND WRITE EXTERNAL 32K RAM----------
9:46:11> 0 READ AND WRITE NO WAIT  PC7 RELEASED !
9:46:12> init system ok!
9:46:12> now test system-ram  all is 32k !
9:46:12> ----now write  ram  0000
9:46:12> ----write ok
9:46:12> ----now check write
9:46:12> ---- test system-ram  end!
9:46:12> ----now write  ram  0055
9:46:12> ----write ok
9:46:12> ----now check write
9:46:12> ---- test system-ram  end!
9:46:12> ----now write  ram  00aa
9:46:12> ----write ok
9:46:12> ----now check write
9:46:12> ---- test system-ram  end!
9:46:12> ----now write  ram  0000
9:46:12> ----write ok
9:46:12> ----now check write
9:46:12> ---- test system-ram  end!
9:46:12> 1 READ AND WRITE 1 WAIT  PC7 RELEASED !
9:46:12> init system ok!
9:46:12> now test system-ram  all is 32k !
9:46:12> ----now write  ram  0000
9:46:12> ----write ok
9:46:12> ----now check write
9:46:12> ---- test system-ram  end!
9:46:12> ----now write  ram  0055
9:46:12> ----write ok
9:46:12> ----now check write
9:46:12> ---- test system-ram  end!
9:46:12> ----now write  ram  00aa
9:46:13> ----write ok
9:46:13> ----now check write
9:46:13> ---- test system-ram  end!
9:46:13> ----now write  ram  0000
9:46:13> ----write ok
9:46:13> ----now check write
9:46:13> ---- test system-ram  end!
9:46:13> 2 READ AND WRITE 2 WAIT  PC7 RELEASED !
9:46:13> init system ok!
9:46:13> now test system-ram  all is 32k !
9:46:13> ----now write  ram  0000
9:46:13> ----write ok
9:46:13> ----now check write
9:46:13> ---- test system-ram  end!
9:46:13> ----now write  ram  0055
9:46:13> ----write ok
9:46:13> ----now check write
9:46:13> ---- test system-ram  end!
9:46:13> ----now write  ram  00aa
9:46:13> ----write ok
9:46:13> ----now check write
9:46:13> ---- test system-ram  end!
9:46:13> ----now write  ram  0000
9:46:13> ----write ok
9:46:13> ----now check write
9:46:13> ---- test system-ram  end!
9:46:13> 3 READ AND WRITE 2+1 WAIT  PC7 RELEASED !
9:46:14> init system ok!
9:46:14> now test system-ram  all is 32k !
9:46:14> ----now write  ram  0000
9:46:14> ----write ok
9:46:14> ----now check write
9:46:14> ---- test system-ram  end!
9:46:14> ----now write  ram  0055
9:46:14> ----write ok
9:46:14> ----now check write
9:46:14> ---- test system-ram  end!
9:46:14> ----now write  ram  00aa
9:46:14> ----write ok
9:46:14> ----now check write
9:46:14> ---- test system-ram  end!
9:46:14> ----now write  ram  0000
9:46:14> ----write ok
9:46:14> ----now check write
9:46:14> ---- test system-ram  end!
9:46:14> ******POINTER  READ AND WRITE EXTERNAL 32K RAM*******
9:46:14>
9:46:14> -----BUFFER READ AND WRITE EXTERNAL 32K RAM----------
9:46:14> 4  READ AND WRITE  NOWAIT PC7  NO RELEASED !
9:46:14> init system ok!
9:46:14> now test system-ram  all is 32k !
9:46:14> ----now write  ram  0000
9:46:14> ----write ok
9:46:14> ----now check write
9:46:14> ---- test system-ram  end!
9:46:14> ----now write  ram  0055
9:46:14> ----write ok
9:46:14> ----now check write
9:46:14> ---- test system-ram  end!
9:46:14> ----now write  ram  00aa
9:46:15> ----write ok
9:46:15> ----now check write
9:46:15> ---- test system-ram  end!
9:46:15> ----now write  ram  0000
9:46:15> ----write ok
9:46:15> ----now check write
9:46:15> ---- test system-ram  end!
9:46:15> 5  READ AND WRITE  1 WAIT PC7  NO RELEASED !
9:46:15> init system ok!
9:46:15> now test system-ram  all is 32k !
9:46:15> ----now write  ram  0000
9:46:15> ----write ok
9:46:15> ----now check write
9:46:15> ---- test system-ram  end!
9:46:15> ----now write  ram  0055
9:46:15> ----write ok
9:46:15> ----now check write
9:46:15> ---- test system-ram  end!
9:46:15> ----now write  ram  00aa
9:46:15> ----write ok
9:46:15> ----now check write
9:46:15> ---- test system-ram  end!
9:46:15> ----now write  ram  0000
9:46:15> ----write ok
9:46:15> ----now check write
9:46:15> ---- test system-ram  end!
9:46:15> 6  READ AND WRITE  2WAIT PC7  NO RELEASED !
9:46:15> init system ok!
9:46:15> now test system-ram  all is 32k !
9:46:15> ----now write  ram  0000
9:46:15> ----write ok
9:46:15> ----now check write
9:46:15> ---- test system-ram  end!
9:46:16> ----now write  ram  0055
9:46:16> ----write ok
9:46:16> ----now check write
9:46:16> ---- test system-ram  end!
9:46:16> ----now write  ram  00aa
9:46:16> ----write ok
9:46:16> ----now check write
9:46:16> ---- test system-ram  end!
9:46:16> ----now write  ram  0000
9:46:16> ----write ok
9:46:16> ----now check write
9:46:16> ---- test system-ram  end!
9:46:16> 7  READ AND WRITE  2+1WAIT PC7  NO RELEASED !
9:46:16> init system ok!
9:46:16> now test system-ram  all is 32k !
9:46:16> ----now write  ram  0000
9:46:16> ----write ok
9:46:16> ----now check write
9:46:16> ---- test system-ram  end!
9:46:16> ----now write  ram  0055
9:46:16> ----write ok
9:46:16> ----now check write
9:46:16> ---- test system-ram  end!
9:46:16> ----now write  ram  00aa
9:46:16> ----write ok
9:46:16> ----now check write
9:46:16> ---- test system-ram  end!
9:46:16> ----now write  ram  0000
9:46:16> ----write ok
9:46:16> ----now check write
9:46:17> ---- test system-ram  end!
9:46:17>
9:46:17> *******BUFFER READ AND WRITE EXTERNAL 32K RAM***********
9:46:17> ---- RAM TEST OK!-----
9:46:17>
9:46:17>  now test rtl8019as!
9:46:17> now show first rtl8019as reg !
9:46:17>
9:46:17>  Realtek 8019AS Register dump
9:46:17>  REG  Page0 Page1 Page2 Page3
9:46:17> 0000    0021    0061    00a1    00e1  
9:46:17> 0001    002a    002a    002a    002a  
9:46:17> 0002    00a0    00a0    00a0    00a0  
9:46:17> 0003    0021    0021    0021    0021  
9:46:17> 0004    0042    0042    0042    0042  
9:46:17> 0005    000c    000c    000c    000c  
9:46:17> 0006    0048    0048    0048    0048  
9:46:17> 0007    0004    0004    0004    0004  
9:46:17> 0008    00e0    00e0    00e0    00e0  
9:46:17> 0009    0048    0048    0048    0048  
9:46:17> 000a    000a    000a    000a    000a  
9:46:17> 000b    00a8    00a8    00a8    00a8  
9:46:17> 000c    0002    0002    0002    0002  
9:46:17> 000d    00c1    00c1    00c1    00c1  
9:46:17> 000e    0010    0010    0010    0010  
9:46:17> 000f    0087    0087    0087    0087  
9:46:17> now init rtl8019as!
9:46:19> now show second rtl8019as reg !
9:46:19>
9:46:19>  Realtek 8019AS Register dump
9:46:19>  REG  Page0 Page1 Page2 Page3
9:46:19> 0000    0023    0063    00a3    00e3  
9:46:19> 0001    0000    006d    0046    0030  
9:46:19> 0002    00ff    0069    0060    0000  
9:46:19> 0003    0046    0072    00ff    000c  
9:46:19> 0004    0013    0072    0040    0080  
9:46:19> 0005    0000    006f    00ff    0020  
9:46:19> 0006    0000    006b    00ff    0000  
9:46:19> 0007    0080    0046    00ff    00ff  
9:46:19> 0008    00ff    0000    00ff    0000  
9:46:19> 0009    00ff    0005    00ff    00fe  
9:46:19> 000a    0050    0000    00ff    00ff  //50 RLT8019的ID
9:46:19> 000b    0070    0000    00ff    00fe  //70 RLT8019的ID
9:46:19> 000c    0036    0000    00c4    00ff  
9:46:19> 000d    0000    0000    00e0    00fe  
9:46:19> 000e    0000    0080    00d8    00ff  
9:46:19> 000f    0000    0000    0091    00ff  
9:46:19> ----test rtl8019as end!

出0入0汤圆

 楼主| 发表于 2008-2-19 09:40:53 | 显示全部楼层
3.现在开始测试UIP协议栈,显示网页

出0入0汤圆

 楼主| 发表于 2008-2-19 09:52:46 | 显示全部楼层
一次测试通过!!
实现PING web显示和连接成功
认证界面 登录名 admin 密码 12345

1

pingOK 了
2

实现TCP连接成功

3

实现web显示成功
4

出0入0汤圆

 楼主| 发表于 2008-2-19 13:42:27 | 显示全部楼层
4.现在开始测试LCD,at45DB61D,SD2201

出0入4汤圆

发表于 2008-2-19 17:15:22 | 显示全部楼层
电路图的图片看不清阿,请问有没有PDF的阿?
谢谢!

出0入0汤圆

 楼主| 发表于 2008-2-20 08:08:36 | 显示全部楼层
原理图PDF版本
点击此处打开ZIGBEE2NETSCH(文件大小:86K)

出0入0汤圆

发表于 2008-2-20 13:22:12 | 显示全部楼层
顶一下

出0入0汤圆

 楼主| 发表于 2008-2-21 13:59:10 | 显示全部楼层
4.1测试at45DB161D


#ifndef AT45DB161D_H
#define AT45DB161D_H
#include<global.h>
#include<iom128v.h>
#include<macros.h>
#include "at45db161d_commands.h"

#ifndef SPI

#define DATAOUT     11

#define DATAIN      12

#define SPICLOCK    13

#define SLAVESELECT 10

#define RESET        8

#define WP           7

/*
#define DF_CS_inactive digitalWrite(SLAVESELECT,HIGH)

#define DF_CS_active   digitalWrite(SLAVESELECT,LOW)
*/
/*
#define DF_CS_inactive    PORTB|=_BV(DDB0)

#define DF_CS_active      PORTB&=~_BV(DDB0)
*/
#define DF_CS_inactive    PORTB|=1
#define DF_CS_active      PORTB&=0xfe

#endif /* SPI */

#define READY_BUSY 0x80

#define COMPARE 0x40

#define PROTECT 0x02

#define PAGE_SIZE 0x01

#define DEVICE_DENSITY 0x2C

struct ATD45DB161D_ID
{
uint8_t manufacturer;      
uint8_t device[2];         
uint8_t extendedInfoLength;
};

void ATD45DB161D_Init(void);

uint8_t ReadStatusRegister(void);

void ReadManufacturerAndDeviceID(struct ATD45DB161D_ID *id);
               
void ReadMainMemoryPage(uint16_t page, uint16_t offset);

void ContinuousArrayRead(uint16_t page, uint16_t offset, uint8_t low);

void  BufferRead(uint8_t bufferNum, uint16_t offset, uint8_t low);

void  BufferWrite(uint8_t bufferNum, uint16_t offset);
               
void  BufferToPage(uint8_t bufferNum, uint16_t page, uint8_t erase);            

void  PageToBuffer(uint16_t page, uint8_t bufferNum);

void  PageErase(uint16_t page);
               
void  BlockErase(uint16_t block);

void  SectoreErase(uint8_t sector);

void  ChipErase(void);

void  BeginPageWriteThroughBuffer(uint16_t page, uint16_t offset, uint8_t bufferNum);
               
void  EndAndWait(void);

int8_t  ComparePageToBuffer(uint16_t page, uint8_t bufferNum);

void  DeepPowerDown(void);

void  ResumeFromDeepPowerDown(void);


#endif /* AT45DB161D_H */


#ifndef AT45DB161D_COMMANDS_H
#define AT45DB161D_COMMANDS_H

#define AT45DB161D_PAGE_READ 0xD2

#define AT45DB161D_CONTINUOUS_READ_LOW_FREQ 0x03

#define AT45DB161D_CONTINUOUS_READ_HIGH_FREQ 0x0B

#define AT45DB161D_BUFFER_1_READ_LOW_FREQ 0xD1

#define AT45DB161D_BUFFER_2_READ_LOW_FREQ 0xD3

#define AT45DB161D_BUFFER_1_READ 0xD4

#define AT45DB161D_BUFFER_2_READ 0xD6

#define AT45DB161D_BUFFER_1_WRITE 0x84

#define AT45DB161D_BUFFER_2_WRITE 0x87

#define AT45DB161D_BUFFER_1_TO_PAGE_WITH_ERASE 0x83

#define AT45DB161D_BUFFER_2_TO_PAGE_WITH_ERASE 0x86

#define AT45DB161D_BUFFER_1_TO_PAGE_WITHOUT_ERASE 0x88

#define AT45DB161D_BUFFER_2_TO_PAGE_WITHOUT_ERASE 0x89

#define AT45DB161D_PAGE_ERASE 0x81

#define AT45DB161D_BLOCK_ERASE 0x50

#define AT45DB161D_SECTOR_ERASE 0x7C

#define AT45DB161D_CHIP_ERASE_0 0xC7
#define AT45DB161D_CHIP_ERASE_1 0x94
#define AT45DB161D_CHIP_ERASE_2 0x80
#define AT45DB161D_CHIP_ERASE_3 0x9A

#define AT45DB161D_PAGE_THROUGH_BUFFER_1 0x82

#define AT45DB161D_PAGE_THROUGH_BUFFER_2 0x85

#ifdef AT45DB161D_EXPERT_MODE
/* Use the following commands at your own risk ! */
#define AT45DB161D_ENABLE_SECTOR_PROTECTION_0 0x3D
#define AT45DB161D_ENABLE_SECTOR_PROTECTION_1 0x2A
#define AT45DB161D_ENABLE_SECTOR_PROTECTION_2 0x7F
#define AT45DB161D_ENABLE_SECTOR_PROTECTION_3 0xA9

#define AT45DB161D_DISABLE_SECTOR_PROTECTION_0 0x3D
#define AT45DB161D_DISABLE_SECTOR_PROTECTION_1 0x2A
#define AT45DB161D_DISABLE_SECTOR_PROTECTION_2 0x7F
#define AT45DB161D_DISABLE_SECTOR_PROTECTION_3 0x9A

#define AT45DB161D_ERASE_SECTOR_PROTECTION_REGISTER_0 0x3D
#define AT45DB161D_ERASE_SECTOR_PROTECTION_REGISTER_0 0x2A
#define AT45DB161D_ERASE_SECTOR_PROTECTION_REGISTER_0 0x7F
#define AT45DB161D_ERASE_SECTOR_PROTECTION_REGISTER_0 0xCF

#define AT45DB161D_PROGRAM_SECTOR_PROTECTION_REGISTER_0 0x3D
#define AT45DB161D_PROGRAM_SECTOR_PROTECTION_REGISTER_1 0x2A
#define AT45DB161D_PROGRAM_SECTOR_PROTECTION_REGISTER_2 0x7F
#define AT45DB161D_PROGRAM_SECTOR_PROTECTION_REGISTER_3 0xFC

#define AT45DB161D_SECTOR_LOCKDOWN_0 0X3D
#define AT45DB161D_SECTOR_LOCKDOWN_1 0x2A
#define AT45DB161D_SECTOR_LOCKDOWN_2 0x7F
#define AT45DB161D_SECTOR_LOCKDOWN_3 0x30

#define AT45DB161D_PROGRAM_SECURITY_REGISTER_0 0x9B
#define AT45DB161D_PROGRAM_SECURITY_REGISTER_1 0x00
#define AT45DB161D_PROGRAM_SECURITY_REGISTER_2 0x00
#define AT45DB161D_PROGRAM_SECURITY_REGISTER_3 0x00
#endif /* AT45DB161D_EXPERT_MODE */

#define AT45DB161D_READ_SECTOR_PROTECTION_REGISTER 0x32

#define AT45DB161D_READ_SECTOR_LOCKDOWN_REGISTER 35H

#define AT45DB161D_READ_SECURITY_REGISTER 0x77

#define AT45DB161D_TRANSFER_PAGE_TO_BUFFER_1 0x53

#define AT45DB161D_TRANSFER_PAGE_TO_BUFFER_2 0x55

#define AT45DB161D_COMPARE_PAGE_TO_BUFFER_1 0x60

#define AT45DB161D_COMPARE_PAGE_TO_BUFFER_2 0x61

#define AT45DB161D_AUTO_PAGE_REWRITE_THROUGH_BUFFER_1 0x58

#define AT45DB161D_AUTO_PAGE_REWRITE_THROUGH_BUFFER_2 0x59

#define AT45DB161D_DEEP_POWER_DOWN 0xB9

#define AT45DB161D_RESUME_FROM_DEEP_POWER_DOWN 0xAB

#define AT45DB161D_STATUS_REGISTER_READ 0xD7

#define AT45DB161D_READ_MANUFACTURER_AND_DEVICE_ID 0x9F

#define AT45DB161D_BUFFER_1_READ_LEGACY 0X54

#define AT45DB161D_BUFFER_2_READ_LEGACY 0x56

#define AT45DB161D_PAGE_READ_LEGACY 0x52

#define AT45DB161D_CONTINUOUS_READ_LEGACY 0x68

#define AT45DB161D_STATUS_REGISTER_READ_LEGACY 0x57

#endif /* AT45DB161D_COMMANDS_H */

at45db161d.c原程序

#include "at45db161d.h"
#include<iom128v.h>
#include<macros.h>
#include<delay.h>

//#define DF_CS_inactive    PORTB|=1
//#define DF_CS_active      PORTB&=0xfe

uint8_t spi_transfer(uint8_t data)
{
        SPDR = data;
        while(!(SPSR & (1 << SPIF))) ;
        return SPDR;
}
void ATD45DB161D_Init(void)
{
        uint8_t clr;
        
        /* Initialize pinout */
        /*pinMode(DATAOUT, OUTPUT);
        pinMode(DATAIN, INPUT);
        pinMode(SPICLOCK, OUTPUT);
        pinMode(SLAVESELECT, OUTPUT);
        pinMode(DATAIN, INPUT);
                */
        //DDRB|=(1<<DDB2)|(1<<DDB1)|(1<<DDB0);
                //设置SS,SCK,MOSI为输出,MIOS为输入
                DDRB&=0XF7;
                DDRB|=0X07;
                  
        /* Disable device */
        DF_CS_inactive;
  
        /* Setup SPI 主机模式空闲时为高,采样结束沿采样 1/4主频率*/
        SPCR = (1 << SPE) | (1 << MSTR) | (1 << CPOL) | (1 << CPHA);

        /* Cleanup registers */
        clr = SPSR;
        clr = SPDR;
}

uint8_t  ReadStatusRegister(void)
{
        uint8_t status;

        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */
  
    /* Send status read command */
        spi_transfer(AT45DB161D_STATUS_REGISTER_READ);
        /* Get result with a dummy write */
        status = spi_transfer(0x00);

        return status;
}

void  ReadManufacturerAndDeviceID(struct ATD45DB161D_ID *id)
{
        
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */
  
    /* Send status read command */
        spi_transfer(AT45DB161D_READ_MANUFACTURER_AND_DEVICE_ID);

        /* Manufacturer ID */
        id->manufacturer = spi_transfer(0xff);
        /* Device ID (part 1) */
        id->device[0] = spi_transfer(0xff);
        /* Device ID (part 2) */
        id->device[1] = spi_transfer(0xff);
        /* Extended Device Information String Length */
        id->extendedInfoLength = spi_transfer(0xff);
        
}

void  ReadMainMemoryPage(uint16_t page, uint16_t offset)
{
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */

        /* Send opcode */
        spi_transfer(AT45DB161D_PAGE_READ);
        
        /* Address (page | offset)  */
        spi_transfer((uint8_t)(page >> 6));
        spi_transfer((uint8_t)((page << 2) | (offset >> 8)));
        spi_transfer((uint8_t)(offset & 0xff));
        
        /* 4 "don't care" bytes */
        spi_transfer(0x00);
        spi_transfer(0x00);
        spi_transfer(0x00);
        spi_transfer(0x00);
}

void  ContinuousArrayRead(uint16_t page, uint16_t offset, uint8_t low)
{
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */

        /* Send opcode */
        spi_transfer( low ? AT45DB161D_CONTINUOUS_READ_LOW_FREQ :
                            AT45DB161D_CONTINUOUS_READ_HIGH_FREQ );

        /* Address (page | offset)  */
        spi_transfer((uint8_t)(page >> 6));
        spi_transfer((uint8_t)((page << 2) | (offset >> 8)));
        spi_transfer((uint8_t)(offset & 0xff));
}


void  BufferRead(uint8_t bufferNum, uint16_t offset, uint8_t low)
{
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */

        /* Send opcode */
        if(bufferNum == 1)
        {
                spi_transfer(low ? AT45DB161D_BUFFER_1_READ_LOW_FREQ :
                                   AT45DB161D_BUFFER_1_READ);
        }
        else
        {
                spi_transfer(low ? AT45DB161D_BUFFER_2_READ_LOW_FREQ :
                                   AT45DB161D_BUFFER_2_READ);

        }
        
        /* 14 "Don't care" bits */
        spi_transfer(0x00);
        /* Rest of the "don't care" bits + bits 8,9 of the offset */
        spi_transfer((uint8_t)(offset >> 8));
        /* bits 7-0 of the offset */
        spi_transfer((uint8_t)(offset & 0xff));
}

void  BufferWrite(uint8_t bufferNum, uint16_t offset)
{
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */

        spi_transfer( (bufferNum == 1) ? AT45DB161D_BUFFER_1_WRITE :
                                         AT45DB161D_BUFFER_2_WRITE);
        
        /* 14 "Don't care" bits */
        spi_transfer(0x00);
        /* Rest of the "don't care" bits + bits 8,9 of the offset */
        spi_transfer((uint8_t)(offset >> 8));
        /* bits 7-0 of the offset */
        spi_transfer((uint8_t)(offset & 0xff));
}

void  BufferToPage(uint8_t bufferNum, uint16_t page, uint8_t erase)
{
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */

        /* Opcode */
        if(erase)
        {
                spi_transfer( (bufferNum == 1) ? AT45DB161D_BUFFER_1_TO_PAGE_WITH_ERASE :
                                             AT45DB161D_BUFFER_2_TO_PAGE_WITH_ERASE);
        }
        else
        {
                spi_transfer( (bufferNum == 1) ? AT45DB161D_BUFFER_1_TO_PAGE_WITHOUT_ERASE :
                                             AT45DB161D_BUFFER_2_TO_PAGE_WITHOUT_ERASE);
        }
        
        /*
         * 3 address bytes consist of :
         *     - 2 don’t care bits
         *     - 12 page address bits (PA11 - PA0) that specify the page in
         *       the main memory to be written
         *     - 10 don’t care bits
         */
        spi_transfer((uint8_t)(page >> 6));
        spi_transfer((uint8_t)(page << 2));
        spi_transfer(0x00);
        
        DF_CS_inactive;  /* Start transfer */
        DF_CS_active;    /* If erase was set, the page will first be erased */

        /* Wait for the end of the transfer */
        while(!(ReadStatusRegister() & READY_BUSY))
        {}
}

void  PageToBuffer(uint16_t page, uint8_t bufferNum)
{
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */

        /* Send opcode */
        spi_transfer((bufferNum == 1) ? AT45DB161D_TRANSFER_PAGE_TO_BUFFER_1 :
                                        AT45DB161D_TRANSFER_PAGE_TO_BUFFER_2);

        /*
         * 3 address bytes consist of :
         *     - 2 don’t care bits
         *     - 12 page address bits (PA11 - PA0) that specify the page in
         *       the main memory to be written
         *     - 10 don’t care bits
         */
        spi_transfer((uint8_t)(page >> 6));
        spi_transfer((uint8_t)(page << 2));
        spi_transfer(0x00);
               
        DF_CS_inactive;  /* Start page transfer */
        DF_CS_active;

        /* Wait for the end of the transfer */
        while(!(ReadStatusRegister() & READY_BUSY))
        {}
}

void  PageErase(uint16_t page)
{
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */

        /* Send opcode */
        spi_transfer(AT45DB161D_PAGE_ERASE);
        
        /*
         * 3 address bytes consist of :
         *     - 2 don’t care bits
         *     - 12 page address bits (PA11 - PA0) that specify the page in
         *       the main memory to be written
         *     - 10 don’t care bits
         */
        spi_transfer((uint8_t)(page >> 6));
        spi_transfer((uint8_t)(page << 2));
        spi_transfer(0x00);
               
        DF_CS_inactive;  /* Start block erase */
        DF_CS_active;

        /* Wait for the end of the block erase operation */
        while(!(ReadStatusRegister() & READY_BUSY))
        {}
}

void  BlockErase(uint16_t block)
{
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */

        /* Send opcode */
        spi_transfer(AT45DB161D_BLOCK_ERASE);
        
        /*
         * 3 address bytes consist of :
         *     - 2 don’t care bits
         *     - 9 block address bits (PA11 - PA3)
         *     - 13 don’t care bits
         */
        spi_transfer((uint8_t)(block >> 3));
        spi_transfer((uint8_t)(block << 5));
        spi_transfer(0x00);
               
        DF_CS_inactive;  /* Start block erase */
        DF_CS_active;

        /* Wait for the end of the block erase operation */
        while(!(ReadStatusRegister() & READY_BUSY))
        {}
}

void  SectoreErase(uint8_t sector)
{
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */

        /* Send opcode */
        spi_transfer(AT45DB161D_SECTOR_ERASE);
        
        /*
         * 3 address bytes consist of :
         */
        if((sector == 0x0a) || (sector == 0x0b))
        {
                /*
                 *  - 11 don’t care bits
                 *  -
                 *  - 12 don’t care bits
                 */
                spi_transfer(0x00);
                spi_transfer(((sector & 0x01) << 4));
                spi_transfer(0x00);
        }
        else
        {
                /*
                 *  - 2 don't care bits
                 *  - 4 sector number bits
                 *  - 18 don't care bits
                 */
                spi_transfer(sector << 1);
                spi_transfer(0x00);
                spi_transfer(0x00);
        }
                                
        DF_CS_inactive;  /* Start block erase */
        DF_CS_active;

        /* Wait for the end of the block erase operation */
        while(!(ReadStatusRegister() & READY_BUSY))
        {}
}

void  ChipErase(void)
{
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */

        /* Send chip erase sequence */
        spi_transfer(AT45DB161D_CHIP_ERASE_0);
        spi_transfer(AT45DB161D_CHIP_ERASE_1);
        spi_transfer(AT45DB161D_CHIP_ERASE_2);
        spi_transfer(AT45DB161D_CHIP_ERASE_3);
                                
        DF_CS_inactive;  /* Start chip erase */
        DF_CS_active;

        /* Wait for the end of the chip erase operation */
        while(!(ReadStatusRegister() & READY_BUSY))
        {}
}

void  BeginPageWriteThroughBuffer(uint16_t page, uint16_t offset, uint8_t bufferNum)
{
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */

        /* Send opcode */
        spi_transfer((bufferNum == 1) ? AT45DB161D_PAGE_THROUGH_BUFFER_1 :
                                        AT45DB161D_PAGE_THROUGH_BUFFER_2);

        /* Address */
        spi_transfer((uint8_t)(page >> 6));
        spi_transfer((uint8_t)((page << 2) | (offset >> 8)));
        spi_transfer((uint8_t)offset);
}

void  EndAndWait(void)
{
        DF_CS_inactive;  /* End current operation */
        DF_CS_active;    /* Some internal operation may occur
                          * (buffer to page transfer, page erase, etc... ) */

        /* Wait for the chip to be ready */
        while(!(ReadStatusRegister() & READY_BUSY))
        {}
}

int8_t  ComparePageToBuffer(uint16_t page, uint8_t bufferNum)
{
        uint8_t status;
        
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */

        /* Send opcode */
        spi_transfer((bufferNum == 1) ? AT45DB161D_COMPARE_PAGE_TO_BUFFER_1 :
                                        AT45DB161D_COMPARE_PAGE_TO_BUFFER_2);
        
        /* Page address */
        spi_transfer((uint8_t)(page >> 6));
        spi_transfer((uint8_t)(page << 2));
        spi_transfer(0x00);
        
        DF_CS_inactive;  /* Start comparaison */
        DF_CS_active;

        /* Wait for the end of the comparaison and get the result */
        while(!((status = ReadStatusRegister()) & READY_BUSY))
        {}
               
        return ((status & COMPARE) == COMPARE);
}

void  DeepPowerDown(void)
{
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */
        
        /* Send opcode */
        spi_transfer(AT45DB161D_DEEP_POWER_DOWN);
        
        /* Enter Deep Power-Down mode */
        DF_CS_inactive;
        
        /* Safety delay */
         delay_ms(100);
}

void  ResumeFromDeepPowerDown(void)
{
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */
        
        /* Send opcode */
        spi_transfer(AT45DB161D_RESUME_FROM_DEEP_POWER_DOWN);
        
        /* Resume device */
        DF_CS_inactive;
        
        /* The CS pin must stay high during t_RDPD microseconds before the device
         * can receive any commands.
         * On the at45db161D t_RDPD = 35 microseconds. But we will wait 100
         * (just to be sure). */
         delay_ms(100);
}

测试程序1

void  ATD45DB161D_test(void)
{
struct ATD45DB161D_ID *id1;
sendstring1("now test ATD45DB161D dataflash !\n");
sendstring1("1.ReadStatusRegister\n");
// sendchar1(char2hex(ReadStatusRegister()));
sendinthex1(ReadStatusRegister());
sendstring1("\n");
sendstring1("2. ReadManufacturerAndDeviceID\n");
ReadManufacturerAndDeviceID(id1);
/* Manufacturer ID */
sendstring1("id1->manufacturer=");
// sendchar1(char2hex(id1->manufacturer));
sendinthex1(id1->manufacturer);
sendstring1("\n");
/* Device ID (part 1) */
sendstring1("id1->device[0]=");
//sendchar1(char2hex(id1->device[0]));
sendinthex1(id1->device[0]);
sendstring1("\n");
/* Device ID (part 2) */
sendstring1("id1->device[1]=");
//sendchar1(char2hex(id1->device[1]));
sendinthex1(id1->device[1]);
sendstring1("\n");
/* Extended Device Information String Length */
sendstring1("id1->extendedInfoLength=");
//sendchar1(char2hex(id1->extendedInfoLength));
sendinthex1(id1->extendedInfoLength);
sendstring1("\n");

sendstring1("3.  ChipErase test\n");
sendstring1("now ChipErase begin\n");
ChipErase();
sendstring1("now ChipErase end\n");


}

这个是串口的输出
1

1

出0入0汤圆

 楼主| 发表于 2008-2-21 14:09:55 | 显示全部楼层
MEGA128与AT45DB161D的硬件连接
1
2
1

出0入0汤圆

 楼主| 发表于 2008-2-21 16:46:02 | 显示全部楼层
4.1.1下面开始at45db161d.c中所有的应用函数!!

出0入0汤圆

 楼主| 发表于 2008-2-22 08:44:19 | 显示全部楼层
//******************************************************************************
/*AT45DB161D的命令可以以组的形式分成4类,在任何时间都可以执行
The commands described previously can be grouped into four different categories
to better describe which commands can be executed at what times.
//组A命令包含
Group A commands consist of:
1. Main Memory Page Read
2. Continuous Array Read
3. Read Sector Protection Register
4. Read Sector Lockdown Register
5. Read Security Register

//组B命令包含
Group B commands consist of:
1. Page Erase
2. Block Erase
3. Sector Erase
4. Chip Erase
5. Main Memory Page to Buffer 1 (or 2) Transfer
6. Main Memory Page to Buffer 1 (or 2) Compare
7. Buffer 1 (or 2) to Main Memory Page Program with Built-in Erase
8. Buffer 1 (or 2) to Main Memory Page Program without Built-in Erase
9. Main Memory Page Program through Buffer 1 (or 2)
10. Auto Page Rewrite

//组C命令包含
Group C commands consist of:
1. Buffer 1 (or 2) Read
2. Buffer 1 (or 2) Write
3. Status Register Read
4. Manufacturer and Device ID Read

//组D命令包含
Group D commands consist of:
1. Erase Sector Protection Register
2. Program Sector Protection Register
3. Sector Lockdown
4. Program Security Register
//如果组A命令还没有执行完成,在B,C,D中的其他命令不应该开始.但是,当组B中的自己定时
部分的内部命令在执行中,在组C中的任何命令都可以执行.使用BUFFER1的组B命令此时应该用
使用BUFFER2的组c命令,反之亦然.最后,当执行使用内部定时部分的组D命令执行时,只有
状态寄存器读命令可以被执行!
If a Group A command is in progress (not fully completed), then another command in Group A,
B, C, or D should not be started. However, during the internally self-timed portion of Group B
commands, any command in Group C can be executed. The Group B commands using buffer 1
should use Group C commands using buffer 2 and vice versa. Finally, during the internally selftimed
portion of a Group D command, only the Status Register Read command should be
executed.
*/
//******************************************************************************

出0入0汤圆

 楼主| 发表于 2008-2-22 08:50:35 | 显示全部楼层
参考测试代码http://blockos.org/releases/at45db161d/examples/pageTest/pageTest.pde

#include "at45db161d.h"

#define NUM_PAGES 8

struct ATD45DB161D dataflash;
uint8_t     loop_cnt;
uint16_t    page;

void setup()
{   
  uint8_t        status;
  struct ATD45DB161D_ID id;
  
  /* Let's wait 1 second, allowing use to press the serial monitor button :p */
  delay(1000);
  
  /* Initialize dataflash */
  dataflash.Init();
   
  delay(10);
  
  /* Read status register */
  status = dataflash.ReadStatusRegister();
  
  /* Read manufacturer and device ID */
  dataflash.ReadManufacturerAndDeviceID(&id);

  /* Set baud rate for serial communication */
  Serial.begin(115200);

  /* Display status register */
  Serial.print("Status register :");
  Serial.print(status, BIN);
  Serial.print('\n');

  /* Display manufacturer and device ID */
  Serial.print("Manufacturer ID :\n");  // Should be 00011111
  Serial.print(id.manufacturer, HEX);
  Serial.print('\n');

  Serial.print("Device ID (part 1) :\n"); // Should be 00011111
  Serial.print(id.device[0], HEX);
  Serial.print('\n');

  Serial.print("Device ID (part 2)  :\n"); // Should be 00000000
  Serial.print(id.device[1], HEX);
  Serial.print('\n');

  Serial.print("Extended Device Information String Length  :\n"); // 00000000
  Serial.print(id.extendedInfoLength, HEX);
  Serial.print('\n');
  
  loop_cnt = 0;
  page     = 0;
}

void loop()
{
  unsigned int i,j;
  char message[] = "write test ";
  char overflow[] = "\nOVERFLOW!\n";
  char buffer[64];
  uint8_t data;

  /* We are going to write a simple text into buffer 1 */
  itoa(loop_cnt, buffer, 10);
  
  /* Set dataflash so that any call to spi_tranfer will write the byte
   * given as argument to the Buffer 1 */
  dataflash.BufferWrite(1, 0);
  /* Transfer the message */
  for(i=0; message != '\0'; ++i)
  {
    spi_transfer(message);
  }
  /* Transfer the loop counter (as string) */  
  for(i=0; buffer != '\0'; ++i)
  {
    spi_transfer(buffer);
  }
  
  spi_transfer('\n');
  
  ++loop_cnt;
  
  if(loop_cnt == 0)
  {
    /* loop_cnt overflow */
    /* To celebrate this we write the string "\nOVERFLOW!\n" to Buffer 1 */
    for(i=0; overflow != '\0'; ++i)
    {
      spi_transfer(overflow);
    }
  }

  /* Write '\0' to buffer 1. This will help us know that we must stop reading from it. */
  spi_transfer('\0');

  /* Transfer buffer 1 to 'page' page (with builtin erase) */
  dataflash.BufferToPage(1, page, 1);       
  
  ++page;
  /* When we wrote the number of pages we wanted (NUM_PAGES), we display their contents by
   * using 2 methods alternatively ;
   *     - PageToBuffer + BufferRead
   *     - PageRead
   */
  if(page >= NUM_PAGES)
  {
    for(i=0; i<NUM_PAGES; ++i)
    {
      if(i & 1)
      {
        Serial.println("Page to buffer");
        dataflash.PageToBuffer(i, 1);   
        dataflash.BufferRead(1, 0, 1);
      }
      else {   
        Serial.println("Page read");
        dataflash.ReadMainMemoryPage(i, 0);
      }
      
      j = 0;
      do
      {
        data = spi_transfer(0xff);
        if(data != '\0')
          Serial.print(data);
        ++j;
      }while((data != '\0') && (j < 64));
   
      /* Add a little delay otherwise the display will be too fast */   
      delay(500);
    }
   
    page = 0;
  }

出0入22汤圆

发表于 2008-2-22 13:37:18 | 显示全部楼层
谢谢,高人。

出0入0汤圆

 楼主| 发表于 2008-2-23 09:20:30 | 显示全部楼层
特别注意:
在DATASHEET中有对读取的是512/528字节的描述:

The device operation is controlled by instructions from the host processor. The list of instructions
and their associated opcodes are contained in Table 15-1 on page 28 through Table 15-7 on
page 31. A valid instruction starts with the falling edge of CS followed by the appropriate 8-bit
opcode and the desired buffer or main memory address location. While the CS pin is low, toggling
the SCK pin controls the loading of the opcode and the desired buffer or main memory
address location through the SI (serial input) pin. All instructions, addresses, and data are transferred
with the most significant bit (MSB) first.

528字节读写
Buffer addressing for standard DataFlash page size (528 bytes) is referenced in the datasheet
using the terminology BFA9 - BFA0 to denote the 10 address bits required to designate a byte
address within a buffer. Main memory addressing is referenced using the terminology PA11 -
PA0 and BA9 - BA0, where PA11 - PA0 denotes the 12 address bits required to designate a
page address and BA9 - BA0 denotes the 10 address bits required to designate a byte address
within the page.

512-2进制读写
For “Power of 2” binary page size (512 bytes) the Buffer addressing is referenced in the
datasheet using the conventional terminology BFA8 - BFA0 to denote the 9 address bits
required to designate a byte address within a buffer. Main memory addressing is referenced
using the terminology A20 - A0, where A20 - A9 denotes the 12 address bits required to designate
a page address and A8 - A0 denotes the 9 address bits required to designate a byte
address within a page.

是采用512还是528字节读写,对应的是在状态寄存器中设置的,具体如下

Bit 1 in the Status Register is used to provide information to the user whether or not the sector
protection has been enabled or disabled, either by software-controlled method or hardware-controlled
method. A logic 1 indicates that sector protection has been enabled and logic 0 indicates
that sector protection has been disabled.
Bit 0 in the Status Register indicates whether the page size of the main memory array is configured
for “power of 2” binary page size (512 bytes) or standard DataFlash page size (528 bytes).
If bit 0 is a 1, then the page size is set to 512 bytes. If bit 0 is a 0, then the page size is set to
528 bytes.
1

出0入0汤圆

 楼主| 发表于 2008-2-23 09:23:15 | 显示全部楼层
在上面的串口输出0xac说明现在是以528字节读写的
1

出0入0汤圆

发表于 2008-2-24 21:57:17 | 显示全部楼层
楼主出的都是精品

出0入0汤圆

发表于 2008-2-25 11:56:20 | 显示全部楼层
好东西,毕设用到,顶一个!

出0入0汤圆

 楼主| 发表于 2008-2-25 16:15:05 | 显示全部楼层
发现CHIPERASE无法擦除所有的内容
http://www.ouravr.com/bbs/bbs_content.jsp?bbs_sn=737106&bbs_page_no=1&sub_kind_id=2065&bbs_id=1000
还忘了提醒大家几点:

1、直到批号为0645的片子,chip erase指令还是不可靠的,这在datasheet 52页有描述。

2、芯片的页大小寄存器只能写一次(OTP),如果配置为每页512字节后就再也不能写回每页528字节了。

3、网上很多例程是旧版的161B的程序,跟161D操作指令有不少差别,ATMEL已经不建议使用这些旧指令了,移植的时候注意对照DATASHEET修改过来。

更改用BLOCK也不行!!!!!!!!
1
void  BlockErase(uint16_t block)
{
        DF_CS_inactive;    /* Make sure to toggle CS signal in order */
        DF_CS_active;      /* to reset Dataflash command decoder     */

        /* Send opcode */
        spi_transfer(AT45DB161D_BLOCK_ERASE);
        
        /*
         * 3 address bytes consist of :
         *     - 2 don’t care bits
         *     - 9 block address bits (PA11 - PA3)
         *     - 13 don’t care bits
         */
        spi_transfer((uint8_t)(block >> 3));
        spi_transfer((uint8_t)(block << 5));
        spi_transfer(0x00);
               
        DF_CS_inactive;  /* Start block erase */
        DF_CS_active;

        /* Wait for the end of the block erase operation */
        while(!(ReadStatusRegister() & READY_BUSY))
        {}
}

sendstring1("3.  BLOCKErase test\n");
sendstring1("now BLOCKErase begin\n");
for(i=0;i<512;i++)BlockErase(i);

sendstring1("now BLOCKErase end\n");

出0入0汤圆

发表于 2008-2-25 16:21:06 | 显示全部楼层
眼花缭乱,强人

出0入0汤圆

 楼主| 发表于 2008-2-26 11:19:24 | 显示全部楼层
原来的
uint8_t spi_transfer(uint8_t data)
{
        SPDR = data;
        while(!(SPSR & (1 << SPIF))) ;
        return SPDR;
}
现在的
uint8_t spi_transfer(uint8_t data)
{
        SPDR = data;
        while(!(SPSR & (1 << SPIF))) ;
                data=SPDR;
                SPSR&=0X7F;
        return data;//SPDR;
}
更新函数后可以擦除PAGE但是最后几个addr0=020a =0000 addr0=020b =0055 addr0=020c =00aa addr0=020e =0010 addr0=020f =0002
还没有能完全擦除!!

测试函数如下!!
sendstring1("3.  SECTOR Erase test\n");
sendstring1("now SECTOR Erase begin\n");

PageErase(0);
delay_ms(100);
sendstring1("now SECTOR Erase end\n");
//现在开始测试对AT45DB161D的FLASH读写
// 首先从PAGE0-PAGE4095开始写0X00,0X55,0XAA,0XFF,然后开始读出数据并比较
sendstring1("4.  now pageread test\n");
df_read_open(0);
// for(i=0;i<4096;i++)
{
sendstring1("PAGENUM=");
sendinthex1(0);
sendstring1("\n");
df_read(ATBUF,AT45DB161D_PAGE_SIZE);
for(j=0;j<AT45DB161D_PAGE_SIZE;j++)
   { if(ATBUF[j]!=0xff)
     {
         sendstring1("addr0=");
         sendinthex1(j);
         sendstring1(" =");
         sendinthex1(ATBUF[j]);
         sendstring1(" ");
         }
   }


}
df_read_close();
1

出0入4汤圆

发表于 2008-2-26 18:03:02 | 显示全部楼层
做了一块XBee连电脑的板,用XBee PRO把ID跟CH设置成一样就可以相互用过串口通信了,可用XBee的话,它的CH不能设置,不知道如何配置才能通信呢?
1点击此处打开ourdev_220135.JPG(文件大小:361K,只有300K以内的图片才能直接显示)
2
点击此处打开ourdev_220137.pdf(文件大小:93K)
点击此处打开ourdev_220138.pdf(文件大小:262K)

出0入0汤圆

 楼主| 发表于 2008-2-27 08:47:12 | 显示全部楼层
re 我的可以呀!!
1

出0入0汤圆

 楼主| 发表于 2008-2-27 08:48:04 | 显示全部楼层
如果连接不上,按下复位键就可以了!!

出0入0汤圆

 楼主| 发表于 2008-2-27 08:52:37 | 显示全部楼层
关于AT45DB161D的512字节测试

8:50:23>  now test ATD45DB161D dataflash !
8:50:23> 1.ReadStatusRegister
8:50:23> ac
8:50:23> 2. ReadManufacturerAndDeviceID
8:50:23> id1->manufacturer=1f
8:50:23> id1->device[0]=26
8:50:23> id1->device[1]=00
8:50:23> id1->extendedInfoLength=00
8:50:23> 3.  BlockErase test
8:50:23> now BlockErase begin
8:50:23> now BlockErase end
8:50:23> 4.  now pageread test
8:50:23> 5.  now  pagewrite test
8:50:23>  now  write 00
8:50:23>  now  write 00 ok
8:50:23>  now  reread 00
8:50:24>  now  reread 00 ok
8:50:24>  now  write 55
8:50:24>  now  write 55 ok
8:50:24>  now  reread 55
8:50:24>  now  reread 55 ok
8:50:24>  now  write aa
8:50:24>  now  write aa ok
8:50:24>  now  reread aa
8:50:24>  now  reread aa ok
8:50:24>  now  write ff
8:50:24>  now  write ff ok
8:50:24>  now  reread ff
8:50:24>  now  reread ff ok
8:50:24>   now  pagewrite test finish!

测试的函数如下:
//******************************************************************************
void  ATD45DB161D_test(void)
{
char temp,ATBUF[528];
char ATTESTBUF[4]={0x00,0x55,0xaa ,0xff};
unsigned int i,j,k;
  
struct ATD45DB161D_ID *id1;
sendstring1("now test ATD45DB161D dataflash !\n");
sendstring1("1.ReadStatusRegister\n");
// sendchar1(char2hex(ReadStatusRegister()));
sendinthex0(ReadStatusRegister());
sendstring1("\n");
sendstring1("2. ReadManufacturerAndDeviceID\n");
ReadManufacturerAndDeviceID(id1);
/* Manufacturer ID */
sendstring1("id1->manufacturer=");
// sendchar1(char2hex(id1->manufacturer));
sendinthex0(id1->manufacturer);
sendstring1("\n");
/* Device ID (part 1) */
sendstring1("id1->device[0]=");
//sendchar1(char2hex(id1->device[0]));
sendinthex0(id1->device[0]);
sendstring1("\n");
/* Device ID (part 2) */
sendstring1("id1->device[1]=");
//sendchar1(char2hex(id1->device[1]));
sendinthex0(id1->device[1]);
sendstring1("\n");
/* Extended Device Information String Length */
sendstring1("id1->extendedInfoLength=");
//sendchar1(char2hex(id1->extendedInfoLength));
sendinthex0(id1->extendedInfoLength);
sendstring1("\n");

sendstring1("3.  BlockErase test\n");
sendstring1("now BlockErase begin\n");
// for(i=0;i<4096;i++)PageErase(i);
//for(i=0;i<512;i++)BlockErase(i);
PageErase(0);
delay_ms(100);
PageErase(1);
  delay_ms(100);
sendstring1("now BlockErase end\n");

//现在开始测试对AT45DB161D的FLASH读写
// 首先从PAGE0-PAGE4095开始写0X00,0X55,0XAA,0XFF,然后开始读出数据并比较
sendstring1("4.  now pageread test\n");
df_read_open(0);
for(i=0;i<2;i++)
{
//sendstring1("\n PAGENUM=");
//sendinthex1(i);
//sendstring1("\n");
df_read(ATBUF,AT45DB161D_PAGE_SIZE);
for(j=0;j<512;j++)
   { if(ATBUF[j]!=0xff)
     {
         sendstring1("addr_");
         sendinthex1(j);
         sendstring1(" =");
         sendinthex1(ATBUF[j]);
         sendstring1(" ");
         }
   }


}
df_read_close();

sendstring1("5.  now  pagewrite test\n");
//分4次将0X00,0X55,0XAA,0XFF写入BUFFER,然后写入PAGE
//每次写入后验证数据

  for(i=0;i<4;i++)
   {//将测试的数据写入ATBUF
   if(i==0)sendstring1(" now  write 00 \n");
   if(i==1)sendstring1(" now  write 55 \n");
   if(i==2)sendstring1(" now  write aa \n");
   if(i==3)sendstring1(" now  write ff \n");
   
      for(j=0;j<AT45DB161D_PAGE_SIZE;j++)
          {
                     temp=ATTESTBUF;
                  ATBUF[j]=temp;
                     }
        // 写入4096次       
          df_write_open(0);
          for(k=0;k<2;k++)
                    {
                  //将数据写入BUFFER2
                  df_write(ATBUF,AT45DB161D_PAGE_SIZE);
//                  BufferWrite(2,pCurWriteByte,ATBUF,528);
//                  BufferToPage(2, pCurWritePage, 0);  
              }
         df_write_close();       
   
   if(i==0)sendstring1(" now  write 00 ok\n");
   if(i==1)sendstring1(" now  write 55 ok\n");
   if(i==2)sendstring1(" now  write aa ok\n");
   if(i==3)sendstring1(" now  write ff ok\n");
  
         df_read_open(0);  
         if(i==0)sendstring1(" now  reread 00 \n");
   if(i==1)sendstring1(" now  reread 55 \n");
   if(i==2)sendstring1(" now  reread aa \n");
   if(i==3)sendstring1(" now  reread ff \n");//
         for(k=0;k<2;k++)
         {df_read(ATBUF,AT45DB161D_PAGE_SIZE);
           for(j=0;j<512;j++)
           {        temp=ATBUF[j];
                    if(temp!=ATTESTBUF)
                           {sendstring1("addr1");
                    sendinthex1(j);
                    sendstring1(" =");
                        sendinthex1(temp);
                        //sendstring1("\n");
                        }
           }
         
   }
   if(i==0)sendstring1(" now  reread 00 ok\n");
   if(i==1)sendstring1(" now  reread 55 ok\n");
   if(i==2)sendstring1(" now  reread aa ok\n");
   if(i==3)sendstring1(" now  reread ff ok\n");
PageErase(0);
delay_ms(100);
PageErase(1);
  delay_ms(100);

}
   sendstring1("  now  pagewrite test finish!\n");

}

小结:
1.超过512字节的内容用擦除命令没有办法完整擦除,建议只用512字节内的,29楼有具体的现象!!
2.现在测试了PAGE0和PAGE1的内容,分别写入0X00,0X55,0XAA,0XFF,每次写入新的数据后需要再用PAGEERASE命令擦除!

出0入0汤圆

 楼主| 发表于 2008-2-27 10:05:21 | 显示全部楼层
发一个SPI dataflash的驱动程序包含文件系统
http://download.easytoweb.net/eTWlib_v1.5.0.ZIP
在device目录下面
1

说明文档
2
http://www.ifas.htwk-leipzig.de/easytoweb/download/eTW_Software_Dokumentation_V206.zip

还没有测试!
马上开始测试了!!

出0入0汤圆

 楼主| 发表于 2008-2-27 10:14:18 | 显示全部楼层
首先将项目需要的函数copy进测试的文件夹,然后修改对应的函数http://www.ouravr.com/bbs/bbs_upload19801/files_9/ourdev_220495.jpg
1

出0入0汤圆

 楼主| 发表于 2008-2-27 16:57:46 | 显示全部楼层
终于完成DATAFLASH部分的程序移植,马上开始写测试程序测试!

出0入4汤圆

发表于 2008-2-27 21:11:27 | 显示全部楼层
已经  搞定!
只要设置成不同的模式就可以了!

出0入0汤圆

 楼主| 发表于 2008-2-28 21:01:35 | 显示全部楼层
dataflash-AT45DB161D的测试程序已经全部编译通过!
1

特别注意的地方
struct ATD45DB161D_ID *id1;
需要在dataflash.c的头部定义

1

点击此处下载AT45DB161D的完整测试程序.rar(文件大小:25K)

出0入0汤圆

 楼主| 发表于 2008-2-29 08:34:59 | 显示全部楼层
下面开始测试基于DATAFLASH的文件系统,主要函数包含在dataflash.c中
Funktionen:
// **********************************************************************************
// Description : init the dataflash-file-system
// Input : spi_mode - see etw_mc.h for details
// Output : 0 - Error (DataFlash no available)
// : 1 - OK
// Indication : none
// **********************************************************************************
unsigned char dataflash_file_init(unsigned int spi_mode)
// **********************************************************************************
// Description : checks the file-system (reads the Info-Page and checks the file
// consistence
// Input : none
// Output : 0 - Read Error
// : 1 - OK
// Indication : internal function, use "dataflash_file_init()"
// **********************************************************************************
unsigned char dataflash_file_check(void)
// **********************************************************************************
// Description : formats the file-system (erase the whole FataFlash and rewrite the
// : info-sector
// Input : none
// Output : 0 - Erase or Write Error
// : 1 - OK
// Indication : none
// **********************************************************************************
unsigned char dataflash_file_format(void)
// **********************************************************************************
// Description : checks the file consistence, reads the full DataFlash and checks
// : chain of file pages
// Input : none
// Output : 0 - read error
// : 1 - no file error
// Indication : internal function, use in "dataflash_file_check()"
// **********************************************************************************
unsigned char dataflash_file_consistence(void)
// **********************************************************************************
// Description : search a file
// Input : file_name - pointer to file name
// : file_name_struct - pointer to "FILE_NAME_STRUCT"
// : file_entry - pointer to 16bit - return file_entry (1 .. (FILE_NAME_COUNT-1))
// : mode: SEARCH_FIRST - start with first entry; SEARCH_NEXT - last entry
// Output : 0 - Error - found no file
// : 1 - found file
// Indication : none
// **********************************************************************************
unsigned char dataflash_file_search(unsigned char *file_name, FILE_NAME_STRUCT *file_name_struct,
unsigned int *file_entry, SEARCH_MODE mode)
// **********************************************************************************
// Description : open a file handle
// Input : file_name: pointer to file name
// Output : 0 - found no file - can't open
// : 1..FILE_HANDLE_COUNT - find file and open a handle
// Indication : open only if
// : a.) handle free
// : b.) file still open
// **********************************************************************************
unsigned char dataflash_file_open(unsigned char *file_name, unsigned char *handle)
// **********************************************************************************
// Description : check the file-handle
// Input : handle: handle to check
// Output : 0 - error
// : 1 - OK and decrement handle
// Indication : internal function
// **********************************************************************************
unsigned char dataflash_file_check_handle(unsigned char handle)
// **********************************************************************************
// Description : close a file handle
// Input : handle: number to data-structure
// Output : 0 - error
// : 1 - OK
// Indication : none
// **********************************************************************************
unsigned char dataflash_file_close(unsigned char *handle)
// **********************************************************************************
// Description : close all file-handler
// Input : none
// Output : none
// Indication : tries all possible file-handler (0..254)
// **********************************************************************************
void dataflash_file_close_all(void)
// **********************************************************************************
// Description : read data from a open a file handle
// Input : handle - number to data-structure
// : data - pointer to buffer
// : data_size - size of data
// Output : 0 - error
// : 1..x - OK and size of read data
// Indication : none
// **********************************************************************************
unsigned int dataflash_file_read(unsigned char handle, unsigned char *data, unsigned int data_size)
// **********************************************************************************
// Description : checks the end of file
// Input : handle - number to data-structure
// Output : 0 - error
// : 1 - OK and end of file
// Indication : none
// **********************************************************************************
unsigned char dataflash_file_eof(unsigned char handle)
// **********************************************************************************
// Description : calculate the size of file
// Input : handle: number to data-structure
// Output : 0 - error
// : 1 - OK and end of file
// Indication : none
// **********************************************************************************
unsigned char dataflash_file_size(unsigned char handle, unsigned long *file_size)
// **********************************************************************************
// Description : seek the data-pointer to value
// Input : handle - number to data-structure
// : file_pos - number to data-structure
// Output : 0 - error
// : 1 - OK and end of file (EOF)
// Indication : none
// **********************************************************************************
unsigned char dataflash_file_seek(unsigned char handle, unsigned long file_pos)
// **********************************************************************************
// Description : refresh a page with filename entries (all 0x0000 entries to 0xffff)
// Input : page - page of filenames
// : page_data - data of "page"
// Output : 0 - Error
// : 1 - OK
// Indication : internal file function
// **********************************************************************************
unsigned char dataflash_file_refresh(unsigned int page, unsigned char *page_data)
// **********************************************************************************
// Description : refresh a page with allocation entries
// Input : page - page of filenames
// : page_data - data of "page"
// : search - data to search, see below
// Output : 0 - Error
// : 1 - OK
// Indication : internal file function
// : search==0x0000 all entries to 0xffff, and erase + program "page"
// : search==0x0001..0xffff all entries to 0x0000, and program only "page"
// **********************************************************************************
unsigned char dataflash_file_alloc_refresh(unsigned int page, unsigned char *page_data, unsigned int search)
// **********************************************************************************
// Description : search a startpage
// Input : freepage - pointer to new free page
// Output : 0 - Error
// : 1 - OK
// Indication : internal file function
// : freepage==0xffff - search start with first Allocation page
// : freepage!=0xffff - calculate Allocation page and than start
// : both versions search the whole Allocation table
// **********************************************************************************
unsigned char dataflash_file_freepage(unsigned int *freepage)
// **********************************************************************************
// Description : search a startpage
// Input : startpage - pagenumber of "startpage"
// : countpage - count of datapages
// : actual_page - pointer to actual page (absolut page number)
// Output : 0 - Error
// : 1 - OK
// Indication : internal file function
// **********************************************************************************
unsigned char dataflash_file_alloc_write(unsigned int startpage, unsigned int countpage, unsigned int actual_page)
// **********************************************************************************
// Description : checks a name of new file or directory
// Input : name: pointer to file name
// Output : 0 - Error; wrong file name
// : 1 - OK
// Indication : at least ONE sign inside of (32..166)
// **********************************************************************************
unsigned char dataflash_file_check_name(unsigned char *name)
// **********************************************************************************
// Description : set the actual date to file
// Input : p_date - pointer to date and time
// Output : none
// Indication : internal function
// **********************************************************************************
void dataflash_file_date(DATE_STRUCT *p_date)
// **********************************************************************************
// Description : create a new file entry
// Input : file_name: pointer to file name
// Output : 0 - Error - can't create
// : 1 - OK - create file
// Indication : none
// **********************************************************************************
unsigned char dataflash_file_new(unsigned char *file_name)
// **********************************************************************************
// Description : write data to a open file handle
// Input : handle - number to data-structure
// : data - pointer to buffer
// : data_size - size of data
// Output : 0 - error
// : 1..x - OK and size of write data
// Indication : Attention: set Page-pointer to EOF
// **********************************************************************************
unsigned int dataflash_file_write(unsigned char handle, unsigned char *data, unsigned int data_size)
// **********************************************************************************
// Description : delete all allocation-entries of page <delete_page>
// Input : delete_page - number of page that delete
// Output : 0 - Error
// : 1 - OK
// Indication : internal file function
// ********************************************************************************** //
unsigned char dataflash_file_alloc_delete(unsigned int delete_page)
// **********************************************************************************
// Description : delete a file with open a file handle
// Input : handle - number to data-structure
// Output : 0 - error
// : 1 - OK
// Indication : none
// **********************************************************************************
unsigned char dataflash_file_delete(unsigned char handle)
// **********************************************************************************
// Description : get the type of a file
// Input : handle: number to data-structure
// : file_typ: pointer to "FILE_TYP" variable
// Output : 0 - error
// : 1 - OK
// Indication : file must be open; checks the header of file
// **********************************************************************************
unsigned char dataflash_file_gettype(unsigned char handle, FILE_TYP *file_typ)
// **********************************************************************************
// Description : get the time of open file
// Input : handle - number to data-structure
// : file_time - pointer to "DATE_STRUCT" variable
// Output : 0 - error
// : 1 - OK
// Indication : file must be open
// **********************************************************************************
unsigned char dataflash_file_gettime(unsigned char handle, DATE_STRUCT *file_time)
// **********************************************************************************
// Description : refresh a page with Dir-Name Entries (all 0x00 entries to 0xff)
// Input : page - page of Dirnames
// : page_data - data of "page"
// Output : 0 - error
// : 1 - OK
// Indication : internal file function
// **********************************************************************************
unsigned char dataflash_dir_refresh(unsigned int page, unsigned char *page_data)
// **********************************************************************************
// Description : search the DIR-Entry
// Input : *dir_name: pointer to dir name
// : *dir_number: dir_number to search
// Output : 0 - Error - can't find
// : 1..FILE_DIR_COUNT - OK - find directory
// Indication : supports 2 options:
// : 1.) dir_name!=0: search the dir number and if(dir_struct!=0)
// : read the DIR-Entry
// : 2.) (dir_number!=0)and(dir_struct!=0): search the dir name
// : check first the (dir_name!=0) and than (dir_number!=0)
// **********************************************************************************
unsigned char dataflash_dir_search(unsigned char *dir_name, unsigned char *dir_number,
DIR_NAME_STRUCT *dir_struct)
// **********************************************************************************
// Description : create a new DIR entry
// Input : *dir_name: pointer to file name
// Output : 0 - Error - can't create
// : 1 - OK - create dir
// Indication : none
// **********************************************************************************
unsigned char dataflash_dir_new(unsigned char *dir_name)
// **********************************************************************************
// Description : change the actual DIR
// Input : *dir_name - pointer to dir name
// Output : 0 - Error - can't change
// : 1 - OK - change directory
// Indication : supports follow signs:
// : ".." : go back to root directory
// : dir_name : go to sub directory
// **********************************************************************************
unsigned char dataflash_dir_change(unsigned char *dir_name)
// **********************************************************************************
// Description : delete a DIR
// Input : *dir_name: pointer to dir name
// Output : 0: Error - can't delete
// : 1: OK - delete directory
// Indication : delete only empthy directories
// : set the root directory
// **********************************************************************************
unsigned char dataflash_dir_delete(unsigned char *dir_name)

出0入0汤圆

 楼主| 发表于 2008-2-29 08:35:30 | 显示全部楼层
Funktionen:
// **********************************************************************************
// Description : displays ONE entry of Filename
// Input : p_name: pointer to FILE_NAME_STRUCT
// file_entry - position in the file-list
// mode: 1==displays all; 0==display without directory
// Output : none
// Indication : none
// **********************************************************************************
void dataflash_file_display(FILE_NAME_STRUCT *p_name, unsigned int file_entry, unsigned char mode)
// **********************************************************************************
// Description : displays ALL entries of Filenames
// Input : none
// Output : none
// Indication : none
// **********************************************************************************
void dataflash_file_debug_file(void)
// **********************************************************************************
// Description : displays ALL entries of Filename from actual directory
// Input : none
// Output : none
// Indication : none
// **********************************************************************************
void dataflash_file_debug_file_dir(void)
// **********************************************************************************
// Description : displays the data of file-handle
// Input : handle - handle to open file
// Output : none
// Indication : none
// **********************************************************************************
void dataflash_file_debug_handle_d(unsigned char handle)
// **********************************************************************************
// Description : info of the file-handle
// Input : handle - handle to open file
// ==0xff - displays all file handler
// !=0xff - displays only the handle
// Output : none
// Indication : none
// **********************************************************************************
void dataflash_file_debug_handle(unsigned char handle)
// **********************************************************************************
// Description : displays ALL entries of Directories
// Input : none
// Output : none
// Indication : none
// **********************************************************************************
void dataflash_file_debug_dir(void)
// **********************************************************************************
// Description : info to the dataflash-file-system
// Input : none
// Output : none
// Indication : none
// **********************************************************************************
void dataflash_file_debug_info(void)
//********************************************************************************
// Description : display the convert integer from string
// Input : data_page: 0...FILE_DATA_PAGE_COUNT
// Output : none
// Indication : none
//*********************************************************************************
void dataflash_file_alloc_info(unsigned int data_page)
//********************************************************************************
// Description : ???
// Input : command - pointer to ????
// : file_name - string... ????
// Output : none
// Indication : none
//*********************************************************************************
unsigned char dataflash_file_debug_string(unsigned char *command, unsigned char *file_name)
// **********************************************************************************
// Description : displays a page of DataFlash
// Input : page - number of page
// Output : none
// Indication : format with infomations of page-number
// **********************************************************************************
void dataflash_file_debug_page_dis(unsigned int page)
// **********************************************************************************
// Description : debug-frontend for Dataflash-File-functions
// Input : *command: pointer to command
// Output : none
// Indication : none
// **********************************************************************************
void dataflash_file_debug_do_cmd(unsigned char *command)

出0入0汤圆

 楼主| 发表于 2008-2-29 16:27:26 | 显示全部楼层
dataflash_file.h
dataflash_file.c
dataflash_file_debug.h
dataflash_file_debug.c

点击此处下载dataflash_file文件系统.rar(文件大小:19K)
1

出0入0汤圆

 楼主| 发表于 2008-3-2 17:46:36 | 显示全部楼层
yaffs2 directory
http://www.openembedded.org/filebrowser/org.openembedded.dev/packages/yaffs2

出0入0汤圆

 楼主| 发表于 2008-3-2 17:48:22 | 显示全部楼层
yaffs2
http://svn.neurostechnology.com/listing.php?repname=neuros-bsp&path=%2Ftrunk%2Fkernels%2Flinux-2.6.15%2Ffs%2Fyaffs2%2F&rev=1345&sc=1

出0入0汤圆

 楼主| 发表于 2008-3-2 17:49:24 | 显示全部楼层
http://rgbbones.googlepages.com/yaffs

出0入0汤圆

 楼主| 发表于 2008-3-4 16:13:57 | 显示全部楼层
1
2
3点击此处打开ourdev_224157.jpg(文件大小:305K,只有300K以内的图片才能直接显示)

出0入0汤圆

 楼主| 发表于 2008-3-4 16:15:45 | 显示全部楼层
点击此处打开ourdev_224158.xls(文件大小:18K)
点击此处打开ourdev_224159.pdf(文件大小:10K)
点击此处打开ourdev_224160.htm(文件大小:26K)

出0入0汤圆

 楼主| 发表于 2008-3-7 10:29:02 | 显示全部楼层
dataflash 文件系统测试汇报
现在可以创建文件系统了,初步测试了文件目录建立和删除,文件建立!文件修改和分配表的应用将在后面的测试中!
//*****************************************************************************
// DATAFLASH 文件测试函数
//
//
//*****************************************************************************
void  ATD45DB161D_filetest(void)
{
static unsigned char handle=0;
//首次初始化文件系统,并格式化
sendstring1("1.dataflash_file_init NOW!\n");
if(dataflash_file_init(DATAFLASH_SPI_MODE))sendstring1("dataflash_file_init ok!\n");
sendstring1("2.dataflash file info display !\n");
dataflash_file_debug_info();
sendstring1("3.dataflash file dir display !\n");
dataflash_file_debug_dir();
//下面创建4个文件目录
//1.html
//2.jpeg
//3.class
//4.text
/*typedef enum{
        FILE_TYPE_NONE,
        FILE_TYPE_HTML,
        FILE_TYPE_JPEG,
        FILE_TYPE_CLASS,                // Java Application
        FILE_TYPE_TEXT
} FILE_TYP;
*/
//现在创建html,jpeg,class,text4个目录
sendstring1("3.dataflash file dir creat !\n");
sendstring1("3.1 dataflash file dir html creat !\n");
dataflash_dir_new("html");
sendstring1("3.2 dataflash file dir jpeg creat !\n");
dataflash_dir_new("jpeg");
sendstring1("3.3 dataflash file dir class creat !\n");
dataflash_dir_new("class");
sendstring1("3.4 dataflash file dir text creat !\n");
dataflash_dir_new("text");
sendstring1("3.5 dataflash file dir display !\n");
dataflash_file_debug_dir();
//现在测试文件目录删除并显示目录
sendstring1("4.dataflash file dir delete !\n");
sendstring1("4.1 dataflash file dir html  delete !\n");
dataflash_dir_delete("html");
sendstring1("4.2 dataflash file dir jpeg  delete !\n");
dataflash_dir_delete("jpeg");
sendstring1("4.3 dataflash file dir class delete !\n");
dataflash_dir_delete("class");
sendstring1("4.4 dataflash file dir text delete !\n");
dataflash_dir_delete("text");
sendstring1("4.5 dataflash file dir delete ok !\n");
dataflash_file_debug_dir();


sendstring1("5.dataflash file creat in dir !\n");
dataflash_dir_new("html");
dataflash_dir_new("jpeg");
dataflash_dir_new("class");
dataflash_dir_new("text");
dataflash_file_debug_dir();
//*****************************************************
//创建1.html在html目录下
sendstring1("5.1 1.html  creat in  dir html !\n");
dataflash_dir_change("html");
dataflash_file_new("1.html");
//切换目录到jpeg
dataflash_dir_change("jpeg");
//创建2.jpeg在jpeg目录下
sendstring1("5.2 2.jpeg  creat in  dir jpeg !\n");
dataflash_file_new("2.jpeg");
//切换目录到class
dataflash_dir_change("class");
//创建2.class在class目录下
sendstring1("5.3 3.class creat in  dir class !\n");
dataflash_file_new("3.class");
//切换目录到text
dataflash_dir_change("text");
//创建2.text在text目录下
sendstring1("5.4 4.text  creat in  dir text !\n");
dataflash_file_new("4.text");
dataflash_file_debug_file();
}
1
2
3
4
5

出0入0汤圆

 楼主| 发表于 2008-3-7 10:30:46 | 显示全部楼层
完整的串口输出

10:25:58> now uart0!
10:25:58> now test ATD45DB161D dataflash !
10:25:58> 1.ReadStatusRegister
10:25:58> StatusRegister=ac
//这里读出设备号
10:25:58> 2. ReadManufacturerAndDeviceID
10:25:58> id1->manufacturer=1f
10:25:58> id1->device[0]=26
10:25:58> id1->device[1]=00
10:25:58> id1->extendedInfoLength=00
//块擦除程序
10:25:58> 3.  BlockErase test
10:25:58> now BlockErase begin
10:26:20> now BlockErase end
10:26:20> 1.dataflash_file_init NOW!
10:26:20> dataflash_file_init ok!
//文件系统信息显示
10:26:21> 2.dataflash file info display !
10:26:21> DataFlash-File:
10:26:21> FILE_INFO      : address:  0 pages: 1 (528byte)
10:26:21>
10:26:21> FILE_FF        : address:  1 pages: 1 (528byte)
10:26:21>
10:26:21> FILE_DIR       : address:  2-   3 pages: 1 (528byte; 26 Directories; 20byte)
10:26:21>
10:26:21> FILE_ALLOCATION: address:  3-  35 pages: 32 (16896byte; Entry:4byte)
10:26:21>
10:26:21> FILE_NAME      : address: 35-  55 pages: 20 (23603520byte; 29 Files; 77byte)
10:26:21>
10:26:21> FILE_DATA      : address: 55-4095 pages: 4041 (34361196byte; Pagesize:29byte)
10:26:21>
10:26:21> FILE Label: 0x0
10:26:21>
10:26:21> FILE Version: 0x0600
10:26:21>
10:26:21> FILE Storage: 0x0606
10:26:21>
10:26:21> FILE Date/Time: /?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
10:26:21>
10:26:21> FILE Dir: 1542  File: 1542
10:26:21>
10:26:21> FILE Info: ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
10:26:21>
//这里显示文件所有目录
10:26:21> dataflash file dir display !
10:26:21> Current DIR: root"
10:26:22> 3.dataflash file dir creat !
//现在开始创建dir html
10:26:22> 3.1 dataflash file dir html creat !
//现在开始创建dir jpeg
10:26:22> 3.2 dataflash file dir jpeg creat !
//现在开始创建dir class
10:26:22> 3.3 dataflash file dir class creat !
//现在开始创建dir text
10:26:22> 3.4 dataflash file dir text creat !
//开始显示所有目录,一共建立了4个目录
10:26:22> 3.5 dataflash file dir display !
10:26:22> Current DIR: root"
10:26:22> DIR( 0):"        html", 01.01.2003/00:00:00, 0xfe
10:26:22>
10:26:22> DIR( 1):"        jpeg", 01.01.2003/00:00:00, 0xfe
10:26:22>
10:26:22> DIR( 2):"       class", 01.01.2003/00:00:00, 0xfe
10:26:22>
10:26:22> DIR( 3):"        text", 01.01.2003/00:00:00, 0xfe
10:26:22>
//现在开始删除文件目录
10:26:22> dataflash file dir delete !
10:26:22> 4.1 dataflash file dir html  delete !
10:26:22> 4.2 dataflash file dir jpeg  delete !
10:26:22> 4.3 dataflash file dir class delete !
10:26:22> 4.4 dataflash file dir text delete !
10:26:22> 4.5 dataflash file dir delete ok !
//删除结束,只有ROOT目录
10:26:22> Current DIR: root"
//重新建立上面的4个目录,并显示
10:26:22> 5.dataflash file creat in dir !
10:26:22> Current DIR: root"
10:26:22> DIR( 4):"        html", 01.01.2003/00:00:00, 0xfe
10:26:23>
10:26:23> DIR( 5):"        jpeg", 01.01.2003/00:00:00, 0xfe
10:26:23>
10:26:23> DIR( 6):"       class", 01.01.2003/00:00:00, 0xfe
10:26:23>
10:26:23> DIR( 7):"        text", 01.01.2003/00:00:00, 0xfe
10:26:23>
//在对应的目录下面创建4个文件,
10:26:23> 1 1.html  creat in  dir html !
10:26:23> 5.2 2.jpeg  creat in  dir jpeg !
10:26:23> 5.3 3.class creat in  dir class !
10:26:23> 5.4 4.text  creat in  dir text !
//显示所有创建的文件
10:26:23> FILE(  0):"      1.html",     0Byte,01.01.2003/00:00:00,  55,  55,"       html"
10:26:23>
10:26:23> FILE(  1):"      2.jpeg",     0Byte,01.01.2003/00:00:00,  56,  56,"       jpeg"
10:26:23>
10:26:23> FILE(  2):"     3.class",     0Byte,01.01.2003/00:00:00,  57,  57,"      class"
10:26:23>
10:26:23> FILE(  3):"      4.text",     0Byte,01.01.2003/00:00:00,  58,  58,"       text"
10:26:23>
10:26:23> dataflash_file_search()
10:26:23> FILE(  3):"      4.text",     0Byte,01.01.2003/00:00:00,  58,  58,"       text"
10:26:23>

出0入0汤圆

 楼主| 发表于 2008-3-7 10:38:49 | 显示全部楼层
下面开始测试文件的读写操作和分配表的应用!!

出0入0汤圆

 楼主| 发表于 2008-3-7 16:06:21 | 显示全部楼层
//*****************************************************************************
// DATAFLASH 文件测试函数
//
//
//*****************************************************************************
void  ATD45DB161D_filetest(void)
{
static unsigned char handle=0;
unsigned int i,j,k;
/*typedef struct{
        unsigned char                year;                        // 0..255 years
        unsigned char                month;//:4;                // 1..12 months
        unsigned char                day;//:5;                        // 1..31 days
        unsigned char                hour;//:5;                        // 0..23 hours
        unsigned char                minute;//:6;                // 0..59 minutes
        unsigned char                second;//:6;                // 0..59 seconds
} DATE_STRUCT; */
DATE_STRUCT pdate={8,3,7,16,00,00};
//首次初始化文件系统,并格式化
sendstring1("1.dataflash_file_init NOW!\n");
if(dataflash_file_init(DATAFLASH_SPI_MODE))sendstring1("dataflash_file_init ok!\n");
sendstring1("2.dataflash file info display !\n");
dataflash_file_debug_info();
sendstring1("3.dataflash file dir display !\n");
dataflash_file_debug_dir();
//下面创建4个文件目录
//1.html
//2.jpeg
//3.class
//4.text
/*typedef enum{
        FILE_TYPE_NONE,
        FILE_TYPE_HTML,
        FILE_TYPE_JPEG,
        FILE_TYPE_CLASS,                // Java Application
        FILE_TYPE_TEXT
} FILE_TYP;
*/
//现在创建html,jpeg,class,text4个目录
sendstring1("3.dataflash file dir creat !\n");
sendstring1("3.1 dataflash file dir html creat !\n");
dataflash_dir_new("html");
sendstring1("3.2 dataflash file dir jpeg creat !\n");
dataflash_dir_new("jpeg");
sendstring1("3.3 dataflash file dir class creat !\n");
dataflash_dir_new("class");
sendstring1("3.4 dataflash file dir text creat !\n");
dataflash_dir_new("text");
sendstring1("3.5 dataflash file dir display !\n");
dataflash_file_debug_dir();
//现在测试文件目录删除并显示目录
sendstring1("4.dataflash file dir delete !\n");
sendstring1("4.1 dataflash file dir html  delete !\n");
dataflash_dir_delete("html");
sendstring1("4.2 dataflash file dir jpeg  delete !\n");
dataflash_dir_delete("jpeg");
sendstring1("4.3 dataflash file dir class delete !\n");
dataflash_dir_delete("class");
sendstring1("4.4 dataflash file dir text delete !\n");
dataflash_dir_delete("text");
sendstring1("4.5 dataflash file dir delete ok !\n");
dataflash_file_debug_dir();


sendstring1("5.dataflash file creat in dir !\n");
dataflash_dir_new("html");
dataflash_dir_new("jpeg");
dataflash_dir_new("class");
dataflash_dir_new("text");
dataflash_file_debug_dir();
sendstring1("\n");
/*
//*****************************************************
//创建1.html在html目录下
sendstring1("5.1 1.html  creat in  dir html !\n");
dataflash_dir_change("html");
dataflash_file_new("1.html");
//切换目录到jpeg
dataflash_dir_change("jpeg");
//创建2.jpeg在jpeg目录下
sendstring1("5.2 2.jpeg  creat in  dir jpeg !\n");
dataflash_file_new("2.jpeg");
//切换目录到class
dataflash_dir_change("class");
//创建2.class在class目录下
sendstring1("5.3 3.class creat in  dir class !\n");
dataflash_file_new("3.class");
//切换目录到text
dataflash_dir_change("text");
//创建2.text在text目录下
sendstring1("5.4 4.text  creat in  dir text !\n");
dataflash_file_new("4.text");
dataflash_file_debug_file();
//****************************************************
*/
//创建1.html在html目录下
sendstring1("6.1 1.html  creat in  dir html !\n");
dataflash_dir_change("html");
dataflash_file_new("1.html");

if(!dataflash_file_open("1.html", &handle))sendstring1("1.html file open err!\n");
dataflash_file_date(&pdate);
for(i=0;i<1024;i++)file_data_buffer=0x55;
if(dataflash_file_write(handle, file_data_buffer, 1024)==0)sendstring1("1.html file close err!\n");
dataflash_file_close(&handle);

//切换目录到jpeg
dataflash_dir_change("jpeg");
//创建2.jpeg在jpeg目录下
sendstring1("5.2 2.jpeg  creat in  dir jpeg !\n");
dataflash_file_new("2.jpeg");
if(!dataflash_file_open("2.jpeg", &handle))sendstring1("2.jpeg file open err!\n");
dataflash_file_date(&pdate);
for(i=0;i<1024;i++)file_data_buffer=0xaa;
if(dataflash_file_write(handle, file_data_buffer, 1024)==0)sendstring1("2.jpeg file close err!\n");
dataflash_file_close(&handle);
//切换目录到class
dataflash_dir_change("class");
//创建2.class在class目录下
sendstring1("5.3 3.class creat in  dir class !\n");
dataflash_file_new("3.class");
if(!dataflash_file_open("3.class", &handle))sendstring1("3.class file open err!\n");
dataflash_file_date(&pdate);
for(i=0;i<1024;i++)file_data_buffer=0x00;
if(dataflash_file_write(handle, file_data_buffer, 1024)==0)sendstring1("3.class file close err!\n");
dataflash_file_close(&handle);
//切换目录到text
dataflash_dir_change("text");
//创建2.text在text目录下
sendstring1("5.4 4.text  creat in  dir text !\n");
dataflash_file_new("4.text");
if(!dataflash_file_open("4.text", &handle))sendstring1("4.text file open err!\n");
dataflash_file_date(&pdate);
for(i=0;i<1024;i++)file_data_buffer=0x00;
if(dataflash_file_write(handle, file_data_buffer, 1024)==0)sendstring1("4.text file close err!\n");
dataflash_file_close(&handle);

dataflash_file_debug_file();

出0入0汤圆

 楼主| 发表于 2008-3-7 16:09:59 | 显示全部楼层
串口输出结果

16:15:02> now uart0!
16:15:02> now test ATD45DB161D dataflash !
16:15:02> 1.ReadStatusRegister
16:15:02> StatusRegister=ac
16:15:02> 2. ReadManufacturerAndDeviceID
16:15:02> id1->manufacturer=1f
16:15:02> id1->device[0]=26
16:15:02> id1->device[1]=00
16:15:02> id1->extendedInfoLength=00
16:15:02> 3.  BlockErase test
16:15:02> now BlockErase begin
16:15:24> now BlockErase end
16:15:24> 1.dataflash_file_init NOW!
16:15:25> dataflash_file_init ok!
16:15:25> 2.dataflash file info display !
16:15:25> DataFlash-File:
16:15:25> FILE_INFO      : address:  0 pages: 1 (528byte)
16:15:25>
16:15:25> FILE_FF        : address:  1 pages: 1 (528byte)
16:15:25>
16:15:25> FILE_DIR       : address:  2-   3 pages: 1 (528byte; 26 Directories; 20byte)
16:15:25>
16:15:25> FILE_ALLOCATION: address:  3-  35 pages: 32 (16896byte; Entry:4byte)
16:15:25>
16:15:25> FILE_NAME      : address: 35-  55 pages: 20 (23603520byte; 29 Files; 81byte)
16:15:25>
16:15:25> FILE_DATA      : address: 55-4095 pages: 4041 (34361196byte; Pagesize:29byte)
16:15:25>
16:15:25> FILE Label: 0x0
16:15:25>
16:15:25> FILE Version: 0x0600
16:15:25>
16:15:25> FILE Storage: 0x0606
16:15:25>
FILE Date/Time: /16:15:25> ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
16:15:25>
16:15:25> FILE Dir: 1542  File: 1542
16:15:25>
16:15:26> FILE Info: ?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
16:15:26>
16:15:26> dataflash file dir display !
16:15:26> Current DIR: root"
16:15:26> 3.dataflash file dir creat !
16:15:26> 3.1 dataflash file dir html creat !
16:15:26> 3.2 dataflash file dir jpeg creat !
16:15:26> 3.3 dataflash file dir class creat !
16:15:26> 3.4 dataflash file dir text creat !
16:15:26> 3.5 dataflash file dir display !
16:15:26> Current DIR: root"
16:15:26> DIR( 0):"        html", 01.01.2003/00:00:00, 0xfe
16:15:26>
16:15:26> DIR( 1):"        jpeg", 01.01.2003/00:00:00, 0xfe
16:15:26>
16:15:26> DIR( 2):"       class", 01.01.2003/00:00:00, 0xfe
16:15:26>
16:15:26> DIR( 3):"        text", 01.01.2003/00:00:00, 0xfe
16:15:26>
16:15:26> dataflash file dir delete !
16:15:26> 4.1 dataflash file dir html  delete !
16:15:26> 4.2 dataflash file dir jpeg  delete !
16:15:26> 4.3 dataflash file dir class delete !
16:15:26> 4.4 dataflash file dir text delete !
16:15:26> 4.5 dataflash file dir delete ok !
16:15:26> Current DIR: root"
16:15:26> 5.dataflash file creat in dir !
16:15:26> Current DIR: root"
16:15:27> DIR( 4):"        html", 01.01.2003/00:00:00, 0xfe
16:15:27>
16:15:27> DIR( 5):"        jpeg", 01.01.2003/00:00:00, 0xfe
16:15:27>
16:15:27> DIR( 6):"       class", 01.01.2003/00:00:00, 0xfe
16:15:27>
16:15:27> DIR( 7):"        text", 01.01.2003/00:00:00, 0xfe
16:15:27>
16:15:27> .1 1.html  creat in  dir html !
16:15:27> Page: 55 (size: 528byte)
16:15:27>
  1) 37 00 38 00 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55  25) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55  49) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55  73) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55  97) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 121) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 145) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 169) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 193) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 217) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 241) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 265) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 289) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 313) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 337) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 361) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 385) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 409) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 433) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 457) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 16:15:27> 55 55 55 55 55 55 55 481) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 505) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55
16:15:27> Page: 56 (size: 528byte)
16:15:27>
16:15:27>   1) 37 00 ff ff 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55  25) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55  49) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55  73) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55  97) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 121) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 145) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 169) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 193) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 217) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 241) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 265) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 289) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 313) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 337) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 361) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 385) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 409) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 433) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 457) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 481) 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 505) ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
16:15:27> 5.2 2.jpeg  creat in  dir jpeg !
16:15:27> Page: 57 (size: 528byte)
16:15:27>
  1) 39 00 3a 00 aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa  25) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 16:15:27> aa aa aa aa aa aa aa aa aa  49) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa  73) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa  97) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 121) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 145) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 169) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 193) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 217) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 241) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 265) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 289) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 313) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 337) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 361) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 385) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 409) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 433) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 457) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 481) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 505) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa
16:15:27> Page: 58 (size: 528byte)
16:15:27>
  1) 39 00 ff ff aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa  25) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa  49) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa  73) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa  97) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 121) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 145) aa aa aa aa aa aa aa aa aa aa aa aa aa aa aa 16:15:27> aa aa aa aa aa aa aa aa aa 169) Page: 59 (size: 528byte)
16:15:27>
16:15:27>   1) 3b 00 3c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  25) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  49) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  73) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  97) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 121) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 145) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 169) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 193) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 217) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 241) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 265) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 289) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 313) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 337) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 361) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 385) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 409) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 433) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 457) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 481) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 505) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
16:15:27> Page: 60 (size: 528byte)
16:15:27>
  1) 3b 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  25) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  49) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  73) 00 00 00 00 00 00 00 16:15:27> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  97) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 121) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 145) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 169) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 193) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 217) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 241) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 265) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 289) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 313) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 337) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 361) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 385) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 409) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 433) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 457) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 481) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 505) ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
16:15:28> 5.4 4.text  creat in  dir text !
16:15:28> Page: 61 (size: 528byte)
16:15:28>
  1) 3d 00 3e 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  25) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  49) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  73) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  97) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 121) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 145) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 169) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 193) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 217) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 241) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 265) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 289) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 313) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 337) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 361) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 385) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 409) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 433) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 457) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 16:15:28> 00 00 00 00 00 00 00 481) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 505) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
16:15:28> Page: 62 (size: 528byte)
16:15:28>
  1) 3d 00 ff ff 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  25) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  49) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  73) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  97) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 121) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 145) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 169) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 193) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 217) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 241) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 265) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 289) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 313) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 337) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 361) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 385) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 409) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 433) 00 00 16:15:28> 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 457) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 481) 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 505) ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
//这里可以看的很清楚,创建了4个文件都是1kBYTE
//第1个文件在PAGE 55-56 因为每个文件1KBYTE,所以需要2PAGE
16:15:28> FILE(  0):"      1.html",  1024Byte,01.01.2003/00:00:00,  55,  56,"       html"
16:15:28>
//第2个文件在PAGE 57-58 因为每个文件1KBYTE,所以需要2PAGE

16:15:28> FILE(  1):"      2.jpeg",  1024Byte,01.01.2003/00:00:00,  57,  58,"       jpeg"
16:15:28>
//第3个文件在PAGE 59-60 因为每个文件1KBYTE,所以需要2PAGE

16:15:28> FILE(  2):"     3.class",  1024Byte,01.01.2003/00:00:00,  59,  60,"      class"
16:15:28>
//第4个文件在PAGE 60-61 因为每个文件1KBYTE,所以需要2PAGE

16:15:28> FILE(  3):"      4.text",  1024Byte,01.01.2003/00:00:00,  61,  62,"       text"
16:15:28>
16:15:28> dataflash_file_search()
16:15:28> FILE(  3):"      4.text",  1024Byte,01.01.2003/00:00:00,  61,  62,"       text"
16:15:28>

出0入0汤圆

 楼主| 发表于 2008-3-10 08:33:27 | 显示全部楼层
下面开始测试SD2201和LCD1602

出0入0汤圆

发表于 2008-3-10 08:53:37 | 显示全部楼层
精品啊,加油!

出0入0汤圆

 楼主| 发表于 2008-3-10 10:31:10 | 显示全部楼层
SD2000时钟读取测试完成!!

1

出0入0汤圆

 楼主| 发表于 2008-3-10 10:32:22 | 显示全部楼层
下面准备采用中断方式读取时钟的时间并通过串口输出!

出0入0汤圆

 楼主| 发表于 2008-3-10 17:03:43 | 显示全部楼层
碰到一个用中断使熔丝被锁的问题,详细可以参考!

稀里糊涂学一招之---ATMEGA128熔丝恢复! http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=937652&bbs_page_no=1&bbs_id=1000

出0入0汤圆

 楼主| 发表于 2008-3-17 12:33:08 | 显示全部楼层
最近开始SD2201ap的测试了!!

已经可以中断并以一秒的频率中断了!!
1
//************************************
// SD2000 real time interrupt
//************************************
#pragma interrupt_handler int5_isr:7
void int5_isr(void)
{
//external interupt on INT5
clkUpdate=1;
sendstring1("  -int5!  ");

//EIFR&=0XDF;
//return;
}
//***********************************************************
void SD2000test(void)
{
u08 a1[11],d,s;
//初始化参数

a1[0]=8;//year           08
a1[1]=3;//month                02
a1[2]=0X17;//date                01
a1[3]=1;//week                 02                                                                                  
a1[4]=0X52;//hour  12
a1[5]=0X20;//mm-                14
a1[6]=00;//ss       00
for(s=0;s<7;s++)
{
sendstring1("a1[");
sendinthex1(s);
sendstring1("]=");
sendinthex1(a1);
sendstring1(" ");
}
sendstring1("\n");
for(s=0;s<7;s++)
{
sendstring1("a1[");
sendinthex1(s);
sendstring1("]=");
sendinthex1(invert(a1));
sendstring1(" ");
}
sendstring1("\n");
//开始复位
d=1;
s= SD2K_TWI(CMD_STUSR_W, &d, 1);//0x62
//开始写实时数据
SD2K_TWI(CMD_TIMEALL_W, &a1[0], 7);
//状态寄存器1
d=2;
SD2K_TWI(CMD_RESET-1, &d, 1);
//状态寄存器2
d=1;
SD2K_TWI(CMD_STUSR_W,&d,1);
//int1寄存器
d=3;
SD2K_TWI(CMD_INT1_W, &d, 1);
//int2寄存器
d=0;
SD2K_TWI(CMD_INT2_W, &d, 1);
//时钟调整
d=0;
SD2K_TWI(CMD_TIMEADJ_W, &d, 1);
//通用寄存器
d=0;
SD2K_TWI(CMD_GER_W, &d, 1);

{
   
       
SD2K_TWI(CMD_TIMEALL_R, &a1[0], 7);
for(s=0;s<7;s++)
{if(s==4){a1&=0x3f;BCD2HEX(&a1);}
else BCD2HEX(&a1);
}
sendstring1("yy:mm:dd:=");
sendinthex2(a1[0]);
sendstring1(":");
sendinthex2(a1[1]);
sendstring1(":");
sendinthex2(a1[2]);
sendstring1("  ");
sendstring1("date=");
sendinthex2(a1[3]);
sendstring1(":");
sendstring1(" hh:mm:ss:=");
sendinthex2(a1[4]);
sendstring1(":");
sendinthex2(a1[5]);
sendstring1(":");
sendinthex2(a1[6]);
sendstring1("\n");

//printf("yy:mm:dd: -d-  hh:mm:ss=%d:%d:%d  -%d- %d:%d:%d    \n",a1[0],a1[1],a1[2],a1[3],a1[4],a1[5],a1[6]);

delay_ms(800);
}





}

void main(void)
{
u08 a[11],s;
init_devices();
sendstring1("now uart1 !\n");
sendstring1("delay 1s!\n");
delay_ms(1000);
sendstring1("now uart0!\n");
// test_net();
//printf(" i come!\n  ");
//putchar('d');
sendstring1("\n ");

SD2000test();
// ATD45DB161D_test();
/*
RAMALLTEST();

sendstring1("\n ");
test_net();
*/
while(1)
  {                if(clkUpdate)
                {        //TIFR&=0xdf;
                        clkUpdate=0;
                    SD2K_TWI(CMD_TIMEALL_R, &a[0], 7);
                        for(s=0;s<7;s++)
                        {if(s==4){a&=0x3f;BCD2HEX(&a);}
                         else BCD2HEX(&a);}
                        //printf("yy:mm:dd: -d-  hh:mm:ss=%d:%d:%d  -%d- %d:%d:%d    \n",a[0],a[1],a[2],a[3],a[4],a[5],a[6]);
                        sendstring1("yy:mm:dd:=");
                        sendinthex2(a[0]);
                        sendstring1(":");
                        sendinthex2(a[1]);
                        sendstring1(":");
                        sendinthex2(a[2]);
                        sendstring1("  ");
                        sendstring1("date=");
                        sendinthex2(a[3]);
                        sendstring1(":");
                        sendstring1("hh:mm:ss:=");
                        sendinthex2(a[4]);
                        sendstring1(":");
                        sendinthex2(a[5]);
                        sendstring1("  ");
                        sendinthex2(a[6]);
                        sendstring1("\n");
                }
  }
}

出0入0汤圆

 楼主| 发表于 2008-3-17 16:00:29 | 显示全部楼层
更新了函数
//************************************
// SD2000 real time interrupt
//************************************
#pragma interrupt_handler int5_isr:7
void int5_isr(void)
{
//external interupt on INT5
clkUpdate=1;
sendstring1("  -int5!  ");

//EIFR&=0XDF;
//return;
}
//***********************************************************
void SD2000test(void)
{
u08 a1[7],d,s;
//初始化参数

a1[0]=8;//year           08
a1[1]=3;//month                02
a1[2]=17;//date                01
a1[3]=1;//week                 02                                                                                  
a1[4]=16;//hour  12
a1[5]=35;//mm-                14
a1[6]=42;//ss       00
/*for(s=0;s<7;s++)
{
sendstring1("a1[");
sendinthex1(s);
sendstring1("]=");
sendinthex1(a1);
sendstring1(" ");
}
sendstring1("\n");
for(s=0;s<7;s++)
{
sendstring1("a1[");
sendinthex1(s);
sendstring1("]=");
sendinthex1(invert(a1));
sendstring1(" ");
}
sendstring1("\n");*/
sd2k_InitTime(&a1[0]);
sd2k_ReadTime();
sd2k_DisTime();






}

void main(void)
{
u08 a[11],s;
init_devices();
sendstring1("now uart1 !\n");
sendstring1("delay 1s!\n");
delay_ms(1000);
sendstring1("now uart0!\n");
// test_net();
//printf(" i come!\n  ");
//putchar('d');
sendstring1("\n ");

SD2000test();
// ATD45DB161D_test();
/*
RAMALLTEST();

sendstring1("\n ");
test_net();
*/
while(1)
  {                if(clkUpdate)
                {        //TIFR&=0xdf;
                        clkUpdate=0;
                    sd2k_ReadTime();
                        //printf("yy:mm:dd: -d-  hh:mm:ss=%d:%d:%d  -%d- %d:%d:%d    \n",a[0],a[1],a[2],a[3],a[4],a[5],a[6]);
                        sd2k_DisTime();
                }
  }
}


调用的函数
void sd2k_ReadTime(void)
{
u08 a[7],s;

SD2K_TWI(CMD_TIMEALL_R, &a[0], 7);
for(s=0;s<7;s++)
{if(s==4){a&=0x3f;BCD2HEX(&a);}
else BCD2HEX(&a);}
sdata.year  =a[0];
sdata.month =a[1];
sdata.day          =a[2];
sdata.week  =a[3];
sdata.hour  =a[4];
sdata.minute=a[5];
sdata.second=a[6];

}
void sd2k_DisTime(void)
{

sendstring1("year:=");
sendinthex2(sdata.year);
sendstring1(":");
sendstring1("month:=");
sendinthex2(sdata.month);
sendstring1(":");
sendstring1("day:=");
sendinthex2(sdata.day);

sendstring1("week:=");
sendinthex2(sdata.week);
//sendstring1("date=");
//sendinthex2(a[3]);
//sendstring1(":");
sendstring1(" hh:mm:ss:=");
sendinthex2(sdata.hour);
sendstring1(":");
sendinthex2(sdata.minute);
sendstring1("  ");
sendinthex2(sdata.second);
sendstring1("\n");
}

//24小时制式
void sd2k_InitTime(u08* a)
{
u08 d,s;
//初始化参数判断
if(a[0]>99||a[0]<0) {sendstring1("year  error\n") ;a[0]=0;}
if(a[1]>12||a[1]<=0){sendstring1("month error\n"); a[1]=1;}
if(a[2]>31||a[2]<1){ sendstring1("day   error\n"); a[2]=1;}

if(a[3]>6 ||a[3]<0){sendstring1("week   error\n"); a[3]=0;}
if(a[4]>23||a[4]<0){sendstring1("hour   error\n"); a[4]=0;}
if(a[5]>59||a[5]<0){sendstring1("minute error\n"); a[5]=0;}
if(a[6]>59||a[6]<0){sendstring1("second error\n"); a[6]=0;}
//初始化参数设置
//初始化设置范例
//2008年3月17日 周2,17:54:35
a[0]=HEX2BCD(a[0]);
a[1]=HEX2BCD(a[1]);
a[2]=HEX2BCD(a[2]);
a[3]=HEX2BCD(a[3]);
a[4]=HEX2BCD(a[4])+0x40;//hour +0x40 24小时制
a[5]=HEX2BCD(a[5]);
a[6]=HEX2BCD(a[6]);
/*
a[0]=8;//year           08
a[1]=3;//month                02
a[2]=0X17;//date                01
a[3]=1;//week                 02                                                                                  
a[4]=0X52;//hour  12
a[5]=0X20;//mm-                14
a[6]=00;//ss       00
*/
/*
for(s=0;s<7;s++)
{
sendstring1("a1[");
sendinthex1(s);
sendstring1("]=");
sendinthex1(a1);
sendstring1(" ");
}
sendstring1("\n");
for(s=0;s<7;s++)
{
sendstring1("a1[");
sendinthex1(s);
sendstring1("]=");
sendinthex1(invert(a1));
sendstring1(" ");
}
sendstring1("\n");
*/
//开始复位
d=1;
s= SD2K_TWI(CMD_STUSR_W, &d, 1);//0x62
//开始写实时数据
SD2K_TWI(CMD_TIMEALL_W, &a[0], 7);
//状态寄存器1
d=2;
SD2K_TWI(CMD_RESET-1, &d, 1);
//状态寄存器2
d=1;
SD2K_TWI(CMD_STUSR_W,&d,1);
//int1寄存器
d=3;
SD2K_TWI(CMD_INT1_W, &d, 1);
//int2寄存器
d=0;
SD2K_TWI(CMD_INT2_W, &d, 1);
//时钟调整
d=0;
SD2K_TWI(CMD_TIMEADJ_W, &d, 1);
//通用寄存器
d=0;
SD2K_TWI(CMD_GER_W, &d, 1);



}

出0入0汤圆

发表于 2008-3-17 18:35:19 | 显示全部楼层
完全糊涂了

出0入0汤圆

 楼主| 发表于 2008-3-19 13:29:24 | 显示全部楼层
现在开始调试LCD1602,初步可以实现显示,但是第2行还是没有!郁闷中!!!

出0入0汤圆

发表于 2008-3-20 12:49:23 | 显示全部楼层
ZigBee="你这个B"

出0入0汤圆

 楼主| 发表于 2008-3-28 15:10:19 | 显示全部楼层

lcd001 (原文件名:LCD1602-001.jpg)


lcd002 (原文件名:LCD1602-002.jpg)

LCD终于可以控制了!!!

出0入0汤圆

 楼主| 发表于 2008-3-28 15:11:17 | 显示全部楼层
LCD初始化函数
void lcd_init(void) //初始化液晶
{
DDRB|=0X80; //SET PB7
DDRG|=0X10; //OUT PG4
DDRG|=0X08; //CLK PG3
delay_nms(100);
lcd_write_cmd(0x38,0); //显示模式设置(不测试忙信号)共三次
// delay_nms(15);
delay_nus(4100);
lcd_write_cmd(0x38,0);
delay_nus(100);
lcd_write_cmd(0x38,0);
// delay_nus(100);
delay_nms(40);
//lcd_write_cmd(0x20,0);
//delay_nms(15);


lcd_write_cmd(0x38,1); //8位数据口,2行显示,5*7点阵
lcd_write_cmd(0x08,1); //显示关
lcd_write_cmd(0x01,1); //清屏
lcd_write_cmd(0x06,1); //数据读,写后AC自增1,画面不动
lcd_write_cmd(0x0C,1); //显示开
}

出0入296汤圆

发表于 2008-3-28 15:34:00 | 显示全部楼层
恭喜老大从苦难中挣脱出来……

出0入0汤圆

 楼主| 发表于 2008-4-2 10:33:52 | 显示全部楼层
谢谢终于现在开始调试XBEE模块了!
自己整理了一个简单的XBEE模块接口命令集.doc
XBEE模块接口命令集.docourdev_243440.doc(文件大小:1.14M) (原文件名:XBEE模块接口命令集.doc)

出0入0汤圆

 楼主| 发表于 2008-4-2 10:34:40 | 显示全部楼层
一个不错的代码库!!!http://sixcode.googlecode.com/svn/trunk/

出0入0汤圆

发表于 2008-4-2 11:14:21 | 显示全部楼层
顶一个

出0入0汤圆

发表于 2008-4-2 14:21:08 | 显示全部楼层
标记下,祝楼主早日“修成正果”

出0入0汤圆

 楼主| 发表于 2008-4-2 14:24:41 | 显示全部楼层
谢谢!
剩下还有2个工作
1.XBEE模块测试以及库函数编写
2.整合所有的功能!!

出0入0汤圆

 楼主| 发表于 2008-4-2 14:57:25 | 显示全部楼层
发现一个非常好的ZIGBEE代码
http://www.makingthings.com/ref/firmware/html/group___x_bee.html

XBee
[Controller]
Communicate with XBee (Zigbee) wireless modules via the Make Controller's serial port. More...


Modules
  XBee Packet Types
  The different types of packet that can be used with the XBee subsystem.



Functions
int  XBee_SetActive (int state)
  Controls the active state of the XBee subsystem.

int  XBee_GetActive ()
  Read the active state of the XBee subsystem.

int  XBee_GetPacket (XBeePacket *packet, int timeout)
  Receive an incoming XBee packet.

int  XBee_SendPacket (XBeePacket *packet, int datalength)
  Send an XBee packet.

void  XBee_ResetPacket (XBeePacket *packet)
  Initialize a packet before reading into it.

void  XBeeConfig_SetPacketApiMode (int value)
  Set a module into packet API mode.

int  XBeeConfig_RequestPacketApiMode ()
  Query whether the module is in API mode.

void  XBee_CreateATCommandPacket (XBeePacket *packet, uint8 frameID, char *cmd, uint8 *params, uint8 datalength)
  A convenience function for creating an AT command packet.

int  XBeeConfig_RequestATResponse (char *cmd)
  Query the address of the module.

void  XBeeConfig_SetIO (int pin, int value)
  Configure the IO settings on an XBee module.

int  XBeeConfig_RequestIO (int pin)
  Query the configuration of an IO pin.

bool  XBee_CreateTX16Packet (XBeePacket *xbp, uint8 frameID, uint16 destination, uint8 options, uint8 *data, uint8 datalength)
  Create a packet to be transmitted with a 16-bit address.

bool  XBee_CreateTX64Packet (XBeePacket *xbp, uint8 frameID, uint64 destination, uint8 options, uint8 *data, uint8 datalength)
  Create a packet to be transmitted with a 64-bit address.

bool  XBee_ReadRX16Packet (XBeePacket *xbp, uint16 *srcAddress, uint8 *sigstrength, uint8 *options, uint8 **data, uint8 *datalength)
  Unpack the info from an incoming packet with a 16-bit address.

bool  XBee_ReadRX64Packet (XBeePacket *xbp, uint64 *srcAddress, uint8 *sigstrength, uint8 *options, uint8 **data, uint8 *datalength)
  Unpack the info from an incoming packet with a 64-bit address.

bool  XBee_ReadIO16Packet (XBeePacket *xbp, uint16 *srcAddress, uint8 *sigstrength, uint8 *options, int *samples)
  Unpack the info from an incoming IO packet with a 16-bit address.

bool  XBee_ReadIO64Packet (XBeePacket *xbp, uint64 *srcAddress, uint8 *sigstrength, uint8 *options, int *samples)
  Unpack the info from an incoming IO packet with a 64-bit address.

bool  XBee_ReadAtResponsePacket (XBeePacket *xbp, uint8 *frameID, char **command, uint8 *status, uint8 **data)
  Unpack the info from an incoming AT Command Response packet.

bool  XBee_ReadTXStatusPacket (XBeePacket *xbp, uint8 *frameID, uint8 *status)
  Unpack the info from TX Status packet.

void  XBeeConfig_WriteStateToMemory (void)
  Save the configuration changes you've made on the module to memory.

void  XBeeConfig_SetAddress (uint16 address)
  Set this module's address.

int  XBeeConfig_RequestAddress ()
  Query the address of the module.

void  XBeeConfig_SetPanID (uint16 id)
  Set this PAN (Personal Area Network) ID.

int  XBeeConfig_RequestPanID ()
  Query the PAN ID of the module.

void  XBeeConfig_SetChannel (uint8 channel)
  Set the module's channel.

int  XBeeConfig_RequestChannel ()
  Query the channel of the module.

void  XBeeConfig_SetSampleRate (uint16 rate)
  Set the rate at which the module will sample its IO pins.

int  XBeeConfig_RequestSampleRate ()
  Query the sample rate of the module.

void  XBee_IntToBigEndianArray (int value, uint8 *array)
  Convert a 32-bit integer into a big endian array of 4 unsigned 8-bit integers.



--------------------------------------------------------------------------------

Detailed Description
Communicate with XBee (Zigbee) wireless modules via the Make Controller's serial port.
XBee modules from MaxStream are small, cheap ($19 each), wireless RF (radio frequency) modules that can easily be used with the Make Controller Kit to create projects that require wireless communication. Check http://www.maxstream.net/products/xbee/xbee-oem-rf-module-zigbee.php for more info.

Overview
XBee modules are ZigBee/IEEE 802.15.4 compliant and can operate in several modes:
Transparent serial port. Messages in one side magically end up at the other endpoint. Great for enabling wireless communication between 2 Make Controllers.
AT command mode. Send traditional AT commands to configure the module itself (as opposed to having the data go straight through via serial mode.
Packet (API) mode. Lower level communication that doesn't have to wait for the module to be in AT command mode. Check the XBee Packet Types for a description of how these packets are laid out. Be sure to call XBeeConfig_SetPacketApiMode before trying to do anything in this mode.
The general idea is that you have one XBee module connected directly to your Make Controller Kit, and then any number of other XBee modules that can communicate with it in order to get information to and from the Make Controller. Or, several Make Controllers can each have an XBee module connected in order to communicate wirelessly among themselves.

XBee modules also have some digital and analog I/O right on them, which means you can directly connect sensors to the XBee modules which will both read the values and send them wirelessly. Check the XBee doc for the appropriate commands to send in order to set this up.

API
The Make Controller API for working with the XBee modules makes use of the XBee Packet API. If you simply want to make use of the transparent serial port functionality, you don't need to deal with any of this - simply hook up the module to your Make Controller and start reading and writing over the serial port.
The XBee Packet API allows for much more flexible and powerful communication with the modules. It uses AT commands to configure the XBee module itself, and then a handful of Zigbee specified packet types can be sent and received. See XBee Packet Types for details on these packet types.

The XBeeConfig_ functions are convenient wrappers around some of the most common AT commands you might want to send. For any of the other AT commands, check the XBee documentation and create them using XBee_CreateATCommandPacket( ). These will always be send to the XBee module attached to the Make Controller. The XBee_ functions deal with sending and receiving messages to other XBee modules not connected to the Make Controller.


--------------------------------------------------------------------------------

Function Documentation
void XBee_CreateATCommandPacket  ( XBeePacket *  packet,  
  uint8  frameID,  
  char *  cmd,  
  uint8 *  params,  
  uint8  datalength   
)   

A convenience function for creating an AT command packet.

As per the XBee spec, AT Command packets that want to set/write a value must have 4 bytes of data. Packets that query the value of an AT parameter send 0 bytes of data. Note that multi-byte data must be sent big-endian (most significant byte first) - see XBee_IntToBigEndianArray( ).

Make sure you're in API mode before creating & sending packets - see XBeeConfig_SetPacketApiMode( ). See the XBee documentation for the official list of AT commands that the XBee modules understand.

Parameters:
packet  The XBeePacket to create.  
frameID  The frame ID for this packet that subsequent response/status messages can refer to.  
cmd  The 2-character AT command.  
params  A pointer to the buffer containing the data to be sent.  
datalength  The number of bytes to send from the params buffer.  

Returns:
An integer specifying the active state - 1 (active) or 0 (inactive).
Example - Writing
  XBeePacket txPacket;
  uint8 params[4];
  XBee_IntToBigEndianArray( 1000, params ); // set our sampling rate to 1000
  XBee_CreateATCommandPacket( &txPacket, 0, "IR", &params, 4 ); // set the sampling rate of the IO pins
  XBee_SendPacket( &txPacket, 4 );
Example - Reading
  XBeePacket txPacket;
  XBee_CreateATCommandPacket( &txPacket, 0, "IR", NULL, 0 ); // query the sampling rate of the IO pins
  XBee_SendPacket( &txPacket, 0 );
  // then we'll receive a response packet
Definition at line 384 of file xbee.c.


bool XBee_CreateTX16Packet  ( XBeePacket *  xbp,  
  uint8  frameID,  
  uint16  destination,  
  uint8  options,  
  uint8 *  data,  
  uint8  datalength   
)   

Create a packet to be transmitted with a 16-bit address.

If the frameID is 0, you won't receive a TX Status message in response.


Parameters:
xbp  The XBeePacket to create.  
frameID  The frame ID for this packet that subsequent response/status messages can refer to.  
destination  The destination address for this packet.  
options  The XBee options for this packet (0 if none).  
data  A pointer to the data to be sent in this packet.  
datalength  The number of bytes of data to be sent.  

Returns:
True on success, false on failure.
Example
  XBeePacket txPacket;
  uint8 data[] = "ABC";
  XBee_CreateTX16Packet( &txPacket, 0x52, 0, 0, data, 3 );
  XBee_SendPacket( &txPacket, 3 );
Definition at line 492 of file xbee.c.


bool XBee_CreateTX64Packet  ( XBeePacket *  xbp,  
  uint8  frameID,  
  uint64  destination,  
  uint8  options,  
  uint8 *  data,  
  uint8  datalength   
)   

Create a packet to be transmitted with a 64-bit address.


Parameters:
xbp  The XBeePacket to create.  
frameID  The frame ID for this packet that subsequent response/status messages can refer to.  
destination  The destination address for this packet.  
options  The XBee options for this packet (0 if none).  
data  A pointer to the data to be sent in this packet.  
datalength  The number of bytes of data to be sent.  

Returns:
True on success, false on failure.
Example
  XBeePacket txPacket;
  uint8 data[] = "ABCDE";
  XBee_CreateTX16Packet( &txPacket, 0, 0, 0, data, 5 );
  XBee_SendPacket( &txPacket, 5 );
Definition at line 525 of file xbee.c.


int XBee_GetActive  ( void    )   

Read the active state of the XBee subsystem.


Returns:
An integer specifying the active state - 1 (active) or 0 (inactive).
Definition at line 121 of file xbee.c.


int XBee_GetPacket  ( XBeePacket *  packet,  
  int  timeout   
)   

Receive an incoming XBee packet.

A single call to this will continue to read from the serial port as long as there are characters to read or until it times out. If a packet has not been completely received, call it repeatedly with the same packet.

Clear out a packet before reading into it with a call to XBee_ResetPacket( )

Parameters:
packet  The XBeePacket to receive into.  
timeout  The number of milliseconds to wait for a packet to arrive. Set this to 0 to return as soon as there are no characters left to process.  

Returns:
1 if a complete packet has been received, 0 if not.
See also:
XBeeConfig_SetPacketApiMode( )
Example
  // we're inside a task here...
  XBeePacket myPacket;
  XBee_ResetPacket( &myPacket );
  while( 1 )
  {
    if( XBee_GetPacket( &myPacket, 100 ) )
    {
      // process the new packet
      XBee_ResetPacket( &myPacket ); // then clear it out before reading again
    }
    Sleep( 10 );
  }
Definition at line 155 of file xbee.c.


void XBee_IntToBigEndianArray  ( int  value,  
  uint8 *  array   
)   

Convert a 32-bit integer into a big endian array of 4 unsigned 8-bit integers.

This is mostly useful for sending AT Command packets.

Parameters:
value  The value to convert.  
array  An array of 4 unsigned 8-bit integers (uint8). Be sure you have 4.  

Example
see XBee_CreateATCommandPacket( ) for an example.
Definition at line 1059 of file xbee.c.


bool XBee_ReadAtResponsePacket  ( XBeePacket *  xbp,  
  uint8 *  frameID,  
  char **  command,  
  uint8 *  status,  
  uint8 **  data   
)   

Unpack the info from an incoming AT Command Response packet.

In response to a previous AT Command message, the module will send an AT Command Response message.

Pass NULL into any of the parameters you don't care about.

Parameters:
xbp  The XBeePacket to read from.  
frameID  A pointer to a uint64 that will be filled up with the 16-bit address of this packet.  
command  A pointer to a uint8 that will be filled up with the signal strength of this packet.  
status  A pointer to a uint8 that will be filled up with the XBee options for this packet.  
data  A pointer that will be set to the data of this packet.  

Returns:
True on success, false on failure.
Example
  XBeePacket rxPacket;
  if( XBee_GetPacket( &rxPacket, 0 ) )
  {
    uint8 frameID;
    char* command;
    uint8 status;
    uint8* data;
    if( XBee_ReadAtResponsePacket( &rxPacket, &frameID, command, &status, &data ) )
    {
      // then process the new packet here
      XBee_ResetPacket( &rxPacket ); // and clear it out before reading again
    }
  }
Definition at line 782 of file xbee.c.


bool XBee_ReadIO16Packet  ( XBeePacket *  xbp,  
  uint16 *  srcAddress,  
  uint8 *  sigstrength,  
  uint8 *  options,  
  int *  samples   
)   

Unpack the info from an incoming IO packet with a 16-bit address.

When an XBee module has been given a sample rate, it will sample its IO pins according to their current configuration and send an IO packet with the sample data. This function will extract the sample info into an array of ints for you. There are 9 IO pins on the XBee modules, so be sure that the array you pass in has room for 9 ints.

Pass NULL into any of the parameters you don't care about.

Parameters:
xbp  The XBeePacket to read from.  
srcAddress  A pointer to a uint16 that will be filled up with the 16-bit address of this packet.  
sigstrength  A pointer to a uint8 that will be filled up with the signal strength of this packet.  
options  A pointer to a uint8 that will be filled up with the XBee options for this packet.  
samples  A pointer to an array of ints that will be filled up with the sample values from this packet.  

Returns:
True on success, false on failure.
See also:
XBeeConfig_SetSampleRate( ), XBeeConfig_SetIOs( )
Example
  XBeePacket rxPacket;
  if( XBee_GetPacket( &rxPacket, 0 ) )
  {
    uint16 src;
    uint8 sigstrength;
    int samples[9];
    if( XBee_ReadIO16Packet( &rxPacket, &src, &sigstrength, NULL, samples ) )
    {
      // then process the new packet here
      XBee_ResetPacket( &rxPacket ); // and clear it out before reading again
    }
  }
Definition at line 675 of file xbee.c.


bool XBee_ReadIO64Packet  ( XBeePacket *  xbp,  
  uint64 *  srcAddress,  
  uint8 *  sigstrength,  
  uint8 *  options,  
  int *  samples   
)   

Unpack the info from an incoming IO packet with a 64-bit address.

When an XBee module has been given a sample rate, it will sample its IO pins according to their current configuration and send an IO packet with the sample data. This function will extract the sample info into an array of ints for you. There are 9 IO pins on the XBee modules, so be sure that the array you pass in has room for 9 ints.

Pass NULL into any of the parameters you don't care about.

Parameters:
xbp  The XBeePacket to read from.  
srcAddress  A pointer to a uint64 that will be filled up with the 16-bit address of this packet.  
sigstrength  A pointer to a uint8 that will be filled up with the signal strength of this packet.  
options  A pointer to a uint8 that will be filled up with the XBee options for this packet.  
samples  A pointer to an array of ints that will be filled up with the sample values from this packet.  

Returns:
True on success, false on failure.
See also:
XBeeConfig_SetSampleRate( ), XBeeConfig_SetIOs( )
Example
  XBeePacket rxPacket;
  if( XBee_GetPacket( &rxPacket, 0 ) )
  {
    uint64 src;
    uint8 sigstrength;
    int samples[9];
    if( XBee_ReadIO16Packet( &rxPacket, &src, &sigstrength, NULL, samples ) )
    {
      // then process the new packet here
      XBee_ResetPacket( &rxPacket ); // and clear it out before reading again
    }
  }
Definition at line 728 of file xbee.c.


bool XBee_ReadRX16Packet  ( XBeePacket *  xbp,  
  uint16 *  srcAddress,  
  uint8 *  sigstrength,  
  uint8 *  options,  
  uint8 **  data,  
  uint8 *  datalength   
)   

Unpack the info from an incoming packet with a 16-bit address.

Pass NULL into any of the parameters you don't care about.

Parameters:
xbp  The XBeePacket to read from.  
srcAddress  The 16-bit address of this packet.  
sigstrength  The signal strength of this packet.  
options  The XBee options for this packet.  
data  A pointer that will be set to the data of this packet.  
datalength  The length of data in this packet.  

Returns:
True on success, false on failure.
Example
  XBeePacket rxPacket;
  if( XBee_GetPacket( &rxPacket, 0 ) )
  {
    uint16 src;
    uint8 sigstrength;
    uint8* data;
    uint8 datalength;
    if( XBee_ReadRX16Packet( &rxPacket, &src, &sigstrength, NULL, &data, &datalength ) )
    {
      // then process the new packet here
      XBee_ResetPacket( &rxPacket ); // and clear it out before reading again
    }
  }
Definition at line 569 of file xbee.c.


bool XBee_ReadRX64Packet  ( XBeePacket *  xbp,  
  uint64 *  srcAddress,  
  uint8 *  sigstrength,  
  uint8 *  options,  
  uint8 **  data,  
  uint8 *  datalength   
)   

Unpack the info from an incoming packet with a 64-bit address.

Pass NULL into any of the parameters you don't care about.

Parameters:
xbp  The XBeePacket to read from.  
srcAddress  The 64-bit address of this packet.  
sigstrength  The signal strength of this packet.  
options  The XBee options for this packet.  
data  A pointer that will be set to the data of this packet.  
datalength  The length of data in this packet.  

Returns:
True on success, false on failure.
Example
  XBeePacket rxPacket;
  if( XBee_GetPacket( &rxPacket, 0 ) )
  {
    uint64 src;
    uint8 sigstrength;
    uint8* data;
    uint8 datalength;
    if( XBee_ReadRX64Packet( &rxPacket, &src, &sigstrength, NULL, &data, &datalength ) )
    {
      // then process the new packet here
      XBee_ResetPacket( &rxPacket ); // and clear it out before reading again
    }
  }
Definition at line 619 of file xbee.c.


bool XBee_ReadTXStatusPacket  ( XBeePacket *  xbp,  
  uint8 *  frameID,  
  uint8 *  status   
)   

Unpack the info from TX Status packet.

When a TX is completed, the modules esnds a TX Status message. This indicates whether the packet was transmitted successfully or not. If the message you sent had a frameID of 0, a TX status message will not be generated.

Pass NULL into any of the parameters you don't care about.

Parameters:
xbp  The XBeePacket to read from.  
frameID  A pointer to a uint8 that will be filled up with the frame ID of this packet.  
status  A pointer to a uint8 that will be filled up with the status of this packet.  

Returns:
True on success, false on failure.
Example
  XBeePacket rxPacket;
  if( XBee_GetPacket( &rxPacket, 0 ) )
  {
    uint8 frameID;
    uint8 status;
    if( XBee_ReadTXStatusPacket( &rxPacket, &frameID, &status ) )
    {
      // then process the new packet here
      XBee_ResetPacket( &rxPacket ); // and clear it out before reading again
    }
  }
Definition at line 823 of file xbee.c.


void XBee_ResetPacket  ( XBeePacket *  packet   )   

Initialize a packet before reading into it.


Parameters:
packet  The XBeePacket to initialize.  

See also:
XBee_GetPacket( )
Definition at line 274 of file xbee.c.


int XBee_SendPacket  ( XBeePacket *  packet,  
  int  datalength   
)   

Send an XBee packet.

Use the following functions to create packets to be sent:

XBee_CreateTX16Packet( ) - create a data packet to be sent out wirelessly with a 16-bit address
XBee_CreateTX64Packet( ) - create a data packet to be sent out wirelessly with a 64-bit address
XBee_CreateATCommandPacket( ) - create an AT command to configure an attached XBee module
Parameters:
packet  The XBeePacket to send.  
datalength  The length of the actual data being sent (not including headers, options, etc.)  

Returns:
Zero on success.
See also:
XBeeConfig_SetPacketApiMode( )
Example
  XBeePacket txPacket;
  uint8 data[] = "ABC"; // 3 bytes of data
  XBee_CreateTX16Packet( &txPacket, 0, 0, 0, data, 3 );
  XBee_SendPacket( &txPacket, 3 );
Definition at line 232 of file xbee.c.


int XBee_SetActive  ( int  state   )   

Controls the active state of the XBee subsystem.


Parameters:
state  Whether this subsystem is active or not  

Returns:
Zero on success.
Definition at line 88 of file xbee.c.


int XBeeConfig_RequestAddress  ( void    )   

Query the address of the module.

This will block for up to a 1/2 second waiting for a response from the XBee module.

Returns:
An integer corresponding to the address of the module, or negative number on failure.
Example
  int address = XBeeConfig_RequestAddress( );
  if( address >= 0 )
  {
    // then we have our address
  }
Definition at line 897 of file xbee.c.


int XBeeConfig_RequestATResponse  ( char *  cmd   )   

Query the address of the module.

This will block for up to a 1/2 second waiting for a response from the XBee module.

Returns:
An integer corresponding to the address of the module, or negative number on failure.
Example
  int address = XBeeConfig_RequestAddress( );
  if( address >= 0 )
  {
    // then we have our address
  }
Definition at line 410 of file xbee.c.


int XBeeConfig_RequestChannel  ( void    )   

Query the channel of the module.

This will block for up to a 1/2 second waiting for a response from the XBee module.

Returns:
An integer corresponding to the channel of the module, or negative number on failure.
Example
  int chan = XBeeConfig_RequestChannel( );
  if( chan >= 0 )
  {
    // then we have our channel
  }
Definition at line 994 of file xbee.c.


int XBeeConfig_RequestIO  ( int  pin   )   

Query the configuration of an IO pin.

See XBeeConfig_SetIO( ) for the possible return values. This will block for up to a 1/2 second waiting for a response from the XBee module.

Returns:
An integer corresponding to the config of the requested pin, or negative number on failure.
Example
  int pin = XBeeConfig_RequestIO( 0 ); // request the configuration of pin 0
  if( pin >= 0 )
  {
    // then we have our pin config
  }
Definition at line 462 of file xbee.c.


int XBeeConfig_RequestPacketApiMode  ( void    )   

Query whether the module is in API mode.

This will block for up to a 1/2 second waiting for a response from the XBee module.

Returns:
0 if off, 1 if enabled, 2 if enabled with escape characters.
Example
  int mode = XBeeConfig_RequestPacketApiMode( );
  if( mode >= 0 )
  {
    // then we have our mode
  }
Definition at line 344 of file xbee.c.


int XBeeConfig_RequestPanID  ( void    )   

Query the PAN ID of the module.

This will block for up to a 1/2 second waiting for a response from the XBee module.

Returns:
An integer corresponding to the PAN ID of the module, or negative number on failure.
Example
  int panid = XBeeConfig_RequestPanID( );
  if( panid >= 0 )
  {
    // then we have our pan id
  }
Definition at line 944 of file xbee.c.


int XBeeConfig_RequestSampleRate  ( void    )   

Query the sample rate of the module.

This will block for up to a 1/2 second waiting for a response from the XBee module.

Returns:
An integer corresponding to the sample rate of the module, or negative number on failure.
Example
  int rate = XBeeConfig_RequestSampleRate( );
  if( rate >= 0 )
  {
    // then we have our rate
  }
Definition at line 1042 of file xbee.c.


void XBeeConfig_SetAddress  ( uint16  address   )   

Set this module's address.

As with the other XBeeConfig functions, make sure you're in API mode before trying to use this function.

Parameters:
address  An integer specifying the module's address.  

Returns:
True on success, false on failure.
See also:
XBeeConfig_SetPacketApiMode( )
Example
  XBeeConfig_SetPacketApiMode( );
  XBeeConfig_SetAddress( 100 );
  XBeeConfig_WriteStateToMemory( );
Definition at line 874 of file xbee.c.


void XBeeConfig_SetChannel  ( uint8  channel   )   

Set the module's channel.

The channel is one of 3 addressing options available to the module - the others are the PAN ID and the destination address. In order for modules to communicate with each other, the modules must share the same channel number. Default is 0x0C.

This value can have the range 0x0B - 0x1A for XBee modules, and 0x0C - 0x17 for XBee-Pro modules.

As with the other XBeeConfig functions, make sure you're in API mode before trying to use this function.

Parameters:
channel  A uint8 specifying the channel.  

Returns:
True on success, false on failure.
See also:
XBeeConfig_SetPacketApiMode( )
Example
  XBeeConfig_SetPacketApiMode( );
  XBeeConfig_SetChannel( 0x0D );
Definition at line 971 of file xbee.c.


void XBeeConfig_SetIO  ( int  pin,  
  int  value   
)   

Configure the IO settings on an XBee module.

IO pins can have one of 5 values:

XBEE_IO_DISABLED
XBEE_IO_ANALOGIN - Analog input (10-bit)
XBEE_IO_DIGITALIN - Digital input
XBEE_IO_DIGOUT_HIGH - Digital out high
XBEE_IO_DIGOUT_LOW - Digital out low
Parameters:
pin  An integer specifying which pin to configure. There are 9 IO pins (numbered 0-8) on the XBee modules. Only channels 0-7 can be analog inputs - channel 8 can only operate as a digital in or out.  
value  An int specifying the behavior of this pin (options shown above).  

Example
  // set channel 0 to analog in
  XBeeConfig_SetIO( 0, XBEE_IO_ANALOGIN );
Definition at line 435 of file xbee.c.


void XBeeConfig_SetPacketApiMode  ( int  value   )   

Set a module into packet API mode.

XBee modules are in transparent serial port mode by default. This allows you to work with them via the packet API.

When setting this on, the XBee module needs to wait 1 second after sending the command sequence before it's ready to receive any AT commands - this function will block for that amount of time. Once you turn it off, you won't get any responses to packets you send the module until you turn packet mode on again.

Parameters:
value  1 to turn packet mode on, 0 to turn it off.

Example
  MyTask( void * p )
  {
    XBeeConfig_SetPacketApiMode( 1 ); // initialize the module to be in API mode
    while( 1 )
    {
      // your task here.
    }
  }
Definition at line 306 of file xbee.c.


void XBeeConfig_SetPanID  ( uint16  id   )   

Set this PAN (Personal Area Network) ID.

Only modules with matching PAN IDs can communicate with each other. Unique PAN IDs enable control of which RF packets are received by a module. Default is 0x3332.

As with the other XBeeConfig functions, make sure you're in API mode before trying to use this function.

Parameters:
id  A uint16 specifying the PAN ID.  

Returns:
True on success, false on failure.
See also:
XBeeConfig_SetPacketApiMode( )
Example
  XBeeConfig_SetPacketApiMode( );
  XBeeConfig_SetPanID( 0x1234 );
Definition at line 921 of file xbee.c.


void XBeeConfig_SetSampleRate  ( uint16  rate   )   

Set the rate at which the module will sample its IO pins.

When the sample rate is set, the module will sample all its IO pins according to its current IO configuration and send a packet with the sample data. If this is set too low and the IO configuration is sampling too many channels, the RF module won't be able to keep up. You can also adjust how many samples are gathered before a packet is sent.

As with the other XBeeConfig functions, make sure you're in API mode before trying to use this function.

Parameters:
rate  A uint16 specifying the sample rate in milliseconds.  

Returns:
True on success, false on failure.
See also:
XBeeConfig_SetIOs( ), XBeeConfig_SetPacketApiMode( )
Example
  XBeeConfig_SetPacketApiMode( );
  XBeeConfig_SetSampleRate( 0x14 );
Definition at line 1019 of file xbee.c.


void XBeeConfig_WriteStateToMemory  ( void    )   

Save the configuration changes you've made on the module to memory.

When you make configuration changes - setting the module to API mode, or configuring the sample rate, for example - those changes will be lost when the module restarts. Call this function to save the current state to non-volatile memory.

As with the other XBeeConfig functions, make sure you're in API mode before trying to use this function.

Returns:
True on success, false on failure.
See also:
XBeeConfig_SetPacketApiMode( )
Example
  XBeeConfig_SetPacketApiMode( );
  XBeeConfig_SetSampleRate( 100 );
  XBeeConfig_WriteStateToMemory( );
Definition at line 850 of file xbee.c.

出0入0汤圆

发表于 2008-4-2 15:12:46 | 显示全部楼层
感谢分享

请教lz,AVR128 + CC2420模块 方案,对比你用的xbee如何?
能否做一下比较?哪个更具有通用性?源码丰富上手快?

出0入0汤圆

发表于 2008-4-2 15:28:01 | 显示全部楼层
mark

出0入0汤圆

发表于 2008-4-2 18:32:57 | 显示全部楼层
lz真乃好人也!!!3Q

出0入46汤圆

发表于 2008-4-2 19:00:47 | 显示全部楼层
学习了!

出0入0汤圆

 楼主| 发表于 2008-4-3 08:39:26 | 显示全部楼层
请教lz,AVR128 + CC2420模块 方案,对比你用的xbee如何?
CC2420我记得是ZIGBEE ready的芯片
我这个模块是FCC认证的,质量肯定没得说!!

出0入0汤圆

发表于 2008-4-3 19:38:16 | 显示全部楼层
原理图上有一个SDIRQ#网络号,不知道是接在哪的,请lz看一下

还有个问题请教,如果用138译码输出片选地址,那么是否应该nNET_CS -->  AEN, SA8 --> VCC,其余保持不变?

出0入0汤圆

发表于 2008-4-4 22:02:06 | 显示全部楼层
请lz帮我看一下我画的8019,看看有啥问题没?

M128 3.3v供电,8019 5v
读写信号,复位,中断,全部直接连MCU,
片选型号产生于138

点击此处下载 ourdev_244842.pdf(文件大小:26K) (原文件名:8019.pdf)

出0入0汤圆

发表于 2008-4-5 15:46:38 | 显示全部楼层
w我手头有个2430的,可是用不来

出0入0汤圆

 楼主| 发表于 2008-4-11 11:53:11 | 显示全部楼层
SDIRQ# 空着的

出0入0汤圆

 楼主| 发表于 2008-4-11 11:54:36 | 显示全部楼层
XBEE通过串口0来测试与串口1连接的XBEE模块!!

本测试函数说明:
1.基本思路:
我们通过uart1与ZIGBEE模块连接,交互显示需要使用UART0来进行,串口都使用9600,8,N,1
串口都不使用缓冲环.通过串口0显示XBEE模块的设置状态和发送命令.
流程分析:
1.PC串口软件->串口0接收->串口1发送->xbee模块
2.XBEE模块发送->串口1接收->串口0发送->PC串口软件
显示的信息包含以下内容:
1.1本模块信息:
1)模块类型:xbee/xbeepro

1.2网络与安全

2)通道CH Set/read the channel number (Uses 802.15.4 channel numbers).
RANGE:0xC-0x17

3)PANID Set the PAN (Personal Area Network) ID. Set ID = 0xFFFF to send message to all PANs.
RANGE:0-0xFFFF
               
4)地址高位DH Set/read the upper 32 bits of the 64 bit destination address. Set the DH register to zero and DL less than 0xFFFF to transmit using a 16 bit address. 0x000000000000FFFF is the broadcast address for the PAN.
RANGE:0-0xFFFFFFFF

5)地址低位DL Set/read the lower 32 bits of the 64 bit destination address. Set the DH register to zero and DL less than 0xFFFF to transmit using a 16 bit address.  0x000000000000FFFF is the broadcast address for the PAN.
RANGE:0-0xFFFFFFFF

6)MY 源地址 16位 Set/read the 16-bit source address for the modem. Set MY = 0xFFFF to disable reception of packets with 16-bit addresses. 64-bit source address is the serial number and is always enabled.
RANGE:0-0xFFFF

7)序列号高位SH Read high 32 bits of modems unique IEEE 64-bit source address. 64-bit source address is always enabled.

8)序列号低位SL Read low 32 bits of modems unique IEEE 64-bit source address. 64-bit source address is always enabled.

9)RR xbee retries Set number of retries the modem will execute in addition to the 3 retries provided by the 802.15.4 MAC. For each XBee retry, the 802.15.4 MAC can execute up to 3 retries.
RANGE:0-0x6
                  
10)RN RANDOM DELAY SLOTS Set/Read the minimum value of the back-off exponent in the CSMA-CA algorithm that is used for collision avoidance. If RN = 0, collision avoidance is disabled during the first iteration of the algorithm (802.15.4 - macMinBE)
RANGE:0-0x3

11)MM MAC MODE Set/Read MAC Mode value. MAC Mode enables/disables the use of a MaxStream header in the 802.15.4 RF packet. When Mode 0 is enabled (MM=0), duplicate packet detection is enabled as well as certain AT commands. Modes 1 and 2 are strict 802.15.4 modes.

12)NT 节点发现时间 Set/read Node Discover Time register. This sets the maximum time for the Node Discover command.
RANGE:0x1-0xFC    x 100 ms

13)CE coordinator enable Set/Read the coordinator setting: 0 - End Device, 1 - Coordinator.

14)SC scan channel Read/set list of channels to scan for Active and Energy Scans as bitfield. Scans may be initiated by the ATAS, ATED commands and during End Device Association and Coordinator startup: Bit 15  - Ch. 0x1A . . . Bit 0 -Ch. 0x0B (bits 15, 14 and 0 not available on XBee-PRO)
RANGE:0-0xFFFF   Bitfield

15)SD SCAN DURATION Set read the Scan duration exponent. The exponent configures the duration of the active scan during association. Set End Device SD = BE of  beaconing coordinator. Scan Time = N* (2 ^ SD) * 15.36ms. N=# channels: XBee = 16, XBee/Pro = 13.
RANGE:0-0x0F   exponent

16)A1 END DEVICE ASSOCIATION Set/read End Device association options. Options enabled when bits are set: bit3 - Poll coordinator on pin wake, bit2 - Auto Associate, bit1 - Allow Channel reassignment, bit0 - Allow PanId reassignment.

17)A2 coordinator ASSOCIATION Set/read Coordinator association options. Options enabled when bits are set:  bit2 - Allow Association, bit1 - Allow Channel reassignment, bit0 - Allow PanId reassignment.

18)AI ASSOCIATION 指示 Read Association status code to monitor association progress.

19)EE AES ENCRYPTION ENABLE Enables AES encryption

20)KY AES ENCRYPTION KEY  Sets key used for encryption and decryption. This register can not be read.

21)NI 网络指示Set/Read Node Identifier string

1.3RF接口

22)PL POWER LEVEL Select/Read transmitter output power. XBee-PRO: 0= 10dBm, 1= 12dBm, 2= 14dBm, 3= 16dBm, 4= 18dBm. XBee: 0= -10dBm, 1= -6dBm, 2= -4dBm, 3= -2dBm, 4= 0dBm.

23)CA CCA THRESHOLD Set/read the Clear Channel Assessment (CCA) threshold. If the modem detects energy above the CCA Threshold, if will not transmit. The CCA parameter is measured in units of -dBm.
RANGE:0-0x50   -dBm

1.4SLEEP MODES( NON BEACON)

24)SM SLEEP MODE Set/read sleep mode: Pin Hibernate is lowest power, Pin Doze provides the fastest wake up, Cyclic Sleep Remote with or without pin wake up. Sleep Coordinator setting is for SM parameter compatibility with version 106; ATCE should be used going forward.
25)ST TIME BEFORE SLEEP

26)SP 周期休眠时间 Set/read time period of inactivity (no serial or RF data is sent or received) before activating Sleep Mode. The ST parameter is used only with Cyclic Sleep settings (SM=4-5). Set ST on Cyclic Sleep Coordinator to match Cyclic Sleep Remotes
RANGE:0x1-0xFFFF   x 1 ms

27)DP 断掉连接周期休眠时间 Set/read sleep period for cyclic sleeping remotes that are configured for Association but that are not associated to a Coordinator. Maximum sleep period is 268 seconds (0x68B0).
RANGE:1-0x68B0   x 10 ms

1.5串口设置
28)BD 接口速率 Set/read the serial interface baud rate for communication between modem serial port and host. Request non-standard baud rates with values above 0x80 using a terminal window. Read BD register to find actual baud rate achieved.

29)RO PACKETIZATION TIMOUT Set/read number of character times of inter-character delay required before transmission begins. Set to zero to transmit characters as they arrive instead of buffering them into one RF packet.
RANGE:0-0xFF   x character times

30)AP API ENABLE Enables API mode

31)PR 上拉电阻使能 Set/read bitfield to configure internal pull-up resistors status for I/O lines. 1=internal pull-up enabled, 0=no internal pull-up. Bitfield map:  Bit 7 - DIN (P3), Bit 6 - DI8/SLEEP_RQ (P9), Bit 5 - DIO6/RTS (P16), Bit 4 - DIO0 (P20), Bit 3 - DIO1 (P19), Bit 2 - DIO2 (P18), Bit 1 - DIO3 (P17), Bit 0 - DIO4 (P11).

1.6 IO口设置
32)D8 Configure options for the DI8 line of the module. Options include: Digital Input. This line is also used with Pin Sleep
33)D7 Configure options for the DIO7 line of the module. Options include: CTS flow control, Digital Input and Output.
34)D6 Configure options for the DIO6 line of the module. Options include: RTS flow control, Digital Input and Output.
35)D5 Configure options for the DIO5 line of the module. Options include: Associated LED indicator (blinks when associated),Digital Input and Output.
36)D4 Configure options for the DIO4 line of the module. Options include: Analog to Digital converter,Digital Input and Output.
37)D3 Configure options for the DIO3 line of the module. Options include: Analog to Digital converter,Digital Input and Output.
38)D2 Configure options for the DIO2 line of the module. Options include: Analog to Digital converter,Digital Input and Output.
39)D1 Configure options for the DIO1 line of the module. Options include: Analog to Digital converter,Digital Input and Output.
40)D0 Configure options for the DIO0 line of the module. Options include: Analog to Digital converter,Digital Input and Output.

41)IU IO输出使能 Enables I/O data received to be sent out UART. The data is sent using an API frame regardless of the current ATAP mode.

42)IT samples before TX Set/read number of samples to collect before transmission. The maximum number of samples is dependent on the number of enabled I/O lines.
RANGE:0x1-0xFF

43)IC DIO CHANGE DETECT Set/Read bitfield values for change detect monitoring.Each bit enables monitoring of DIO0-DIO7 for changes. If detected, data is transmitted with DIO data only. Any samples queued waiting for transmission will be sent first.
RANGE:0-0xFF

44)IR Set/read sample rate. When set this parameter causes the modem to sample all enabled DIO and ADC at a specified interval.
RANGE:0-0xFFFF   X 1 ms

1.6.1 IO LINE PASSING

45)IA IO INPUT ADDRESS Set/Read addresses of module to which outputs are bound. Setting all bytes to 0xFF will not allow any receive I/O packet to change outputs. Setting address to 0xFFFF will allow any received I/O packet to change outputs.

46)T0 D0 OUTPUT TIMEOUT Set/Read Output timeout value. When output is set, due to I/O line passing, to a non-default level a timer is started which when expired will set the output to it default level. The timer is reset when a valid I/O packet is received.
RANGE:0-0xFF  x 100 ms
47)T1
48)T2
49)T3
50)T4
51)T5
52)T6
53)T7
54)P0 PWM0 设置 Select/Read function for PWM0.
55)P1 PWM1 设置 Select/Read function for PWM1.
56)PT PWM outputtimeout Set/Read output timeout value for both PWM outputs. when PWM is set to a non-zero value, due to I/O line passing, a time is started which when expired will set the PWM output to zero. The timer is reset when a valid I/O packet is received.
          RANGE:0-0xFF  x 100 ms
57)RP RSSI PWM TIMER Set/read PWM timer register. Set duration of PWM (pulse width modulation) signal output on the RSSI pin (P6). The signal duty cycle is updated with each received packet and is shut off when the timer expires.
          RANGE:0-0xFF   x 100 ms

1.7 DIAGNOSTICS 诊断命令

58)VR FIRMWARE VERSION Read modem firmware version number.

59)HV HARDWARE VERSION Read modem hardware version number.

60)DB接收信号强度  Read signal level of last good packet received (RSSI) in dB (reports absolute value, eg. -88dBm = 0x58, accurate between -40 dBm to RX sensitivity).

61)EC CCA FAILURE Reset/read count of Clear Channel Assessment (CCA) failures. This register increments when the modem does not transmit a packet because it detected energy above the CCA threshold level set with CA command. This count saturates at its maximum value. Set count to zero to reset count.

62)EA ACK FAILURE Reset/read count of acknowledgment failures. This register increments when the modem expires the retries without receiving an ACK on a packet transmission. This count saturates at its maximum value. Set count to zero to reset count.

1.8 AT命令
63)CT AT命令模式超时时间

64)GT guard 时间Set required period of silence before, after and between the Command Mode Characters of the Command Mode Sequence (GT + CC + GT). The period of silence is used to prevent inadvertent entrance into AT Command Mode.
RANGE:0x2-0xCE4   x 1ms

65)CC command 序列字符Set/read character value to be used to break from data mode to command mode. The default value <2Bh> is the ASCII code for the plus ('+') character.
RANGE:0-0xFF   Recommended: 0x20-0x7F (ASCII)

出0入0汤圆

 楼主| 发表于 2008-4-15 15:59:13 | 显示全部楼层
更新版本
本测试函数说明:
1.基本思路:
我们通过uart1与ZIGBEE模块连接,交互显示需要使用UART0来进行,串口都使用9600,8,N,1
串口都使用缓冲环.通过串口0显示XBEE模块的设置状态和发送命令.
流程分析:

在主程序中判断串口0的缓冲是否为空,

如果不为空,则把数据读到UART1的发送缓冲区,然后发送

如果为空则检查串口1的缓冲区是否为空,如果不为空,则把读到UART0的发送缓冲然后发送

如果为空继续循环.

在这里需要设立2个缓冲环来处理数据接收

UART0接收缓冲环用来接收PC串口数据

UART1接收缓冲环用来接收xbee模块数据

每个缓冲环设置512字节,数据发送缓冲区每个UART为50个字节


!!!特别注意是否在发送命令后需要延时??待定


1.PC串口软件->串口0接收->串口1发送->xbee模块


2.XBEE模块发送->串口1接收->串口0发送->PC串口软件



Modify RF Module Destination Address
Method 1 (One line per command)
Send AT Command                                              System Response
+++                                                                 OK <CR> (Enter into Command Mode)
ATDL <Enter>                                        {current value} <CR> (Read Destination Address Low)
ATDL1A0D <Enter>                                OK <CR> (Modify Destination Address Low)
ATWR <Enter>                                        OK <CR> (Write to non-volatile memory)
ATCN <Enter>                                        OK <CR> (Exit Command Mode)
Method 2 (Multiple commands on one line)
Send AT Command                                       System Response
+++                                                                 OK <CR> (Enter into Command Mode)
ATDL <Enter>                                        {current value} <CR>(Read Destination Address Low)
ATDL1A0D,WR,CN <Enter>                        OK, OK, OK <CR> (Command execution is triggered upon each instance of the comma)

显示的信息包含以下内容:
1.1本模块信息:
1)模块类型:xbee/xbeepro

1.2网络与安全

2)通道CH Set/read the channel number (Uses 802.15.4 channel numbers).
RANGE:0xC-0x17

3)PANID Set the PAN (Personal Area Network) ID. Set ID = 0xFFFF to send message to all PANs.
RANGE:0-0xFFFF
               
4)地址高位DH Set/read the upper 32 bits of the 64 bit destination address. Set the DH register to zero and DL less than 0xFFFF to transmit using a 16 bit address. 0x000000000000FFFF is the broadcast address for the PAN.
RANGE:0-0xFFFFFFFF

5)地址低位DL Set/read the lower 32 bits of the 64 bit destination address. Set the DH register to zero and DL less than 0xFFFF to transmit using a 16 bit address.  0x000000000000FFFF is the broadcast address for the PAN.
RANGE:0-0xFFFFFFFF

6)MY 源地址 16位 Set/read the 16-bit source address for the modem. Set MY = 0xFFFF to disable reception of packets with 16-bit addresses. 64-bit source address is the serial number and is always enabled.
RANGE:0-0xFFFF

7)序列号高位SH Read high 32 bits of modems unique IEEE 64-bit source address. 64-bit source address is always enabled.

8)序列号低位SL Read low 32 bits of modems unique IEEE 64-bit source address. 64-bit source address is always enabled.

9)RR xbee retries Set number of retries the modem will execute in addition to the 3 retries provided by the 802.15.4 MAC. For each XBee retry, the 802.15.4 MAC can execute up to 3 retries.
RANGE:0-0x6
                  
10)RN RANDOM DELAY SLOTS Set/Read the minimum value of the back-off exponent in the CSMA-CA algorithm that is used for collision avoidance. If RN = 0, collision avoidance is disabled during the first iteration of the algorithm (802.15.4 - macMinBE)
RANGE:0-0x3

11)MM MAC MODE Set/Read MAC Mode value. MAC Mode enables/disables the use of a MaxStream header in the 802.15.4 RF packet. When Mode 0 is enabled (MM=0), duplicate packet detection is enabled as well as certain AT commands. Modes 1 and 2 are strict 802.15.4 modes.

12)NT 节点发现时间 Set/read Node Discover Time register. This sets the maximum time for the Node Discover command.
RANGE:0x1-0xFC    x 100 ms

13)CE coordinator enable Set/Read the coordinator setting: 0 - End Device, 1 - Coordinator.

14)SC scan channel Read/set list of channels to scan for Active and Energy Scans as bitfield. Scans may be initiated by the ATAS, ATED commands and during End Device Association and Coordinator startup: Bit 15  - Ch. 0x1A . . . Bit 0 -Ch. 0x0B (bits 15, 14 and 0 not available on XBee-PRO)
RANGE:0-0xFFFF   Bitfield

15)SD SCAN DURATION Set read the Scan duration exponent. The exponent configures the duration of the active scan during association. Set End Device SD = BE of  beaconing coordinator. Scan Time = N* (2 ^ SD) * 15.36ms. N=# channels: XBee = 16, XBee/Pro = 13.
RANGE:0-0x0F   exponent

16)A1 END DEVICE ASSOCIATION Set/read End Device association options. Options enabled when bits are set: bit3 - Poll coordinator on pin wake, bit2 - Auto Associate, bit1 - Allow Channel reassignment, bit0 - Allow PanId reassignment.

17)A2 coordinator ASSOCIATION Set/read Coordinator association options. Options enabled when bits are set:  bit2 - Allow Association, bit1 - Allow Channel reassignment, bit0 - Allow PanId reassignment.

18)AI ASSOCIATION 指示 Read Association status code to monitor association progress.

19)EE AES ENCRYPTION ENABLE Enables AES encryption

20)KY AES ENCRYPTION KEY  Sets key used for encryption and decryption. This register can not be read.

21)NI 网络指示Set/Read Node Identifier string

1.3RF接口

22)PL POWER LEVEL Select/Read transmitter output power. XBee-PRO: 0= 10dBm, 1= 12dBm, 2= 14dBm, 3= 16dBm, 4= 18dBm. XBee: 0= -10dBm, 1= -6dBm, 2= -4dBm, 3= -2dBm, 4= 0dBm.

23)CA CCA THRESHOLD Set/read the Clear Channel Assessment (CCA) threshold. If the modem detects energy above the CCA Threshold, if will not transmit. The CCA parameter is measured in units of -dBm.
RANGE:0-0x50   -dBm

1.4SLEEP MODES( NON BEACON)

24)SM SLEEP MODE Set/read sleep mode: Pin Hibernate is lowest power, Pin Doze provides the fastest wake up, Cyclic Sleep Remote with or without pin wake up. Sleep Coordinator setting is for SM parameter compatibility with version 106; ATCE should be used going forward.
25)ST TIME BEFORE SLEEP

26)SP 周期休眠时间 Set/read time period of inactivity (no serial or RF data is sent or received) before activating Sleep Mode. The ST parameter is used only with Cyclic Sleep settings (SM=4-5). Set ST on Cyclic Sleep Coordinator to match Cyclic Sleep Remotes
RANGE:0x1-0xFFFF   x 1 ms

27)DP 断掉连接周期休眠时间 Set/read sleep period for cyclic sleeping remotes that are configured for Association but that are not associated to a Coordinator. Maximum sleep period is 268 seconds (0x68B0).
RANGE:1-0x68B0   x 10 ms

1.5串口设置
28)BD 接口速率 Set/read the serial interface baud rate for communication between modem serial port and host. Request non-standard baud rates with values above 0x80 using a terminal window. Read BD register to find actual baud rate achieved.

29)RO PACKETIZATION TIMOUT Set/read number of character times of inter-character delay required before transmission begins. Set to zero to transmit characters as they arrive instead of buffering them into one RF packet.
RANGE:0-0xFF   x character times

30)AP API ENABLE Enables API mode

31)PR 上拉电阻使能 Set/read bitfield to configure internal pull-up resistors status for I/O lines. 1=internal pull-up enabled, 0=no internal pull-up. Bitfield map:  Bit 7 - DIN (P3), Bit 6 - DI8/SLEEP_RQ (P9), Bit 5 - DIO6/RTS (P16), Bit 4 - DIO0 (P20), Bit 3 - DIO1 (P19), Bit 2 - DIO2 (P18), Bit 1 - DIO3 (P17), Bit 0 - DIO4 (P11).

1.6 IO口设置
32)D8 Configure options for the DI8 line of the module. Options include: Digital Input. This line is also used with Pin Sleep
33)D7 Configure options for the DIO7 line of the module. Options include: CTS flow control, Digital Input and Output.
34)D6 Configure options for the DIO6 line of the module. Options include: RTS flow control, Digital Input and Output.
35)D5 Configure options for the DIO5 line of the module. Options include: Associated LED indicator (blinks when associated),Digital Input and Output.
36)D4 Configure options for the DIO4 line of the module. Options include: Analog to Digital converter,Digital Input and Output.
37)D3 Configure options for the DIO3 line of the module. Options include: Analog to Digital converter,Digital Input and Output.
38)D2 Configure options for the DIO2 line of the module. Options include: Analog to Digital converter,Digital Input and Output.
39)D1 Configure options for the DIO1 line of the module. Options include: Analog to Digital converter,Digital Input and Output.
40)D0 Configure options for the DIO0 line of the module. Options include: Analog to Digital converter,Digital Input and Output.

41)IU IO输出使能 Enables I/O data received to be sent out UART. The data is sent using an API frame regardless of the current ATAP mode.

42)IT samples before TX Set/read number of samples to collect before transmission. The maximum number of samples is dependent on the number of enabled I/O lines.
RANGE:0x1-0xFF

43)IC DIO CHANGE DETECT Set/Read bitfield values for change detect monitoring.Each bit enables monitoring of DIO0-DIO7 for changes. If detected, data is transmitted with DIO data only. Any samples queued waiting for transmission will be sent first.
RANGE:0-0xFF

44)IR Set/read sample rate. When set this parameter causes the modem to sample all enabled DIO and ADC at a specified interval.
RANGE:0-0xFFFF   X 1 ms

1.6.1 IO LINE PASSING

45)IA IO INPUT ADDRESS Set/Read addresses of module to which outputs are bound. Setting all bytes to 0xFF will not allow any receive I/O packet to change outputs. Setting address to 0xFFFF will allow any received I/O packet to change outputs.

46)T0 D0 OUTPUT TIMEOUT Set/Read Output timeout value. When output is set, due to I/O line passing, to a non-default level a timer is started which when expired will set the output to it default level. The timer is reset when a valid I/O packet is received.
RANGE:0-0xFF  x 100 ms
47)T1
48)T2
49)T3
50)T4
51)T5
52)T6
53)T7
54)P0 PWM0 设置 Select/Read function for PWM0.
55)P1 PWM1 设置 Select/Read function for PWM1.
56)PT PWM outputtimeout Set/Read output timeout value for both PWM outputs. when PWM is set to a non-zero value, due to I/O line passing, a time is started which when expired will set the PWM output to zero. The timer is reset when a valid I/O packet is received.
          RANGE:0-0xFF  x 100 ms
57)RP RSSI PWM TIMER Set/read PWM timer register. Set duration of PWM (pulse width modulation) signal output on the RSSI pin (P6). The signal duty cycle is updated with each received packet and is shut off when the timer expires.
          RANGE:0-0xFF   x 100 ms

1.7 DIAGNOSTICS 诊断命令

58)VR FIRMWARE VERSION Read modem firmware version number.

59)HV HARDWARE VERSION Read modem hardware version number.

60)DB接收信号强度  Read signal level of last good packet received (RSSI) in dB (reports absolute value, eg. -88dBm = 0x58, accurate between -40 dBm to RX sensitivity).

61)EC CCA FAILURE Reset/read count of Clear Channel Assessment (CCA) failures. This register increments when the modem does not transmit a packet because it detected energy above the CCA threshold level set with CA command. This count saturates at its maximum value. Set count to zero to reset count.

62)EA ACK FAILURE Reset/read count of acknowledgment failures. This register increments when the modem expires the retries without receiving an ACK on a packet transmission. This count saturates at its maximum value. Set count to zero to reset count.

1.8 AT命令
63)CT AT命令模式超时时间

64)GT guard 时间Set required period of silence before, after and between the Command Mode Characters of the Command Mode Sequence (GT + CC + GT). The period of silence is used to prevent inadvertent entrance into AT Command Mode.
RANGE:0x2-0xCE4   x 1ms

65)CC command 序列字符Set/read character value to be used to break from data mode to command mode. The default value <2Bh> is the ASCII code for the plus ('+') character.
RANGE:0-0xFF   Recommended: 0x20-0x7F (ASCII)

出0入0汤圆

 楼主| 发表于 2008-4-15 16:08:34 | 显示全部楼层
现在开始通过串口0来调试串口1的XBEE模块
软件采用青云COMMAX
串口设置如下:

串口设置 (原文件名:config.jpg)


报文定义 (原文件名:报文0.jpg)


+++启动指令 (原文件名:+++.jpg)


ATBD (原文件名:ATBD.jpg)

出0入0汤圆

 楼主| 发表于 2008-4-15 16:09:19 | 显示全部楼层

ATID (原文件名:ATID.jpg)

出0入0汤圆

 楼主| 发表于 2008-4-15 16:12:20 | 显示全部楼层

ATMY (原文件名:ATMY.jpg)


ATSH (原文件名:ATSH.jpg)


ATSL (原文件名:ATSL.jpg)

出0入0汤圆

 楼主| 发表于 2008-4-17 17:07:25 | 显示全部楼层
现在测试串口0/1不用中断和缓冲区来测试基础参数的读取

zigbee串口测试 (原文件名:xbeet2.jpg)

出0入0汤圆

 楼主| 发表于 2008-4-17 17:09:59 | 显示全部楼层
//不使用缓冲环的串口1函数
//等待ok
void ReadUart1(void)
{
char c;
unsigned char i;

i=0;
c=XBEE_Get();Uart1RxBuf[i++]=c;
c=XBEE_Get();Uart1RxBuf[i++]=c;
c=XBEE_Get();Uart1RxBuf[i++]=c;

}
void ReadUart2(void)
{
char c,i;
i=0;
while(1)
{
c=XBEE_Get();
//if((c==0x0a)&&(i==0))c=XBEE_Get();
//if(i>=1)c=XBEE_Get();
Uart1RxBuf[i++]=c;
if(c==0x0a)break;
if(c==0x0d)break;
}

}


//xbee接口测试函数
//1.+++启动命令
void Xbee_Start(void)
{
//Uart1BufTxClear();
Uart1BufRxClear();
sendstring0("\\发送启动命令+++\n");
sendstring1("+++");
ReadUart1();
sendstring0((unsigned char *)&Uart1RxBuf);
sendstring0("\n");
//Uart1BufRxClear();
}
void Xbee_Command(char *buf)
{
//unsigned char ulen;
     char i=0x0d;
         sendstring0(buf);
         sendstring0("\n");

         Uart1BufTxClear();
         Uart1BufRxClear();
         //首先复制命令字符串到UART1的发送缓冲
         memcpy((char *)&Uart1TxBuf[0],buf,strlen(buf) );
         strcat(( char *)&Uart1TxBuf[0],&i);
         sendstring1(( char *)&Uart1TxBuf[0]);
         ReadUart2();
         sendstring0(( char *)&Uart1RxBuf);
         sendstring0("\n");
         Uart1BufTxClear();
}

出0入0汤圆

 楼主| 发表于 2008-4-17 17:10:25 | 显示全部楼层
void XbeeTest(void)
{
unsigned int u0len,u1len;
unsigned int u00len,u11len;
unsigned char p;
u0len=u1len=0;
//串口指针初始化
Uart0_RxHead=0;
Uart0_RxTail=0;
//串口0缓冲环发送首尾指针
Uart0_TxHead=0;
Uart0_TxTail=0;
//串口1缓冲环接收首尾指针
Uart1_RxHead=0;
Uart1_RxTail=0;
//串口1缓冲环发送首尾指针
Uart1_TxHead=0;
Uart1_TxTail=0;
Xbee_RstH;
Xbee_RstL;
asm("nop\n");
asm("nop\n");
asm("nop\n");
asm("nop\n");
asm("nop\n");
asm("nop\n");
asm("nop\n");
asm("nop\n");
Xbee_RstH;

//缓冲区初始化
Uart0BufTxClear();
Uart1BufTxClear();


//这里需要开uart1的接收中断,发送中断不要开
SEI(); //re-enable interrupts
//
sendstring0("\\现在开始测试XBEE模块\n");

//1.发送启动命令等待,回应OK<CR>
Xbee_Start();
delay_nms(1000);
Xbee_Command("ATDL");
delay_nms(1000);
Xbee_Command("ATDH");
delay_nms(1000);
Xbee_Command("ATBD");
delay_nms(1000);
Xbee_Command("ATID");
delay_nms(1000);
Xbee_Command("ATMY");
delay_nms(1000);
Xbee_Command("ATSH");
delay_nms(1000);
Xbee_Command("ATSL");

UCSR0B = 0x00; //disable while setting baud rate
UCSR0A = 0x00;
UCSR0C = 0x06;
UBRR0L = 0x67; //set baud rate lo
UBRR0H = 0x00; //set baud rate hi
// UCSR0B = 0x18;
UCSR0B = 0x90;
UCSR0B|=(1<<RXCIE0)|/*(1<<TXCIE0)|*/(1<<RXEN0)|(1<<TXEN0);

UCSR1B = 0x00; //disable while setting baud rate
UCSR1A = 0x00;
UCSR1C = 0x06;
UBRR1L = 0x67; //set baud rate lo
UBRR1H = 0x00; //set baud rate hi
//UCSR1B = 0x18;
//  UCSR1B = 0x90;
  UCSR1B|=(1<<RXCIE1)|/*(1<<TXCIE)|*/(1<<RXEN1)|(1<<TXEN1);
u00len=0;
p=0;//(unsigned char *)&Uart0TxBuf[0];

while(1)
{
checkuart0:

u0len=Uart0BufReadLen();
u00len+=u0len;
//接收到+++或者/r结束的字符串
if(u0len!=0)
{               
                //如果不支持连续读,则后续的数据会覆盖前面的数据
                Uart0BufRead((unsigned char *)&Uart0TxBuf[0],u0len);
               
               
                                 //pc来的数据从串口0进来,发送到串口1
                                 sendstring0((unsigned char *)&Uart0TxBuf[0]);
                                 
                                 
                                 sendstring1((unsigned char *)&Uart0TxBuf[0]);
                                 Uart0BufTxClear();
                                 p=0;//&Uart0TxBuf[0];
                                 u00len=0;
                       
}

checkuart1:

u1len=Uart1BufReadLen();
if(u1len!=0)
{               
Uart1BufRead((unsigned char *)&Uart1TxBuf,u1len);
//XBEE来的数据从串口1进来,发送到串口0
sendstring0((unsigned char *)&Uart1TxBuf);
Uart1BufTxClear();
  }
          





}

}

出0入0汤圆

 楼主| 发表于 2008-4-18 09:49:25 | 显示全部楼层
完整参数读取的范例!!
RD:now uart0!
\现在开始测试XBEE模块

\发送启动命令+++    (09:47:47:843)

RD:OK
(09:47:48:859)

RD:ATCH   C
(09:47:49:812)

RD:ATID   123
(09:47:50:843)

RD:ATDH   0
(09:47:51:859)

RD:ATDL   0
(09:47:52:875)

RD:ATMY   0
(09:47:53:875)

RD:ATSH   13A200
(09:47:54:890)

RD:ATSL   40090186
(09:47:55:890)

RD:ATRR   ERROR
(09:47:56:921)

RD:ATRN   0
(09:47:57:937)

RD:ATMM   0
(09:47:58:968)

RD:ATNT   ERROR
(09:47:59:984)

RD:ATCE   0
(09:48:01:015)

RD:ATSC   1FFE
(09:48:01:906)

RD:ATSD   4
(09:48:02:937)

RD:ATA1   0
(09:48:03:953)

RD:ATA2   0
(09:48:04:968)

RD:ATAI   00
(09:48:06:000)

RD:ATPL   4
(09:48:07:015)

RD:ATCA   2C
(09:48:08:031)

RD:ATSM   0
(09:48:09:062)

RD:ATST   1388
(09:48:10:078)

RD:ATSP   0
(09:48:11:109)

RD:ATDP   3E8
(09:48:12:125)

RD:Serial Interfacing
ATBD   3
(09:48:13:171)

RD:ATRO   3
(09:48:14:187)

RD:ATPR   FF
(09:48:15:187)

RD:I/O Settings
ATD8   ERROR
(09:48:16:234)

RD:ATD7   1
(09:48:17:250)

RD:ATD6   0
(09:48:18:265)

RD:ATD5   1
(09:48:19:296)

RD:ATD4   ERROR
(09:48:19:968)

RD:ATD3   ERROR
(09:48:21:000)

RD:ATD2   ERROR
(09:48:22:031)

RD:ATD1   ERROR
(09:48:23:062)

RD:ATD0   ERROR
(09:48:24:093)

RD:ATIT   ERROR
(09:48:25:125)

RD:ATIS   ERROR
(09:48:26:156)

RD:ATIR   ERROR
(09:48:26:843)

RD:ATIA   ERROR
(09:48:27:875)

RD:ATT0   ERROR
(09:48:28:906)

RD:ATT1   ERROR
(09:48:29:937)

RD:ATT2   ERROR
(09:48:30:953)

RD:ATT3   ERROR
(09:48:31:984)

RD:ATT4   ERROR
(09:48:33:015)

RD:ATT5   ERROR
(09:48:34:046)

RD:ATT6   ERROR
(09:48:35:078)

RD:ATT7   ERROR
(09:48:36:109)

RD:ATP0   1
(09:48:37:125)

RD:ATP1   ERROR
(09:48:38:156)

RD:ATM0   ERROR
(09:48:39:187)

RD:ATM1   ERROR
(09:48:40:218)

RD:ATPT   ERROR
(09:48:41:234)

RD:ATRP   28
(09:48:42:265)

RD:Diagnostics
ATVR   1083
(09:48:43:296)

RD:ATVL   XBee 802.15.4 RELEASE V 1083, Build: May 04 2006 17:10:13
(09:48:44:437)

RD:ATHV   Ha
(09:48:45:453)

RD:ATDB   17
(09:48:46:468)

RD:ATEC   0
(09:48:47:484)

RD:ATEA   0
(09:48:48:500)

RD:AT Command Options
ATCT   0
(09:48:49:531)

RD:ATCC   64
(09:48:50:343)

出0入0汤圆

 楼主| 发表于 2008-4-18 09:51:47 | 显示全部楼层
sendstring0("\\现在开始测试XBEE模块\n");

//1.发送启动命令等待,回应OK<CR>
Xbee_Start();
delay_nms(1000);
Xbee_Command("ATCH");
delay_nms(1000);
Xbee_Command("ATID");
delay_nms(1000);
Xbee_Command("ATDH");
delay_nms(1000);
Xbee_Command("ATDL");
delay_nms(1000);
Xbee_Command("ATMY");
delay_nms(1000);
Xbee_Command("ATSH");
delay_nms(1000);
Xbee_Command("ATSL");
delay_nms(1000);
Xbee_Command("ATRR");
delay_nms(1000);
Xbee_Command("ATRN");
delay_nms(1000);
Xbee_Command("ATMM");
delay_nms(1000);

Xbee_Command("ATNT");
delay_nms(1000);
Xbee_Command("ATCE");
delay_nms(1000);

Xbee_Command("ATSC");
delay_nms(1000);

Xbee_Command("ATSD");
delay_nms(1000);

Xbee_Command("ATA1");
delay_nms(1000);
Xbee_Command("ATA2");
delay_nms(1000);
Xbee_Command("ATAI");
delay_nms(1000);

Xbee_Command("ATPL");
delay_nms(1000);

Xbee_Command("ATCA");
delay_nms(1000);
Xbee_Command("ATSM");
delay_nms(1000);

Xbee_Command("ATST");
delay_nms(1000);
Xbee_Command("ATSP");
delay_nms(1000);

Xbee_Command("ATDP");
delay_nms(1000);
sendstring0("Serial Interfacing\n");
Xbee_Command("ATBD");
delay_nms(1000);
Xbee_Command("ATRO");
delay_nms(1000);
Xbee_Command("ATPR");
delay_nms(1000);
sendstring0("I/O Settings\n");
Xbee_Command("ATD8");
delay_nms(1000);
Xbee_Command("ATD7");
delay_nms(1000);
Xbee_Command("ATD6");
delay_nms(1000);
Xbee_Command("ATD5");
delay_nms(1000);
Xbee_Command("ATD4");
delay_nms(1000);
Xbee_Command("ATD3");
delay_nms(1000);
Xbee_Command("ATD2");
delay_nms(1000);
Xbee_Command("ATD1");
delay_nms(1000);
Xbee_Command("ATD0");
delay_nms(1000);
Xbee_Command("ATIT");
delay_nms(1000);
Xbee_Command("ATIS");
delay_nms(1000);

Xbee_Command("ATIR");
delay_nms(1000);
// Xbee_Command("ATAV"); //XBEEPRO-特有
// delay_nms(1000);
Xbee_Command("ATIA");
delay_nms(1000);
Xbee_Command("ATT0");
delay_nms(1000);
Xbee_Command("ATT1");
delay_nms(1000);
Xbee_Command("ATT2");
delay_nms(1000);
Xbee_Command("ATT3");
delay_nms(1000);
Xbee_Command("ATT4");
delay_nms(1000);
Xbee_Command("ATT5");
delay_nms(1000);
Xbee_Command("ATT6");
delay_nms(1000);
Xbee_Command("ATT7");
delay_nms(1000);
Xbee_Command("ATP0");
delay_nms(1000);
Xbee_Command("ATP1");
delay_nms(1000);
Xbee_Command("ATM0");
delay_nms(1000);
Xbee_Command("ATM1");
delay_nms(1000);
Xbee_Command("ATPT");
delay_nms(1000);
Xbee_Command("ATRP");
delay_nms(1000);
sendstring0("Diagnostics\n");
Xbee_Command("ATVR");
delay_nms(1000);
Xbee_Command("ATVL");
delay_nms(1000);
Xbee_Command("ATHV");
delay_nms(1000);
Xbee_Command("ATDB");
delay_nms(1000);
Xbee_Command("ATEC");
delay_nms(1000);
Xbee_Command("ATEA");
delay_nms(1000);
sendstring0("AT Command Options\n");
Xbee_Command("ATCT");
delay_nms(1000);
Xbee_Command("ATCC");
delay_nms(1000);

出0入0汤圆

 楼主| 发表于 2008-4-18 09:57:02 | 显示全部楼层
下面把基于XBEEPRO的coordinator的设置写个程序!

出0入0汤圆

 楼主| 发表于 2008-4-22 18:06:40 | 显示全部楼层
现在开始点到点的测试!已经初步通过了!!

(原文件名:image001.png)


(原文件名:image002.jpg)


(原文件名:image003.png)


(原文件名:image004.jpg)


(原文件名:image005.png)


(原文件名:image006.jpg)


(原文件名:image007.png)


(原文件名:image008.jpg)


(原文件名:image009.png)


(原文件名:image010.jpg)


(原文件名:image011.png)


(原文件名:image012.jpg)

出0入0汤圆

 楼主| 发表于 2008-4-22 18:08:24 | 显示全部楼层

(原文件名:image013.png)


(原文件名:image014.jpg)


(原文件名:image015.png)


(原文件名:image016.jpg)


(原文件名:image017.png)


(原文件名:image018.jpg)


(原文件名:image019.png)


(原文件名:image020.jpg)


(原文件名:image021.png)


(原文件名:image022.jpg)


(原文件名:image023.png)


(原文件名:image024.jpg)

出0入0汤圆

 楼主| 发表于 2008-4-22 18:09:16 | 显示全部楼层

(原文件名:image025.png)


(原文件名:image026.jpg)


(原文件名:image027.png)


(原文件名:image028.jpg)

出0入0汤圆

发表于 2008-4-23 09:34:36 | 显示全部楼层
楼主能发一原理图上来吗?pdf格式的也行  3楼的pdf 不是原理图

出0入0汤圆

 楼主| 发表于 2008-4-23 10:13:47 | 显示全部楼层
14 楼有呀!!

出0入0汤圆

发表于 2008-4-24 15:12:12 | 显示全部楼层
hill!

出0入0汤圆

发表于 2008-5-8 18:45:22 | 显示全部楼层
zigbee芯片哪里买?多少钱啊?

出0入0汤圆

发表于 2008-5-29 23:38:05 | 显示全部楼层
太太强了!

出0入0汤圆

 楼主| 发表于 2008-5-30 09:02:11 | 显示全部楼层
re:zigbee芯片哪里买?多少钱啊?
用的是MAXSTREAM的模块
可以找代理

出0入0汤圆

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

本版积分规则

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

GMT+8, 2024-6-3 02:57

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

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