|
|
View previous topic :: View next topic |
Author |
Message |
deltatech
Joined: 22 Apr 2006 Posts: 87
|
MMC CARD PIN OUT HELP |
Posted: Wed May 31, 2006 11:01 am |
|
|
HI I am Using CCS Ethernet Prototyping board with a MMC Card Reader.
On the Board the Pins are connected as follows
Din----C5
CS-----D3
CLK----C3
Dout---C4
I am using this code from the CCS Forum post
http://www.ccsinfo.com/forum/viewtopic.php?t=23183&start=15
it says
[b]
#byte PORTC = 7
#bit CS = PORTC.2
set_tris_c(0b11010011); // sck rc3-0, sdo rc5-0, CS rc2-0.
set_tris_b(0b00000010);[/b]
In all the code PortB is not used , why is it defined here . ?
My Question is will this code work with the CCS Board if yes what do i need to do to make it work .
Many thanks for your help
Code: | #include <16F877.H>
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#use fast_io(C)
#byte SSPBUF = 0x13
#byte SSPCON = 0x14
#byte SSPSTAT = 0x94
#bit BF = SSPSTAT.0
#bit SMP = SSPSTAT.7
#bit CKE = SSPSTAT.6
#bit CKP = SSPCON.4
#bit SSPM1 = SSPCON.1
#bit SSPEN = SSPCON.5
#byte PORTC = 7
#bit CS = PORTC.2
//****************************************
// This is the same as the CCS spi_read() function.
char SPI(char d)
{
SSPBUF=d;
while (!BF);
return SSPBUF;
}
//******************************************
char Command(char befF, int16 AdrH, int16 AdrL, char befH)
{
SPI(0xFF);
SPI(befF);
SPI(AdrH >> 8);
SPI(AdrH);
SPI(AdrL >> 8);
SPI(AdrL);
SPI(befH);
SPI(0xFF);
return SPI(0xFF); // Return with the response
}
//********************************************
char MMC_Init()
{
char i;
// Init SPI
SMP=0;
CKE=0;
CKP=1;
SSPM1=1;
//SSPM0=1;
SSPEN=1;
CS=1; // MMC-Disabled
// MMC in SPI Mode -- start and Reset.
for(i=0; i < 10; i++) SPI(0xFF); // 10*8=80 clocks
CS=0; // MMC-Enabled
// CMD0
if (Command(0x40,0,0,0x95) !=1) goto Error; // Reset
st:
// CMD1
if (Command(0x41,0,0,0xFF) !=0) goto st ; // CMD1
return 1;
Error:
return 0;
}
//*********************************************
void main(void)
{
int16 i;
setup_port_a(NO_ANALOGS);
set_tris_c(0b11010011); // sck rc3-0, sdo rc5-0, CS rc2-0.
set_tris_b(0b00000010);
puts("Start\n\r");
if(MMC_Init())
puts("MMC ON\n\r"); // MMC Init OK
//*****************************************
// Write in 512 Byte-Mode
if (Command(0x58,0,512,0xFF) !=0) puts("Write error ");
SPI(0xFF);
SPI(0xFF);
SPI(0xFE);
SPI("Begin\n\r"); // 7 characters
for(i=0; i < 500; i++) // Was 512, but used 12 for text
{
SPI('M');
}
SPI("\n\rEnd"); // 5 characters
SPI(255); // Send two bytes of 0xFF at the end
SPI(255);
i=SPI(0xFF);
i &=0b00011111;
if (i != 0b00000101) puts("Write Error ");
while(SPI(0xFF) !=0xFF); // Wait for end of Busy condition
//*************************************
// Read in 512 Byte-Mode
if (Command(0x51,0,512,0xFF) !=0) puts("Read Error ");
while(SPI(0xFF) != 0xFE);
for(i=0; i < 512; i++)
{
putc(SPI(0xFF)); // Send data
}
SPI(0xFF); // Send two bytes of 0xFF at the end
SPI(0xFF);
//**********************************************
while(1); // The program stops here.
}
|
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed May 31, 2006 1:11 pm |
|
|
Quote: | In all the code PortB is not used , why is it defined here . ? | The original code has little more comment than the translated version Code: | TRISB=0b.0000.0010; // RB2>TX, RB1>RX | It seems like the original poster intended to use RB1 and RB2 for serial data communications but then switched to using the internal hardware UART on pin C6 and C7 and forgot to delete this line.
You will need to change the register addresses to reflect your processor. The ethernet prototyping board has a PIC18F4520 processor, right? Then there is a thread using the same code for a PIC18F4550 which has similar addressing: http://www.ccsinfo.com/forum/viewtopic.php?p=53447.
Don't forget to also change the mapping of the CS line to reflect your circuit.
Other possible drivers you can use are:
- The CCS supplied driver mmc_spi.c in the drivers directory of your compiler.
- A FAT16 file system in the Code Library: http://www.ccsinfo.com/forum/viewtopic.php?t=21721 |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|