个问题调了好几天了,实在不知道哪出问题,跪求各位大侠帮小弟看看。
CPU是AT91RM9200 ,FLASH是三星的K9F1G08U0M,出现的问题是FLASH id老是读不正确,有的时候是0x0,有的时候是一串没规律的数字,ReadStatus()放在ReadID()之前的时候,得到的值是0xe0,放在ReadID()的时候得到的值是0x60。
源码:
#include "cpuRegs.h"
typedef unsigned long DWORD;
typedef unsigned char BYTE;
typedef unsigned char UINT8;
typedef unsigned int UINT32;
#define REG32(addr) *((volatile unsigned long * const) (addr))
#define REG08(addr) *((volatile unsigned char * const) (addr))
/* Flash commands:*/
#define SERIAL_DATA_INPUT 0x80
#define READ_MODE 0x00
#define RESET_FLASH 0xff
#define SETUP_WRITE 0x10
#define SETUP_ERASE 0x60
#define CONFIRM_ERASE 0xd0
#define READ_STATUS 0x70
#define READ_ID (0x90)
#define SUSPEND_ERASE 0xb0
#define REGISTER_READ 0xe0
#define READ_END 0x30
#define NAND_ADDR_DATA 0x40000000
#define NAND_ADDR_COMM 0x40200000
#define NAND_ADDR_ADDR 0x40400000
//#define GET_NAND_R_B ((AT91_PIOC_PDSR & (1<<5)) ? 1 : 0)
/**
* @brief CPU输出管脚控制
* @param port 端口编号(参考bsp.h)
* @param no 管脚编号
* @param value 0,置低; 非0,置高
* @retval 无
*/
void bspPinOut(char port, BYTE no, BYTE value)
{
DWORD temp = (1<<no);
if(port=='A'){
if(value)
REG32(AT91C_PIOA_SODR) = temp;
else
REG32(AT91C_PIOA_CODR) = temp;
}
else if(port=='B'){
if(value)
REG32(AT91C_PIOB_SODR) = temp;
else
REG32(AT91C_PIOB_CODR) = temp;
}
else if(port == 'C'){
if(value)
REG32(AT91C_PIOC_SODR) = temp;
else
REG32(AT91C_PIOC_CODR) = temp;
}
else if(port=='D'){
if(value)
REG32(AT91C_PIOD_SODR) = temp;
else
REG32(AT91C_PIOD_CODR) = temp;
}
}
/**
* @brief CPU输出管脚初始化
* @param port 端口编号(参考bsp.h)
* @param no 管脚编号
* @param value 初始化值; 0,置低; 非0,置高
* @retval 无
*/
void bspPinOutInit(char port, BYTE no, BYTE value)
{
DWORD temp = (1<<no);
if(port == 'A'){
REG32(AT91C_PIOA_PER) = temp;
REG32(AT91C_PIOA_OER) = temp;
}
else if(port == 'B'){
REG32(AT91C_PIOB_PER) = temp;
REG32(AT91C_PIOB_OER) = temp;
}
else if(port == 'C'){
REG32(AT91C_PIOC_PER) = temp;
REG32(AT91C_PIOC_OER) = temp;
}
else if(port == 'D'){
REG32(AT91C_PIOD_PER) = temp;
REG32(AT91C_PIOD_OER) = temp;
}
bspPinOut(port, no, value);
}
/**
* @brief CPU外设管脚初始化
* @param port 端口编号(参考bsp.h)
* @param no 管脚编号
* @param value 初始化值; 0,置低; 非0,置高
* @param ab A:选择A复用,B:选择B复用
* @retval 无
*/
void bspPinPeriInit(char port,BYTE no,char ab)
{
DWORD temp=(1<<no);
if(port == 'A'){
REG32(AT91C_PIOA_PDR) = temp;
if(ab=='A')
REG32(AT91C_PIOA_ASR) = temp;
else if (ab=='B')
REG32(AT91C_PIOA_BSR) = temp;
}
else if(port == 'B'){
REG32(AT91C_PIOB_PDR) = temp;
if(ab=='A')
REG32(AT91C_PIOB_ASR) = temp;
else if (ab=='B')
REG32(AT91C_PIOB_BSR) = temp;
}
else if(port == 'C'){
REG32(AT91C_PIOC_PDR) = temp;
if(ab=='A')
REG32(AT91C_PIOC_ASR) = temp;