Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] pic 18f2550 , micro sd and MikroC

Status
Not open for further replies.

dxtr

Member level 3
Member level 3
Joined
Apr 27, 2012
Messages
66
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,699
Hey everyone
i know this question has been posted several times , i read all the other topics but i didn't get the right answer yet
well i want to interface my micro sd with pic 18f2550 , i format it with FAT 16 and i used the code in the mmc help section
here is my code :
Code:
// MMC module connections
sbit Mmc_Chip_Select           at LATC0_bit;  // for writing to output pin always use latch (PIC18 family)
sbit Mmc_Chip_Select_Direction at TRISC0_bit;
// eof MMC module connections

 int i;

void main() {
  ADCON1 |= 0x0F;                  // Configure AN pins as digital
  CMCON  |= 7;                     // Turn off comparators
  trisa = 0x00;

  // Initialize SPI1 module
  SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
    while (1)
    {
   i = Mmc_Fat_Init();
 switch (i)
   {
      case 0 : porta = 0b00000001; break;
      case 1 : porta = 0b00000010; break;
      case 255 : porta = 0b00000011; break;
      default: porta = 0xff; break;
      }
      delay_ms(50);
     }
}}
i even try with MMC_INIT() with no result
can u please guide me to the problem ?
 

hi, i think you haven't clearly stated what your exact problem is in your post, but i can't see anything wrong with your code. have you tried using a different sd card? we've tried interfacing an sd card to a pic18f4620 (using mikroc as well). at first we couldn't figure out what was wrong, the code was ok, it was only after trying a different sd card that we managed to make it work. (we actually used a microSD card attached to an adapter)
 

hi, i think you haven't clearly stated what your exact problem is in your post
yes sorry , well Mmc_Fat_Init() return 0 if card is detected , 1 if fat 16 boot not found and 255 if card is not found
i always get 255
why it can't find the card ?
 

also using isis , it doesn't work
 

Are you testing your design only using Proteus or both hardware and simulation?

Have you level shifted the MMC/SD I/O to the appropriate 3.3v level, the interface is not 5v tolerate.

Also note according to the MikroC documentation:

unsigned char Mmc_Init();

Initializes hardware SPI communication; The function returns 1 if MMC card is
present and successfuly initialized, otherwise returns 0.
Mmc_Init needs to be called before using other functions of this library.

Also, while never sufficiently discussed in the documentation many of the FAT routines require the following resources:

Code:
// Variables for MMC routines
unsigned char SectorData[512]; // Buffer for MMC sector reading/writing
unsigned char data_for_registers[16];// buffer for CID and CSD registers


Although, I never personally use MikroC libraries nor the MikroC compiler for that matter, if you upload your simulation file one of us could certainly take a look.


BigDog
 

Although, I never personally use MikroC libraries nor the MikroC compiler for that matter, if you upload your simulation file one of us could certainly take a look.
BigDog

thank you bigdog for your reply , here is my simulation with code in MikroC
 

Attachments

  • microsd.zip
    221.8 KB · Views: 139

The main issue appears to be, as ramoneb pointed out in his thread, the MISO and MOSI lines of the MMC are incorrectly switched.

The clue is the logic contention (yellow indicator) on the MMC DO pin.

dxtrMMC-logiccontention.jpg

Once the lines are switch, your code yields the expected results, no led lit indicating the card has been successfully detected.

unsigned char Mmc_Init();
0 - if MMC/SD card was detected and successfully initialized
1 - otherwise

dxtrMMC-SPIswitched.jpg


The labeling on the MMC is obviously in reference to the Master device rather than the Slave device.

MISO - SDO - (M)DI

MOSI - SDI - (M)DO

BigDog
 

The main issue appears to be, as ramoneb pointed out in his thread, the MISO and MOSI lines of the MMC are incorrectly switched.

The clue is the logic contention (yellow indicator) on the MMC DO pin.

View attachment 81542

Once the lines are switch, your code yields the expected results, no led lit indicating the card has been successfully detected.



View attachment 81543


The labeling on the MMC is obviously in reference to the Master device rather than the Slave device.



BigDog

problem solved
thank you so much :)
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top