View previous topic :: View next topic |
Author |
Message |
skelzer
Joined: 21 Apr 2016 Posts: 20 Location: Spain
|
|
|
skelzer
Joined: 21 Apr 2016 Posts: 20 Location: Spain
|
|
Posted: Wed May 11, 2016 2:20 am |
|
|
Just using mmcsd.h and trying to do a mmcsd_init() will keep on giving me timeout. I'm totally clueless right now, any ideas?
I've got the lines pulled up, I'm using a 3v uC and I'm still getting nothing. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Wed May 11, 2016 2:33 am |
|
|
I have _never_ used 'fixed_io'. Worst of all the PIC I/O modes.
As it currently stands, with fixed io, you keep the speed disadvantage of standard I/O, but you prevent routines like the SPI functions, from themselves controlling the I/O. Any changes made in routines are overridden on the next I/O operation. With fixed_io, you are going to have to ensure you set everything correctly for every single I/O operation.....
Worse, the setting you are using is wrong, based on what you have earlier posted:
#define MMCSD_PIN_SCL PIN_B10 //o
#define MMCSD_PIN_SDI PIN_B11 //i
#define MMCSD_PIN_SDO PIN_B12 //o
#define MMCSD_PIN_SELECT PIN_B13 //o
So you need B10, 12 & 13 set as output, but you are only setting 10 as output, then you are setting pin 11 as output, when it needs to be an input....
If you want to control I/O, use 'fast_io', and add a line near the start of the code to set the tris to:
0b0100101111111011
This then still leaves the TRIS able to change if other functions want to control the I/O. |
|
|
skelzer
Joined: 21 Apr 2016 Posts: 20 Location: Spain
|
|
Posted: Wed May 11, 2016 2:59 am |
|
|
Sorry, I made some undocumented changes, this is my new code:
Code: | #include <main.h>
#define MMCSD_PIN_SCL PIN_B11 //o
#define MMCSD_PIN_SDI PIN_B13 //i
#define MMCSD_PIN_SDO PIN_B10 //o
#define MMCSD_PIN_SELECT PIN_B15 //o
#include <mmcsd.h>
void main()
{
signed int nRet=44;
set_tris_b( 0b0111001110111011);
output_high(PIN_B6);
nRet=mmcsd_init();
printf("-> mmcsd init returned ( %X )\n\r",nRet);
output_low(PIN_B6);
while(TRUE)
{
}
} |
Code: | #include <33EP512GP504.h>
#FUSES NOWDT //No Watch Dog Timer
#FUSES NOJTAG //JTAG disabled
#FUSES CKSFSM //Clock Switching is enabled, fail Safe clock monitor is enabled
#device PASS_STRINGS=IN_RAM
#device ICSP=1
#use delay(internal=20MHz)
#USE FAST_IO (B)
#use rs232(xmit=PIN_B2, rcv=PIN_B3, baud=115200, stream=RS232_PORT1)
|
This is still giving me timeout. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Wed May 11, 2016 3:12 am |
|
|
Do you have the required resistors on the SD connections?.
Ideally 10K pull-ups on SCK, SDO, SDI, and SDCS.
The SCK one is only to speed the rising edges (you can get away without this), The SDI one is required to stop the PIC input floating when no card is present. SDO requires a pull-up, & CS is really also needed. On the data line, the SD physical specification say 'All hosts shall provide pull-up resistors'. Note 'shall'. |
|
|
skelzer
Joined: 21 Apr 2016 Posts: 20 Location: Spain
|
|
Posted: Wed May 11, 2016 3:49 am |
|
|
Ttelmah wrote: | Do you have the required resistors on the SD connections?.
Ideally 10K pull-ups on SCK, SDO, SDI, and SDCS.
The SCK one is only to speed the rising edges (you can get away without this), The SDI one is required to stop the PIC input floating when no card is present. SDO requires a pull-up, & CS is really also needed. On the data line, the SD physical specification say 'All hosts shall provide pull-up resistors'. Note 'shall'. |
Yes, I do, I've pulled up the four signals. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Wed May 11, 2016 3:51 am |
|
|
OK. It was just that it could wake up in the wrong mode otherwise....
I really think you need to triple check the connections. |
|
|
skelzer
Joined: 21 Apr 2016 Posts: 20 Location: Spain
|
|
Posted: Wed May 11, 2016 4:17 am |
|
|
Ttelmah wrote: | OK. It was just that it could wake up in the wrong mode otherwise....
I really think you need to triple check the connections. |
Working now, just did :
Code: | while(nRet!=0){
nRet=mmcsd_init();}
printf("-> mmcsd init returned ( %X )\n\r",nRet); |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Wed May 11, 2016 1:23 pm |
|
|
Suggests you are trying to talk to the card too quickly at boot. There is an initialisation time specified in the SD documents, that they require before they can start. The demo code does a print before it starts trying to talk to the SD. This gives about a 10mSec delay.
Just checked the SD documentation, and they are not guaranteed to give the correct response to any command for 10mSec after power on. |
|
|
skelzer
Joined: 21 Apr 2016 Posts: 20 Location: Spain
|
|
Posted: Thu May 12, 2016 3:46 am |
|
|
Ttelmah wrote: | Suggests you are trying to talk to the card too quickly at boot. There is an initialisation time specified in the SD documents, that they require before they can start. The demo code does a print before it starts trying to talk to the SD. This gives about a 10mSec delay.
Just checked the SD documentation, and they are not guaranteed to give the correct response to any command for 10mSec after power on. |
Understood, will try to fix that on monday when I'm back in the office, next time I'll check the documentation more carefully.
One more thing, I kept getting EOF when I was trying to use mk_file(), any hint? (I know I'm not posting any code right now, so it might be hard to know what's happening, but it was something like Code: |
char filename[]="\test.txt";
while(nRet!=0){
nRet=fat_init();printf("-> fat init returned ( %X )\n\r",nRet); }
nRet=44;
while(nRet!=0){
nRet=mk_file(filename);
printf("-> mkfile init returned ( %X )\n\r",nRet);} |
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19552
|
|
Posted: Thu May 12, 2016 8:12 am |
|
|
I think you need /file, not \file |
|
|
skelzer
Joined: 21 Apr 2016 Posts: 20 Location: Spain
|
|
Posted: Fri May 20, 2016 4:30 am |
|
|
Ttelmah wrote: | I think you need /file, not \file |
Thanks... |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Fri May 20, 2016 7:05 am |
|
|
Hi skelzer,
If your code is working now, you post a complete, working test program that incorporates all the suggestions/fixes offered in this thread. That way, users coming after you can benefit from this help in the same way that you did! _________________ John
If it's worth doing, it's worth doing in real hardware! |
|
|
|