S3c2440(ARM9)spi_read_write闪存 [英] S3c2440(ARM9) spi_read_write Flash Memory
问题描述
当我阅读制造商ID时,显示MF_ID => 4A25BF
,但最初是MF_ID => BF254A。我得到它只是反向,意味着第一和第三个字节的第一个咬。
可能的原因是什么?
我的SPI Init函数在这里:
//启用时钟控制寄存器CLKCON 18位使能SPI
CLKCON | =(0x01 <18); // 0x40000;
printk(s3c2440_clkcon =%08ld\\\
,CLKCON);
//启用GPG2对应的NSS端口
GPGCON = 0x1011; // 010000 00 01 00 01
printk(s3c2440_GPGCON =%08ld\\\
,GPGCON);
SPNSS0_ENABLE();
//启用GPE 11,12,13,相应的MISO0,MOSI0,SCK0 = 11 0x0000FC00
GPECON& =〜((3 <22)|(3 < |(3 << 26));
GPECON | =((2 <22)|(2 <24)|(2 <26));
// GPEUP Set;所有禁用
GPGUP& =〜(0x07 <2);
GPEUP | =(0x07 // SPI寄存器部分
// SPI预分频器寄存器设置,
//波特率= PCLK / 2 /(预分频值+ 1)
SPPRE0 = 0x18; // freq = 1M
printk(SPPRE0 =%02X\\\
,SPPRE0);
//轮询,en-sck,master,low,格式A,nomal = 0 | (1 <3)|(1 <3)|(0 <2)|(0 <1)|(1 < 0℃;&小于0);
printk(SPCON1 =%02ld\\\
,SPCON0);
//启用多主机错误检测
SPPIN0 =(0 <2)| (1 <1)| (0 <0);
printk(SPPIN1 =%02X\\\
,SPPIN0);
//初始化过程
SPTDAT0 = 0xff;
我的spi_read_write函数如下:
static char spi_read_write(unsigned char outb)
{
//在SPI接口上写入和读取一个字节。
int j = 0;
unsigned char inb;
SPTDAT0 = outb; (j = 0; j <0xFF; j ++)的
while(!SPI_TXRX_READY);
SPTDAT0 = outb;
// SPTDAT0 = 0xff; (j = 0; j <0xFF; j ++)的
while(!SPI_TXRX_READY);
inb = SPRDAT0;
return(inb);
}
我的通话功能是:
MEM_1_CS(0);
spi_read_write(0x9F);
m1 = spi_read_write(0x00);
m2 = spi_read_write(0x00);
m3 = spi_read_write(0x00);
MEM_1_CS(1);
printk(\\\
\rMF_ID =>%02X-%02X-%02X,m1,m2,m3);
请指导我做什么?
感谢您的提前!!
最近几天我正在敲我的头,终于找到解决方案。所有我需要更改我的 spi_read_write
函数如下。
static char spi_read_write(unsigned char outb)
{
int j = 0;
unsigned char inb; (j = 0; j <0xFF; j ++)的
while(!SPI_TXRX_READY);
SPTDAT0 = outb; (j = 0; j <0xFF; j ++)的
while(!SPI_TXRX_READY);
inb = SPRDAT0;
return(inb);
}
更改生成:
首先我们要检查 SPI_TXRX_READY
然后用 SPTDAT0 = outb; / code>。
感谢大家的支持。
I am working on SPI communication.Trying to communicate SST25VF032B(32 MB microchip SPI Flash). When I am reading the Manufacturer Id it shows MF_ID =>4A25BF but originally it is MF_ID =>BF254A. I am getting it simply reverse, means first bite in 3rd and 3rd byte in first.
What could be the possible reason for that? My SPI Init function is here:
//Enable clock control register CLKCON 18 Bit enables SPI
CLKCON |= (0x01 << 18);//0x40000;
printk("s3c2440_clkcon=%08ld\n",CLKCON);
//Enable GPG2 Corresponding NSS port
GPGCON =0x1011;//010000 00 01 00 01
printk("s3c2440_GPGCON=%08ld\n",GPGCON);
SPNSS0_ENABLE();
//Enable GPE 11,12,13,Corresponding MISO0,MOSI0,SCK0 = 11 0x0000FC00
GPECON &= ~((3 << 22) | (3 << 24) | (3 << 26));
GPECON |= ((2 << 22) | (2 << 24) | (2 << 26));
//GPEUP Set; all disable
GPGUP &= ~(0x07 << 2);
GPEUP |= (0x07 << 11);
//SPI Register section
//SPI Prescaler register settings,
//Baud Rate=PCLK/2/(Prescaler value+1)
SPPRE0 = 0x18; //freq = 1M
printk("SPPRE0=%02X\n",SPPRE0);
//polling,en-sck,master,low,format A,nomal = 0 | TAGD = 1
SPCON0 = (0<<5)|(1<<4)|(1<<3)|(0<<2)|(0<<1)|(0<<0);
printk("SPCON1=%02ld\n",SPCON0);
//Multi-host error detection is enabled
SPPIN0 = (0 << 2) | (1 << 1) | (0 << 0);
printk("SPPIN1=%02X\n",SPPIN0);
//Initialization procedure
SPTDAT0 = 0xff;
My spi_read_write function as follows:
static char spi_read_write (unsigned char outb)
{
// Write and Read a byte on SPI interface.
int j = 0;
unsigned char inb;
SPTDAT0 = outb;
while(!SPI_TXRX_READY) for(j = 0; j < 0xFF; j++);
SPTDAT0 = outb;
//SPTDAT0 = 0xff;
while(!SPI_TXRX_READY) for(j = 0; j < 0xFF; j++);
inb = SPRDAT0;
return (inb);
}
My Calling function is:
MEM_1_CS(0);
spi_read_write(0x9F);
m1 = spi_read_write(0x00);
m2 = spi_read_write(0x00);
m3 = spi_read_write(0x00);
MEM_1_CS(1);
printk("\n\rMF_ID =>%02X-%02X-%02X",m1,m2,m3);
Please guide me what to do? Thanks in Advance!!
I was banging my head on this from last couple of days and finally I find the solution. All I needed to change my spi_read_write
function as follows.
static char spi_read_write (unsigned char outb)
{
int j = 0;
unsigned char inb;
while(!SPI_TXRX_READY) for(j = 0; j < 0xFF; j++);
SPTDAT0 = outb;
while(!SPI_TXRX_READY) for(j = 0; j < 0xFF; j++);
inb = SPRDAT0;
return (inb);
}
CHANGES MADE:
First of all we have to check whether the SPI_TXRX_READY
then fill the register with the value SPTDAT0 = outb;
.
Thanks all for your kind support.
这篇关于S3c2440(ARM9)spi_read_write闪存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!