View previous topic :: View next topic |
Author |
Message |
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue May 14, 2013 12:50 am |
|
|
Helping you is difficult for several reasons:
- Your dsPIC33 processor is from a family that only a few people on this forum are using. Heck, most of us don't even have the required PCD compiler, including me.
- Your 4.093 compiler version is old, we are now at v4.141. These 48 releases fixed many problems. Perhaps your compiler is not too old, but v4.104 and 105 did fix some #SPI problems in the PCD compiler and many other PCD related problems have been fixed.
- You didn't post a hardware schematic
- The link to the SD card module does not provide a hardware schematic, this worries me as there are 4 resistors, 4 capacitors and one unknown active component. The 5V connection makes me very suspicious.
So here are a few questions for you:
1) You didn't answer Andrew's question and I would like to know the answer too: did your call to mmcsd_init() return MMCSD_GOODEC?
2) Why do you want to use a dsPIC33? It's a great processor but more difficult to handle than a PIC18 and on this forum there are way less people who can help you.
3) Is your RS232 communication now working stable and without bad characters? Bad characters are an indication of timing problems that will bite you in the other parts of your project.
4) You had to add a resistor to the crystal to make it work? This is not common practice. Again, I'd like to see a schematic if possible.
5) Please post your complete test program, not only the few lines you posted until now. Include the #fuses lines, etc. but do not post the CCS supplied header files. |
|
|
Jim90
Joined: 27 Apr 2013 Posts: 55
|
SD card memory problem |
Posted: Thu May 16, 2013 8:55 pm |
|
|
1)I checked again and, no when i run the code :
Code: |
if (mmcsd_init() == MMCSD_GOODEC)
{
printf(" initialised successfully, proceed");
}
else
{
printf("didn't initialise, do something else");
}
|
I receive the message didn't initialise, do something else
2)I would like to learn this microcontroller's series.
3)Firstly i tried the internal oscillator (There was an example in the forum)and this was created problems, so i moved to the external oscillator which is working fine.
4)I didn't know too , but i read it to the datasheet.
5)This is the code which i used. (I followed an example from the forum, so i believe that The fuses,... are ok):
Code: |
#include <33fj128GP202.h>
#include <stdlib.h>
#fuses HS, NOWDT, PR, NOPUT,NOPROTECT
#use delay (clock=20M)
#PIN_SELECT U1TX=PIN_B13
#PIN_SELECT U1RX=PIN_B12
#USE RS232(UART1,ERRORS,BAUD=9600)
#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 "C:\Users\Desktop\SD_CARD\fat.c"
void main(void)
{
BYTE value, cmd;
int32 address;
int i;
uint8_t buf[512];
MMCSD_err err;
if (mmcsd_init() == MMCSD_GOODEC)
{
printf(" initialised successfully, proceed");
}
else
{
printf("didn't initialise, do something else");
}
printf("\n");
mmcsd_read_byte(10, 10);
if (mmcsd_read_byte(10, 10) == MMCSD_GOODEC)
{
printf(" read_bytesuccessfully, proceed");
}
else
{
printf("didn't read_byte");
}
printf("\n");
.....
}
|
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri May 17, 2013 11:57 am |
|
|
Quote: | I receive the message didn't initialise, do something else | This doesn't make you happy, but to me now things are starting to make sense again: you have a hardware problem with connecting the SD card.
With a hardware problem present there is no way you will be able to fix the problem in software.
I did a little investigation in the Arduino hardware extension boards and it turns out the Arduino is running 5V. The SD card and your dsPIC are running 3.3V. Now, what I expect is that the extra components you have on your SD card PCB are for the 5V to 3.3V conversion and the other way around. This is making things worse for you. In fact, the board is useless and you'll have to make some serious modifications to make it suitable for your project.
You can try to connect your board supplier and ask for the schematic. Most likely it will involve removing all components from the PCB except the two connectors. Ensure there is at least a pull up resistor (100k) on the MISO line, perhaps on on the clock and CS line as well.
Better, get yourself another interface board.
The schematic should be similar to:
Note that this schematic only has pull-up resistors, not resistor voltage-dividers as you board most likely has for 5V to 3.3V conversion. |
|
|
Jim90
Joined: 27 Apr 2013 Posts: 55
|
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Fri May 17, 2013 9:13 pm |
|
|
No. What you're describing as "pull-up resistors" are actually divider resistors, designed to interface a 5V micro (Arduino) with the 3.3V SD card.
To connect your dsPIC33FJ128GP202 to an SD card you don't need divider resistors, you need pull-ups to 3.3V as shown on ckielstra's circuit diagram (the open triangle at the top represents the 3.3V SD/microcontroller power supply). _________________ Andrew |
|
|
Jim90
Joined: 27 Apr 2013 Posts: 55
|
SD card memory problem |
Posted: Sat May 18, 2013 5:57 am |
|
|
Yes but 50K resistor is not very high ? (i expecting a value of 1-2 K) |
|
|
andrewg
Joined: 17 Aug 2005 Posts: 316 Location: Perth, Western Australia
|
|
Posted: Sat May 18, 2013 6:33 am |
|
|
The idea with pullups is that they are generally intended to put a signal line into a default state when it isn't being driven. A higher resistor value means that when the line *is* driven, it doesn't need a lot of current to get it to change state. Typical pull-up values will be 10K to 100K, although there are exceptions. _________________ Andrew |
|
|
Jim90
Joined: 27 Apr 2013 Posts: 55
|
SD card memory problem |
Posted: Tue May 21, 2013 5:06 pm |
|
|
I tried 50K without results.
Any ideas ? |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Wed May 22, 2013 1:27 am |
|
|
Please be more descriptive about your current hardware setup. If possible post a schematic of the connections between the PIC and SD card, otherwise describe each line in a few words like:
- Pin xx of PIC goes to Pin yy of SD, pull up resistor 50K to 3.3V
- etc. |
|
|
Jim90
Joined: 27 Apr 2013 Posts: 55
|
SD card memory problem |
Posted: Sun May 26, 2013 7:26 pm |
|
|
The connections are :
SD card --- dspic
MMC_CS -->PIN_B6
MMC_CLK -->PIN_B10
MMC_DO -->PIN_B11
MMC_DI -->PIN_B7
For each one of the PIN is connect a pull up resistor (50K)
PIN_B6 --> 50K-->3.3V
PIN_B10 --> 50K-->3.3V
PIN_B11 --> 50K-->3.3V
PIN_B7 --> 50K-->3.3V
I did these changes to the code:
Code: |
#define MMC_CS PIN_B6
#define MMC_CLK PIN_B10
#define MMC_DO PIN_B11
#define MMC_DI PIN_B6
|
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon May 27, 2013 1:32 am |
|
|
Code: | #define MMC_CS PIN_B6
#define MMC_CLK PIN_B10
#define MMC_DO PIN_B11
#define MMC_DI PIN_B6 | PIN_B6 is used two times!!!
You didn't mention the pin number on the SD card connector but it looks like your data connection is 'straight' where it should have been 'crossed': Data IN of SD goes to Data OUT of PIC and vice versa.
So check:
The Data In pin of the SD card (pin 2) should be connected to the Data Out of your PIC (B11)
The Data Out pin of the SD card (pin 7) should be connected to the Data In of your PIC (B7)
I don't have the compiler for the PIC33 series, but most likely you will have to add the code for the remap-able pins just under your pin defines: Code: | #PIN_SELECT SCK1=PIN_B10
#PIN_SELECT SDO1=PIN_B11
#PIN_SELECT SDI1=PIN_B7 | PIN_B6, your CS output, is not in this list as it shouldn't use the CS output from the SPI hardware unit. This pin is to be mapped as a general output port |
|
|
|