本帖最后由 流金岁月 于 2015-3-24 10:54 编辑
我用SPI0读写M25P64,一直无法成功,请问有人知道我问题出在哪吗?
硬件:MISO0 连M25P64的Q端,MOSI0 连M25P64的D端,SSEL0连M25P64的/S端,SCLK0 连M25P64的C端,
M25P64的/W /HOLD上拉,
软件配置
#define P0_15_FNUC P0_15_SCK0//P0_15_GPIO
#define P0_17_FNUC P0_17_MISO0// P0_17_GPIO
#define P0_18_FNUC P0_18_MOSI0//P0_18_GPIO
void SPIInit(void)
{
S0SPCCR = 0x52; // Maximum SCK FREQ:F_VPB/82
S0SPCR = 0x28;//(0<<3) | (0<<4) | (1<<5) | (0<<6) | (0<<7);
}
//片选置高、置低
void SSEL0_OP(BOOLEAN op)
{
if (op == LOW) FIO0CLR = SSEL0;
else FIO0SET = SSEL0;
}
void WriteByte(uint32 address, uint8 data)
{
uint8 IsOver = 0;
WriteEn(HIGH);
SSEL0_OP(LOW);
SendByte(PAGE_PRO);
SendByte((address & 0x00ff0000)>>16);
SendByte((address & 0x0000ff00)>>8);
SendByte(address & 0x000000ff);
SendByte(data);
SSEL0_OP(HIGH);
do
{
SSEL0_OP(LOW);
SendByte(READ_STATUS_REG);
IsOver = RcvByte();
SSEL0_OP(HIGH);
}
while (IsOver & 0x01);
}
uint8 ReadByte(uint32 address)
{
uint8 data = 0;
SSEL0_OP(LOW);
SendByte(READ_DATA);
SendByte((address & 0x00ff0000)>>16);
SendByte((address & 0x0000ff00)>>8);
SendByte(address & 0x000000ff);
data = RcvByte();
SSEL0_OP(HIGH);
return(data);
}
main(void)
{
uint8 x; targetInit(); /* 初始化目标板,切勿删除 */
pinInit(); /* 引脚初始化 */
//GPIO0
FIO0DIR = FIO0DIR|SSEL0;//
SPIInit();
WriteByte(120,0x11);
x= ReadByte(120); while(1);
}
X按理应该等于0x11,但是读出为0,一直调试不通,请问谁做过类似的,能指导一下吗?
|