View previous topic :: View next topic |
Author |
Message |
adalucio
Joined: 16 Mar 2009 Posts: 29
|
pic18f45k22 and MMC SD |
Posted: Fri Apr 22, 2011 2:54 am |
|
|
Hi all.
I want to test reading/writing on a SD Card (tried 16MB and 1GB) with a pic18f45k22 running at 3,3v. I'm using pulldown and pullup resistors (http://2.bp.blogspot.com/_meF1KpGU79k/S_csFZP7s6I/AAAAAAAAAUM/0mM7eLn7uWg/s1600/PIC18F2550+WAV+Player.jpg).
The pic stop working on write command.
This is my code
Code: |
#include <main.h>
#use fast_io(D)
#define MMCSD_PIN_SCL PIN_D0 //o
#define MMCSD_PIN_SDI PIN_D4 //i
#define MMCSD_PIN_SDO PIN_D1 //o
#define MMCSD_PIN_SELECT PIN_D6 //o
#include <mmcsd.c>
#define LED1 PIN_A0
#define LED2 PIN_A1
#define DELAY 500
void main()
{
BYTE value = 0x01010101;
BYTE valuer;
int32 address = 0x00000000;
setup_timer_4(T4_DISABLED,0,1);
if(mmcsd_init())
{
while(true)
{
output_high(LED1);
delay_ms(DELAY);
output_low(LED1);
delay_ms(DELAY);
}
}
output_high(LED1);
delay_ms(DELAY);
output_low(LED1);
// Scrivo un dato
mmcsd_write_byte(address, value);
mmcsd_flush_buffer();
output_high(LED1);
delay_ms(DELAY);
output_low(LED1);
// leggo il dato scritto
mmcsd_read_byte(address, &valuer);
output_high(LED1);
delay_ms(DELAY);
output_low(LED1);
if(value != valuer)
{
while(true)
{
output_high(LED2);
delay_ms(DELAY);
output_low(LED2);
delay_ms(DELAY);
}
}
output_high(LED1);
output_high(LED2);
while(true);
}
|
Thanks |
|
 |
collink
Joined: 08 Jan 2010 Posts: 137 Location: Michigan
|
|
Posted: Fri Apr 22, 2011 5:29 am |
|
|
It seems like some of your pins are configured oddly. SDI should be PIN_D1 and SDO should be PIN_D4 not the other way around like you have it. The usual hardware select pin for SPI2 is PIN_D3 but I suppose you are allowed to use anything you want. Just make sure you actually have your select line run to PIN_D6 like you claim.
Also, does the mmcsd_init() function set up the SPI parameters? Because you otherwise don't seem to be doing that. |
|
 |
adalucio
Joined: 16 Mar 2009 Posts: 29
|
|
Posted: Fri Apr 22, 2011 5:57 am |
|
|
THANKS!!!!
the problem was PIN_D1 and PIN_D4. |
|
 |
|