|
|
View previous topic :: View next topic |
Author |
Message |
Jim90
Joined: 27 Apr 2013 Posts: 55
|
SD card memory problem |
Posted: Sat Apr 27, 2013 9:14 pm |
|
|
I am trying to write values in an external sd card memory using the dspic33fj128gp202 microcontroller.
The code which i used (following examples) is presented below :
Code: |
#include <stdlib.h>
//meda library, a compatable media library is required for FAT.
#use fast_io(A)
#use fast_io(B)
#define MMC_CLK PIN_A3
#define MMC_DI PIN_B4
#define MMC_DO PIN_A2
#define MMC_CS PIN_A4
#include "C:\Users\Desktop\SD_CARD\mmcsd.c"
#include <input.c>
int main()
{
BYTE value, cmd;
int32 address;
int i;
printf("\r\n\nex_mmcsd.c\r\n\n");
if (mmcsd_init())
{
printf("Could not init the MMC/SD!!!!");
while(TRUE);
}
for(i=100;i<110;i++)
{
printf("\n\rLocation: ");
address = (i<<8);
printf("number i :%d\n",i);
printf("ADDRESS INSERT :%d\n",address);
printf("\r\nNew value: ");
// value = read_adc();
//printf("value :%d\n\r",value);
printf("\n\r");
mmcsd_write_byte(address,i);
mmcsd_flush_buffer();
}
return 0;
}
|
I used mmsd library with the following changes:
Code: |
#ifndef MMCSD_PIN_SCL
#define MMCSD_PIN_SCL PIN_A3 //o
#define MMCSD_PIN_SDI PIN_B4 //i
#define MMCSD_PIN_SDO PIN_A2 //o
#define MMCSD_PIN_SELECT PIN_A4 //o
#endif
//#if USE_SW_ONLY
/* For software spi */
#use spi(MASTER,CLK=MMCSD_PIN_SCL, DO=MMCSD_PIN_SDO, DI=MMCSD_PIN_SDI, BITS=8, MODE=3, MSB_FIRST, stream=mmcsd_spi, FORCE_SW)
//#else
/* For hardware spi */
//#use spi(MASTER,CLK=MMCSD_PIN_SCL, DO=MMCSD_PIN_SDO, DI=MMCSD_PIN_SDI, BITS=8, MODE=3, stream=mmcsd_spi, FORCE_HW)
//#use spi(MASTER,CLK=MMCSD_PIN_SCL, DO=MMCSD_PIN_SDO, DI=MMCSD_PIN_SDI, BITS=8, MODE=3, stream=mmcsd_spi)
//#endif
|
My problem is that when i run the code the loop instead to run for 10 times (from 100 to 110) is run only for 2 times and then stop.
From what i saw in the forum the mmsd library is provided with bugs
http://www.ccsinfo.com/forum/viewtopic.php?t=43764&highlight=mmcsd
but i don't know if this is create the problem or something else.
I don't understand what is going wrong so i need help to solve this problem.
The result when i run the code is presented below:
5))
Location: number i :100
C!‘}¡¡ ADDRESS INSERT :786432
5))
Location: number i :100
C!‘}¡¡ ADDRESS INSERT :786432
New value:
Location: number i :101
ADDRESS INSERT :786432
New value5))
Location: number i :100
}¡¡ ADDRESS INSERT :786432
New value:
Location: number i :101
ADDRESS INSERT :786432
New value5))
Location: number i :100
}¡¡ ADDRESS INSERT :786432
New value:
Location: number i :101
ADDRESS INSERT :786432
New value: |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Sun Apr 28, 2013 6:18 am |
|
|
I don't see an obvious error, but it is strange to see the garbage output on the newline characters.
Please post a complete program, now the processor include and #fuses lines are missing.
ALWAYS post your compiler version number (4.xxx) as the early v4 versions are known to have problems. |
|
|
Jim90
Joined: 27 Apr 2013 Posts: 55
|
SD card memory problem |
Posted: Sun Apr 28, 2013 9:37 am |
|
|
The compiler version is V4.093.
The remain code which i used is presented below.
Code: |
#FUSES NOPROTECT
#FUSES NOIESO
#FUSES FRC
#FUSES NOWDT
#use delay(clock=7.37MHz)
#PIN_SELECT U1TX=PIN_B14
#PIN_SELECT U1RX=PIN_B15
#USE RS232(UART1,ERRORS,BAUD=9600)
|
According what i read at the forum, i think the problem coming from the mmsd.c library which have bugs.
I don't understand what is going wrong there, that's why i can't fix it. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Sun Apr 28, 2013 10:47 am |
|
|
The MMC library is pretty OK. However yours is a very old compiler, and there may have been problems back then. The problems are with the fat handling, and in particular when using partitions with relative addressing.
First thing to check (critical), is that you have got a SD card _not_ and SDHC card. The latter won't work. The internal address handling is different.
Best Wishes |
|
|
Jim90
Joined: 27 Apr 2013 Posts: 55
|
SD card memory problem |
Posted: Sun Apr 28, 2013 7:02 pm |
|
|
I bought an SD/SDHC card (2GB) from an ebay seller (I used also an sd card module).
I checked it with my laptop (I think it is able to read only SD card).
Can i use it or i will have problems? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Sun Apr 28, 2013 8:22 pm |
|
|
SD or SDHC they are NOT the same...has to be one or the other.
Perhaps you can examine it to find out? Hopefully you have some kind of program that will read the card and tell you what it is(mfr/make/size/format/etc). I can't offer anymore, as I only use flashdrives.
hth
jay |
|
|
Jim90
Joined: 27 Apr 2013 Posts: 55
|
SD card memory problem |
Posted: Mon Apr 29, 2013 1:24 am |
|
|
temtronic because of the size (2GB) the card is for sure SD.
Do you mean that the MMC library is ok to newer version of compiler (and the example in older version is buggy ?)
If yes can you provide me the bug free example?
If you mean that the compiler has bug for this application then is anything which can i do to fix it?
I though that it was very popular to use SD card so there will be a lot of resources and a lot of people who the use them !!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Mon Apr 29, 2013 4:23 am |
|
|
Not true I'm afraid.
Quote from Wiki on this one:
"By the time the Version 2.0 (SDHC) specification was completed in June 2006,[68] vendors had already devised 2 GB and 4 GB SD cards, either as specified in Version 1.01, or by creatively reading Version 1.00. The resulting cards do not work correctly in some host devices."
Unfortunately these 2GB cards in particular can be a real pain, since they work in some devices, and not others. I've seen a few of these, particularly from ebay suppliers. Even more annoyingly they carry no marks to give a hint that there is anything special.
Best Wishes |
|
|
Jim90
Joined: 27 Apr 2013 Posts: 55
|
SD card memory problem |
Posted: Wed May 01, 2013 5:03 pm |
|
|
I speak with the seller and he confirm me that the card is SD type.
Now, is anyone who can give any suggestions what to do ???? |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9221 Location: Greensville,Ontario
|
|
Posted: Wed May 01, 2013 5:44 pm |
|
|
hmm... of course the vendor will say that ! What you need is some kind of 'SD card reader' program similar to USBVIEW for USB devices, that will show you the internal details of the card. Details like mfr/make/format/size of device/etc. should be displayed on a screen.
Perhaps someone here who uses that type of card can offer a suggestion. I don't use them, preferring to use USB flash drives. Maybe looking at the drive through Windows, hard drive, properties might say something ?
hth
jay |
|
|
Jim90
Joined: 27 Apr 2013 Posts: 55
|
SD card memory problem |
Posted: Thu May 02, 2013 1:14 am |
|
|
I checked it and it is SD card for sure.
I hope someone would be able to help me in this issue. |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Thu May 02, 2013 8:59 am |
|
|
I've only ever used the MMC/SD libraries for reading, not writing. I used v4.095 and reading was fine, so I think v4.093 would be OK. v4.0 was getting fairly stable just before they got to v4.100.
What is in "input.c"? Any interrupts?
I'd recommend checking the return values from the MMC routines. Bail out and display the error code if anything other than MMCSD_GOODEC is returned. That might give some clues... _________________ Andrew |
|
|
Jim90
Joined: 27 Apr 2013 Posts: 55
|
SD card memory problem |
Posted: Thu May 02, 2013 7:06 pm |
|
|
andrewg , i will start it again from the beginning and i will need your help.
first of all when you used the mmsd what was the frequency which you used ??
I modified the code and after each adding i use mmcsd_print_csd(); to Displays all data in the Card Specific Data (print everything results to zero)
Code: |
for(i=100;i<110;i++)
{
address = (i<<8)+i;
printf("\r\nNew value: ");
printf("i:%d",i);
mmcsd_write_byte(address, i);
mmcsd_flush_buffer();
mmcsd_print_csd(); |
Have you got any suggestions what to do ?
You said to "checking the return values from the MMC routines" can you give me any example what to do ? |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Sat May 04, 2013 7:43 am |
|
|
I've used SD cards with two projects, both read only, both running at 3.3V, so no level conversion between micro and card, and both using the hardware SPI support.
The first project was an 18LF4620/18LF4685 (needed more code space after a bit). It ran at 4MHz (so the SPI was 1MHz).
The second project was an 18LF4550 running at 8MHz (so the SPI was 2MHz).
If you have a look at the MMC/SD code, you'll see that practically all the functions have a return type of MMCSD_err, which is defined as: Code: | enum MMCSD_err
{MMCSD_GOODEC = 0,
MMCSD_IDLE = 0x01,
MMCSD_ERASE_RESET = 0x02,
MMCSD_ILLEGAL_CMD = 0x04,
MMCSD_CRC_ERR = 0x08,
MMCSD_ERASE_SEQ_ERR = 0x10,
MMCSD_ADDR_ERR = 0x20,
MMCSD_PARAM_ERR = 0x40,
RESP_TIMEOUT = 0x80}; | The idea is that you make sure the return code from every function is MMCSD_GOODEC (i.e. zero). This includes the call to mmcsd_print_csd(). eg: Code: | if (mmcsd_init() == MMCSD_GOODEC)
{
// initialised successfully, proceed...
}
else
{
// didn't initialise, do something else...
} | If you're not getting zero, then the returned code should be giving you a clue as to what the problem is. It may help to refer to the source code for details. _________________ Andrew |
|
|
Jim90
Joined: 27 Apr 2013 Posts: 55
|
SD card memory problem |
Posted: Sun May 05, 2013 10:09 am |
|
|
andrewg i tested all the functions which exist in the mmsd file.
All the functions are working fine except the following functions:
When i run the functions mmcsd_write_block,mmcsd_read_block the program stop (don't produce anything).
Code: |
mmcsd_write_block(1, 1, *10);
if (mmcsd_write_block(1, 1, *10) == MMCSD_GOODEC)
{
printf("mmcsd_write_block(1, 1, *10)) successfully, proceed");
}
else
{
printf("didn't mmcsd_write_block(1, 10, 10)");
}
printf("\n");
mmcsd_read_block(1, 10, 10);
if (mmcsd_read_block(1, 10, 10) == MMCSD_GOODEC)
{
printf("mmcsd_read_block(1, 10, 10)) successfully, proceed");
}
else
{
printf("didn't mmcsd_read_block(1, 10, 10)");
} |
The function mmcsd_read_ocr when i compile it i receive the message :
Function used but not defined: ... mmcsd_read_ocr SCR=4941
Code: |
printf("\n");
mmcsd_read_ocr(10);
if (mmcsd_read_ocr(10) == MMCSD_GOODEC)
{
printf("mmcsd_read_ocr()successfully, proceed");
}
else
{
printf("didn'tmmcsd_read_ocr()");
}
|
The functions mmcsd_crc7,mmcsd_crc16 according the message which is produced
is not return the MMCSD_GOODEC.
Code: |
printf("\n");
mmcsd_crc7(10,1);
if (mmcsd_crc7(10,1)== MMCSD_GOODEC)
{
printf("mmcsd_crc7() successfully, proceed");
}
else
{
printf("didn't mmcsd_crc7()");
}
printf("\n");
mmcsd_crc16(10,1);
if (mmcsd_crc16(10,1)== MMCSD_GOODEC)
{
printf("mmcsd_crc16() successfully, proceed");
}
else
{
printf("didn't mmcsd_crc16() didn't");
}
|
Is anyone who have any comment according these errors messages ? |
|
|
|
|
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
|