我正在進行SPI通信。嘗試與SST25VF032B(32 MB微芯片SPI閃存)通信。 當我讀取製造商ID時,它顯示MF_ID => 4A25BF ,但最初它是MF_ID => BF254A。我簡單地把它翻轉過來,意思是先在第三和第三字節中先咬一口。S3c2440(ARM9)spi_read_write閃存
可能的原因是什麼? 我SPI初始化函數是在這裏:
//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;
我spi_read_write功能如下:
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);
}
我的調用函數是:
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);
請指導我該怎麼辦? 在此先感謝!
我的spi_read_write函數是unsigned char&我保留三個不同變量的返回值。所以,它應該首先打印從spi_read_write函數返回的第一個值。假設,我的函數返回整數,我得到0x11223344 insted 0x44332211,可以通過'小尾數'或'大尾數'來解釋。 – RFK
我使用的是之前的Cortex-M3控制器。我在那裏得到了MF_ID => BF254A。我的調用函數和前面一樣,只有'spi_read_write'和'spi_init'函數是不同的。但是,在這裏我得到了MF_ID => 4A25BF。我的意思是序列的命令是一樣的,那麼爲什麼我得到它倒序? – RFK