CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Using fat.c
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
skelzer



Joined: 21 Apr 2016
Posts: 20
Location: Spain

View user's profile Send private message

PostPosted: Fri May 06, 2016 4:23 am     Reply with quote

Ok, here it is:

https://gyazo.com/8c1e46631b9c9a49c9f85b83907cbc52 (with #use FIXED_IO( B_outputs=PIN_B2, PIN_B10, PIN_B11, PIN_B15))

https://gyazo.com/ab4dcb38a8e5eefc1dc5187220525a2d (without it)


Signal nÂș1 makes more sense, but It keeps clocking indefinitely.
skelzer



Joined: 21 Apr 2016
Posts: 20
Location: Spain

View user's profile Send private message

PostPosted: Wed May 11, 2016 2:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed May 11, 2016 2:33 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed May 11, 2016 2:59 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed May 11, 2016 3:12 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed May 11, 2016 3:49 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed May 11, 2016 3:51 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed May 11, 2016 4:17 am     Reply with quote

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

View user's profile Send private message

PostPosted: Wed May 11, 2016 1:23 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Thu May 12, 2016 3:46 am     Reply with quote

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

View user's profile Send private message

PostPosted: Thu May 12, 2016 8:12 am     Reply with quote

I think you need /file, not \file
skelzer



Joined: 21 Apr 2016
Posts: 20
Location: Spain

View user's profile Send private message

PostPosted: Fri May 20, 2016 4:30 am     Reply with quote

Ttelmah wrote:
I think you need /file, not \file


Thanks... Embarassed
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri May 20, 2016 7:05 am     Reply with quote

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!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
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