|
|
View previous topic :: View next topic |
Author |
Message |
Icarus
Joined: 02 May 2012 Posts: 16
|
MMC with 18F452 |
Posted: Wed May 02, 2012 6:18 pm |
|
|
Hey ! For a project I want to save ADC values in MMC card; am using 18F452. Does someone know how to send data to MMC and which driver I should use ? |
|
|
ünloco
Joined: 02 Oct 2011 Posts: 12 Location: Tunisia
|
|
Posted: Thu May 03, 2012 2:47 am |
|
|
hi
you should use "C:\Program Files\PICC\Drivers\mmcsd.c"
for the interface you can use resistors voltage divider because the mmc card does not support 5v but rather 3.3v.
OR
connect to the pic:
C2 -> CS (chip select)
C3 -> CLK
C4 <- DO
C5 -> DI
here's some code i'm working on
Code: |
#include <18F252.h>
#device adc=8, *=16
#FUSES NOWDT, WDT128, HS, NOPROTECT, NOOSCSEN, NOBROWNOUT, BORV20, NOPUT, STVREN, DEBUG, NOLVP, NOWRT, NOWRTD, NOWRTB, NOWRTC, NOCPD, NOCPB, NOEBTR, NOEBTRB
#use delay(clock=20000000)
#use rs232(baud=57600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)
#define BLOCK 128
#define p printf
#use fast_io(c)
#define MMCSD_PIN_SCL PIN_C3 //o
#define MMCSD_PIN_SDI PIN_C4 //i
#define MMCSD_PIN_SDO PIN_C5 //o
#define MMCSD_PIN_SELECT PIN_C2 //o
#include "mmcsd.c"
void main()
{
char buffer[512] = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901";
//char buffer[512] = "Test SD Card N° 1 !!";
//char buffer[512];
int init;
init = mmcsd_init();
p("init=%u\r\n", init);
//write block
init = mmcsd_write_data(512*0,512,buffer);
p("write=%u\r\n", init);
mmcsd_read_data(512*0,512,buffer);
p("%s\r",buffer);
mmcsd_read_data(512*1,512,buffer);
p("%s\r",buffer);
mmcsd_read_data(512*2,512,buffer);
p("%s\r",buffer);
p("\r---\r");
while(1);
}
|
_________________ for(;;);
Last edited by ünloco on Thu May 03, 2012 4:21 am; edited 1 time in total |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Thu May 03, 2012 3:44 am |
|
|
Unfortunately, the use of resistors for the 5->3.3v, may well be OK, but going the other way, you _must_ have a buffer chip. This is the big problem that people have trying to control these chips off a 5v PIC.
Problem is that if you use the PIC's hardware SPI, it only sees a signal as 'high', when it gets to 0.7* the chip's supply voltage. So the input signal needs to get up to 3.5v, when trying to input to a 5v PIC. The MMC card _will not do this_.
This is one of the commonest mistakes made trying to drive these chips, with people pulling circuits from the web, showing the card directly connected to a processor, and then perpetually having problems with it not working.
Choices:
1) Best - switch to a 3.3v PIC, and run the whole circuit on 3.3v. You need this anyway as the supply voltage for the card....
2) Add a buffer. A simple logic gate accepting 2.4v as a 'high', solves the problem. The second circuit shown by the poster above does this, and should work.
Best Wishes |
|
|
Icarus
Joined: 02 May 2012 Posts: 16
|
|
Posted: Thu May 03, 2012 7:11 am |
|
|
Thanks ünloco, but I can't find the MMCSD in the PICC drivers. Do you know from where I can download it ? |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Thu May 03, 2012 7:38 am |
|
|
If you don't have the file you need to update your compiler.
It's a copyright violation to ask for CCS drivers and files to be posted or
downloaded and those requests are prohibited here. See the CCS forum
policy and guidelines at the top of the listing. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
ezflyr
Joined: 25 Oct 2010 Posts: 1019 Location: Tewksbury, MA
|
|
Posted: Thu May 03, 2012 7:40 am |
|
|
Hi,
If you own the compiler, you'll find this example program was installed in the \Examples directory (not the \Drivers directory as was incorrectly stated above).
The actual name the of this example program is 'ex_mmcsd.c'.
John |
|
|
Icarus
Joined: 02 May 2012 Posts: 16
|
|
Posted: Thu May 03, 2012 7:46 am |
|
|
I can't find this file, I find only in drivers mmc_spi. Is it the same ? I don't think so .. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Thu May 03, 2012 8:11 am |
|
|
Compiler version?.
MMCSD, was added to the V4 compilers, about early 2008ish.
MMC_SPI.C, _is_ the basic driver to talk to the cards, but you won't have the FAT driver to handle the file system, so can only talk to the cards as raw devices.
Choices:
Update compiler.
Buy an independant FAT library (Brush electronics).
Write your own.....
The second is the better library, but you'll have to check that it is compatible with your compiler if it's that old.
Best Wishes |
|
|
Icarus
Joined: 02 May 2012 Posts: 16
|
|
Posted: Thu May 03, 2012 6:09 pm |
|
|
I've got the driver, but when I compile the program above I find too many errors !! |
|
|
Icarus
Joined: 02 May 2012 Posts: 16
|
|
Posted: Fri May 04, 2012 7:38 am |
|
|
I made another program, I compile on CCS it works but when I run simulation on ISIS it always tells me: Can't create or open card image file !!
Can someone help ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19504
|
|
Posted: Fri May 04, 2012 9:33 am |
|
|
Go to a forum for Proteus....
Seriously, there are people here, who consider using the PIC simulator on Proteus, to be roughly akin to 'shooting yourself in the foot', when it comes to actually getting a PIC project to work.
The error is saying it can't open the file you have configured for Proteus to use to simulate the memory card. Setup problem in Proteus.
You _need_ to be working with a real chip, and memory card, to have any hope at all of generating something that will actually work in the real world.
Best Wishes |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9225 Location: Greensville,Ontario
|
|
Posted: Fri May 04, 2012 11:24 am |
|
|
Best help, is as mr. T says 'GET RID OF PROTEUS !!'
You'll never, ever get an 18F452 and MMC card running in the real world if you blindly accept Proteus as actually working. It is SO full of errors, faulty DRC and well.....the bottom line is ..it doesn't work.
Either spend a few hours with real hardware and get an MMC card to run (be sure to use correct logic level interface chips !!).
or
Buy a Vinculum ($30) and be up and running, storing data on ANY flash drive in an hour.
The choice is yours. |
|
|
Icarus
Joined: 02 May 2012 Posts: 16
|
|
Posted: Sun May 06, 2012 5:02 pm |
|
|
I used the example 'ex_mmcsd' to write my code. I compile with CCS and ISIS, there is no error, but I don't know if the values are saved or not. Does someone have an idea how to check it ?
Here is my program:
Code: |
#include <18F452.h>
#fuses NOWDT, HS, NOPROTECT
#use delay(clock=25M)
#include <LCD.C>
#use rs232(baud=9600, UART1, errors)
#include <stdlib.h> // for atoi32
//meda library, a compatable media library is required for FAT.
#use fast_io(c)
#define MMCSD_PIN_SCL PIN_C3 //o
#define MMCSD_PIN_SDI PIN_C4 //i
#define MMCSD_PIN_SDO PIN_C5 //o
#define MMCSD_PIN_SELECT PIN_C2 //o
#include <mmcsd.c>
#include <input.c>
void main(void)
{
BYTE value, cmd;
int32 address;
float N;
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_DIV_8);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);
lcd_init();
set_adc_channel(0);
delay_us(10);
N=read_adc();
printf(lcd_putc,"la valeur: %fV",N);
value=N;
printf("\r\n\nex_mmcsd.c\r\n\n");
if (mmcsd_init())
{
printf("Could not init the MMC/SD!!!!");
while(TRUE);
}
do {
do {
printf("\r\nRead or Write: ");
cmd=getc();
cmd=toupper(cmd);
putc(cmd);
} while ( (cmd!='R') && (cmd!='W') );
printf("\n\rLocation: ");
address = gethex();
address = (address<<8)+gethex();
if(cmd=='R')
{
mmcsd_read_byte(address, &value);
printf("\r\nValue: %X\r\n", value);
}
if(cmd=='W') {
printf("\r\nNew value: ");
value = gethex();
printf(lcd_putc,"\n\r");
mmcsd_write_byte(address, value);
mmcsd_flush_buffer();
}
} while (TRUE);
} |
|
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon May 07, 2012 4:53 am |
|
|
You remind me of this comic: http://xkcd.com/722/
You have no clue as to what you are doing but by writing more code you hope things will start to work.
Icarus wrote: | I used the example 'ex_mmcsd' to write my code. I
compile with CCS and ISIS, there is no error, but I don't know if the values are saved or not. Does someone have an idea how to check it ?[/code] | What do you think yourself?
There is a command to write to a memory address on the SD card. If you use that command and then next use the command to read from the same address... Same value means the storage was successful.
You still haven't answered the question about which compiler version you are using. This make helping you more difficult.
When you can write to the memory card the next step is to add a file system, otherwise you can't read the data from a standard Windows PC. For example use the FAT32 driver supplied by CCS or one of the drivers from the Code Library section in this forum. |
|
|
Icarus
Joined: 02 May 2012 Posts: 16
|
|
Posted: Wed May 09, 2012 3:51 pm |
|
|
Hey ckielstra, I am using the version 4.057 .
Should I send byte by byte each value of ADC ? |
|
|
|
|
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
|