I tried to connect the two memory card devices by connecting it on ssp port of lpc2148, i have access to memory cards when i enabling them one by one but i can't access memory card device 1 when i'm enabling the both devices on file configuration.c I connected both card's MOSI,MISO,SCLK on same ssp port of lpc2148,i'm using GPIO port 0.20 for ss of one memory card and GPIO port 0.07 of another memory card
I used example program for SD_file in MCB2140 ,i modified spi driver with ss pin as gpio port 0.07 for second device,for first device i'm using inbuilt spi driver
NOTE: I can access both device separately on same bus,i can't able to access them at a time
PLS give some idea
I'm using pullup of 10k for M0SI,MISO and SS pins of both sd cards there are two pullups in a MOSI and MISO pins
This is my spi driver
/*---------------------------------------------------------------------------- SPI Driver instance definition spi0_drv: First SPI driver spi1_drv: Second SPI driver *---------------------------------------------------------------------------*/ //#define __DRV_ID spi1_drv #define __PCLK 48000000 /* SPI Driver Interface functions */ static BOOL Init (void); static BOOL Init1 (void); static BOOL UnInit (void); static BOOL UnInit1 (void); static U8 Send (U8 outb); static BOOL SendBuf (U8 *buf, U32 sz); static BOOL RecBuf (U8 *buf, U32 sz); static BOOL BusSpeed (U32 kbaud); static BOOL SetSS (U32 ss); static BOOL SetSS1 (U32 ss); static U32 CheckMedia (void); /* Optional function for SD card check */ /* SPI Device Driver Control Block */ SPI_DRV spi0_drv = { Init, UnInit, Send, SendBuf, RecBuf, BusSpeed, SetSS, CheckMedia /* Can be NULL if not existing */ }; /* SSPSR - bit definitions. */ #define TFE 0x01 #define TNF 0x02 #define RNE 0x04 #define RFF 0x08 #define BSY 0x10 SPI_DRV spi1_drv = { Init1, UnInit1, Send, SendBuf, RecBuf, BusSpeed, SetSS1, CheckMedia /* Can be NULL if not existing */ }; /*--------------------------- Init ------------------------------------------*/ static BOOL Init (void) { /* Initialize and enable the SSP Interface module. */ /* SSEL is GPIO, output set to high. */ IODIR0 |= 1<<20; IOSET0 = 1<<20; /* SCK1, MISO1, MOSI1 are SSP pins. */ PINSEL1 = (PINSEL1 & ~0x000003FC) | 0x000000A8; // reset SPI SSPCR1 = 0x0000; SSPCR0 = 0x0000; SSPCPSR = 0x00; /* Enable SPI in Master Mode, CPOL=0, CPHA=0. */ SSPCR0 = 0x0007; SSPCR1 = 0x0002; SSPCPSR = 0xFE; return (__TRUE); } /*--------------------------- UnInit ----------------------------------------*/ static BOOL UnInit (void) { /* Return SSP interface to default state. */ IODIR0 &= ~(1<<20); PINSEL1 &= ~0x000003FC; SSPCR1 = 0x0000; SSPCR0 = 0x0000; SSPCPSR = 0x00; return (__TRUE); } /*--------------------------- Send ------------------------------------------*/ static U8 Send (U8 outb) { /* Send and Receive a byte on SPI interface. */ SSPDR = outb; /* Wait if RNE cleared, Rx FIFO is empty. */ while (!(SSPSR & RNE)); return (SSPDR); } /*--------------------------- SendBuf ---------------------------------------*/ static BOOL SendBuf (U8 *buf, U32 sz) { /* Send buffer to SPI interface. */ U32 i; for (i = 0; i < sz; i++) { SSPDR = buf[i]; /* Wait if Tx FIFO is full. */ while (!(SSPSR & TNF)); SSPDR; } /* Wait until Tx finished, drain Rx FIFO. */ while (SSPSR & (BSY | RNE)) { SSPDR; } return (__TRUE); } /*--------------------------- RecBuf ----------------------------------------*/ static BOOL RecBuf (U8 *buf, U32 sz) { /* Receive SPI data to buffer. */ U32 i; for (i = 0; i < sz; i++) { SSPDR = 0xFF; /* Wait while Rx FIFO is empty. */ while (!(SSPSR & RNE)); buf[i] = SSPDR; } return (__TRUE); } /*--------------------------- BusSpeed --------------------------------------*/ static BOOL BusSpeed (U32 kbaud) { /* Set an SPI clock to required baud rate. */ U32 div; div = (__PCLK/1000 + kbaud - 1) / kbaud; if (div == 0) div = 0x02; if (div & 1) div++; if (div > 0xFE) div = 0xFE; SSPCPSR = div; return (__TRUE); } /*--------------------------- SetSS -----------------------------------------*/ static BOOL SetSS (U32 ss) { /* Enable/Disable SPI Chip Select (drive it high or low). */ if (ss) { /* SSEL is GPIO, output set to high. */ IOSET0 = 1<<20; } else { /* SSEL is GPIO, output set to low. */ IOCLR0 = 1<<20; } return (__TRUE); } /*--------------------------- CheckMedia ------------------------------------*/ static U32 CheckMedia (void) { /* Read CardDetect and WriteProtect SD card socket pins. */ U32 stat = 0; #if 0 if (!(IOPIN0 & 0x04)) { /* Card is inserted (CD=0). */ stat |= M_INSERTED; } if ((IOPIN0 & 0x20)) { /* Write Protect switch is active (WP=1). */ stat |= M_PROTECTED; } #else /* When CD,WP signals are not connected. */ stat = M_INSERTED; #endif return (stat); } static BOOL SetSS1 (U32 ss) { /* Enable/Disable SPI Chip Select (drive it high or low). */ if (ss) { /* SSEL is GPIO, output set to high. */ IOSET0 = 1<<7; } else { /* SSEL is GPIO, output set to low. */ IOCLR0 = 1<<7; } return (__TRUE); } /*--------------------------- Init ------------------------------------------*/ static BOOL Init1 (void) { /* Initialize and enable the SSP Interface module. */ /* SSEL is GPIO, output set to high. */ IODIR0 |= 1<<7; IOSET0 = 1<<7; /* SCK1, MISO1, MOSI1 are SSP pins. */ PINSEL1 = (PINSEL1 & ~0x00000FC) | 0x000000A8; // reset SPI SSPCR1 = 0x0000; SSPCR0 = 0x0000; SSPCPSR = 0x00; /* Enable SPI in Master Mode, CPOL=0, CPHA=0. */ SSPCR0 = 0x0007; SSPCR1 = 0x0002; SSPCPSR = 0xFE; return (__TRUE); } /*--------------------------- UnInit ----------------------------------------*/ static BOOL UnInit1 (void) { /* Return SSP interface to default state. */ IODIR0 &= ~(1<<8); PINSEL1 &= ~0x00000FC; SSPCR1 = 0x0000; SSPCR0 = 0x0000; SSPCPSR = 0x00; return (__TRUE); }
What do you mean by "here are two pullups in a MOSI and MISO pins"
Each signal only needs one pullup resistor even if you connect the signal to two memory cards.
Don't you see any issues with having two drivers perform operations on the same registers?
What if the two memory card "drivers" gets called with different baudrate?
And next thing - have you verified if the file system code initializes an interface before every use and then uninitializes it? Or if it initializes both interfaces and then leaves them initialized?
Now i'm able access two drives in same bus i done a small mistake in my spi1_drv uninit function, you can see it on my above posted code
THANK U ALL for kind advice and guidance
You really should consider initializing the slave-select lines totally outside of your file system code. However many init/uninit you do, the slave-select for each memory card should be in "idle" state at all times when you aren't doing any transfers. So you should deassert them on boot. And they should stay that way after any uninit() calls.