|
|
View previous topic :: View next topic |
Author |
Message |
Rodrigo Rios A de Souza
Joined: 30 Apr 2010 Posts: 10
|
HELP !!!! Problem with ex_webserver2 and MMC/SD card Reader |
Posted: Mon Jun 14, 2010 12:25 pm |
|
|
It´s really serious, I have to finish this project for finishing my university!!!
I am really disappointed with the the tools. Nothing happens when I try to put
the website files inside the SD memory.
I am stuck for about 1 month in this step.
I recently brought a CCS Embedded Ethernet kit with a PIC18F4620.
I cannot interface the PIC and the SD.
I tested the configuration with four brands of SD.
Kingston 2GB
Sandisk 512MB
Canon 16MB
Corsair 512MB
The compiler comes with some examples :
ex_fat.c and ex_mmcsd.c
Don't matter how much times I test.
I checked the Pins, checked the signals, the voltage.
I can't make my SD Interface with PIC. Read and Write simple doesn't work seens to be working.
The ICD gives an error when I try do Write in the SD.
In ex_mmcsd.c I can´t get any information with the function :
The mmc_write_byte function locks every time is called...
I really don't know how to solve this problem.
Please Help,
Rodrigo Rios |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jun 14, 2010 4:59 pm |
|
|
To get things right: in this thread you have the webserver working from local Flash memory.
What isn't working is reading the data from the external SD card.
What is your compiler version number?
I don't have the kit so can't really help you, but if you search this forum you'll finds posts of several people having problems with the SD card driver.
http://www.ccsinfo.com/forum/viewtopic.php?t=37800
http://www.ccsinfo.com/forum/viewtopic.php?t=37821
http://www.ccsinfo.com/forum/viewtopic.php?p=128657
One problem is that the CCS supplied SD card drivers do have a bug in interpreting the boot sector, so if you take a card formatted in Windows it can not be read correctly by the CCS driver and vice versa.
Things to try are:
- Use the newer files from the CCS driver directory instead of the SD drivers supplied with the kit. Replace the file fat_pic.c is by fat.c. And fat_spi.c by mmc_spi.c
- In fat.c use #define FAT32 instead of FAT16 |
|
|
Rodrigo Rios A de Souza
Joined: 30 Apr 2010 Posts: 10
|
I did try a LOT of combinations |
Posted: Mon Jun 14, 2010 5:23 pm |
|
|
I still changed the files for the new ones.
But I'm not sure if i did this for mmc_spi.c. I will do it and will contact you.
I also went to the Code library and look for some other implementation of SPI and FAT.
I think the problem is related to SPI. Because there are a lot of VARS, in use SPI.
I also found use SPI a difficult to understand command. You have SAMPLE_RISE,SAMPLE_DOWN, IDLES=0,1,2,3 modes...
Too complicated.
I really need some help here.
Can you give a hand? I depend on this to finish my final project.
Best Regards,
Rodrigo Rios |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Jun 14, 2010 6:29 pm |
|
|
It's true that the SPI setup is confusing because Motorola defined the standard, then Microchip decided not to pay royalties and gave the same signals a different name. CCS are stupid and have chosen to do things in again another way.
Use the following defines to make life easier again, these are the original names used by Motorola: Code: | // SPI mode definitions.
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H) |
MMC and SD cards can be used in either SPI-mode 0 or 3.
Example: setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_4 );
.... and post your compiler version number! |
|
|
Rodrigo Rios A de Souza
Joined: 30 Apr 2010 Posts: 10
|
Compiler Number |
Posted: Mon Jun 14, 2010 7:50 pm |
|
|
Ok, it´s 4.068!!!
Thanks for everything. Where can I change the parameters in the code???
I changed the code as you said. Now my mmcsd.c contain this code :
Code: |
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
//#use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, IDLE=1, stream=mmcsd_spi)
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_4 );
|
But now the CCS compiler gives the following Error :
Code: |
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_4 );
|
Quote: |
Error : Expecting Identifier and Expecting a Declaration
|
best regards,
Rodrigo Rios |
|
|
Rodrigo Rios A de Souza
Joined: 30 Apr 2010 Posts: 10
|
ex_mmcsd.c |
Posted: Mon Jun 14, 2010 8:05 pm |
|
|
Hi again!
My project.. that dont work!
this is my PIC : PIC18F4620 http://www.ccsinfo.com/product_info.php?products_id=embethkit
ex_mmcdsd.c
Code: | #include <18f4620.h> // MODIFIED
#fuses HS,NOLVP,NOWDT,NOPROTECT // MODIFIED
#use delay(clock=40000000) // MODIFIED
#use rs232(DEBUGGER) // MODIFIED hardware UART uses RC6/TX and RC7/RX
#include <stdlib.h> // for atoi32
//media library, a compatable media library is required for FAT.
//#use fast_io(c)
#define MMCSD_PIN_SCL PIN_C3 //o MODIFIED THIS WAS A HUGE PROBLEM, C3 DIDN'T WORK
#define MMCSD_PIN_SDI PIN_C5 //i
#define MMCSD_PIN_SDO PIN_C4 //o
#define MMCSD_PIN_SELECT PIN_D3 //o
#include <mmcsd.c>
#include <input.c>
void main(void)
{
BYTE value, cmd;
int32 address;
printf("\r\n\nex_mmcsd.c\r\n\n");
printf("\r\n\n");
if (mmcsd_init())
{
printf("Could not init the MMC/SD!!!!");
while(TRUE);
}
mmcsd_print_cid(); // MODIFIED
do {
do {
.
.
.
} while (TRUE);
}
|
ex_mmcdsd.c
Code: |
/////////////////////////////////////////////////////////////////////////
//// MMCSD.c ////
//// User Config ////
//// ////
/////////////////////
#ifndef MMCSD_PIN_SCL
#define MMCSD_PIN_SCL PIN_C3 //o
#define MMCSD_PIN_SDI PIN_C5 //i
#define MMCSD_PIN_SDO PIN_C4 //o
#define MMCSD_PIN_SELECT PIN_D3 //o
#endif
// SPI mode definitions.
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
//#use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MSB_FIRST, IDLE=1, stream=mmcsd_spi)
setup_spi(SPI_MASTER | SPI_MODE_0 | SPI_CLK_DIV_4 );
////////////////////////
//// ////
//// Useful Defines ////
//// ////
////////////////////////
.
.
.
|
++++++++++++++++++++++
Most of ex_mmcsd.c and mmcsd.c removed.
Reason: Forum rule #10
10. Don't post the CCS example code or drivers.
http://www.ccsinfo.com/forum/viewtopic.php?t=26245
++++++++++++++++++++++
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Jun 15, 2010 3:57 am |
|
|
My mistake, setup_spi can not be used in mmcsd.c.
In the v4 compiler CCS has introduced the new and more flexible '#use spi' function but this can not be used together with the old setup_spi().
Change the setup in mmcsd.c to:
Code: | #use spi(MASTER, DI=MMCSD_PIN_SDI, DO=MMCSD_PIN_SDO, CLK=MMCSD_PIN_SCL, BITS=8, MODE=0, stream=mmcsd_spi) |
This is an old version and not a very good one. Current version is v4.108, 40 versions newer than yours. It took CCS a long time to make the V4 compiler stable, it was a mess for a long time and only around v4.070 the compiler became usable again. Some of your problems will come from this, for example the '#use spi' was known to be broken in the 4.07x versions. I don't know if this has been fixed in 4.108
Upgrade to a newer compiler version or try using one of the other FAT libraries that uses the stable 'setup_spi' instead of the '#use spi'. |
|
|
Rodrigo Rios A de Souza
Joined: 30 Apr 2010 Posts: 10
|
No Success Yet |
Posted: Tue Jun 15, 2010 9:48 am |
|
|
Hi, I found a very good example for Proteus.
I can read and write in the SD media.
It´s working normally. But when I put in the HEX files and change the parameters for my PIC18F4620 from the kit.
The MMC cannot initialize. I suspect that there is some problem in the pins voltage, or some kind for problem related to communication.
I will forget about the MMC card reader and do it by myself, use resistors and a protoboard. I will make my connection.
cheers,
Rodrigo Rios |
|
|
|
|
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
|