|
|
View previous topic :: View next topic |
Author |
Message |
jaime
Joined: 25 Nov 2005 Posts: 56 Location: Porto - Portugal
|
mmc spi driver example |
Posted: Fri Aug 04, 2006 7:41 am |
|
|
Hi
can anyone post and example using the ccs driver "mmc spi"?
I would like to make a data logger with this driver but i dont now where to start...
thanks
jaime |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Mon Aug 07, 2006 4:23 am |
|
|
From the absence of response you get it looks like no example code exists or nobody is willing to share it.
Can you be a bit more specific of what your problem is? I had a look at the CCS provided code and it looks easy to use. There are init, read and write functions, what more information do you need? |
|
|
jaime
Joined: 25 Nov 2005 Posts: 56 Location: Porto - Portugal
|
|
Posted: Mon Aug 07, 2006 12:01 pm |
|
|
Thanks for the support...
The mmc dont init...
Code: |
#include<18F4550>
#use delay (clock=20000000)
#use rs232(baud=19200, xmit=pin_c6, rcv=pin_c7)
#fuses HS, NOLVP, NOWDT, PUT, BROWNOUT
#include <mmc_spi.c>
#define MMC_CS PIN_D0
#define MMC_CLK PIN_D1
#define MMC_DI PIN_D2
#define MMC_DO PIN_D3
main()
{
printf("\n\rTeste MMC drivers\n\r");
if(mmc_init()==0)
printf("\n\rmmc init ok\n\r");
else
printf("\n\rmmc init fault\n\r");
}
|
This is the beginning of the program. I enable the debug messsges in the driver. I get 50 times
Code: |
sent cmd 0, arg 0
err: no start bit waiting for response
|
and then
Code: |
ERR: after reset, device isn't idle
mmc init fault
|
what shloud i do? I try the same card with the program that PCM translate from cc5x and it woks. I only change the PIC and the pins for the connections.
Thanks |
|
|
slo Guest
|
|
Posted: Mon Aug 07, 2006 3:53 pm |
|
|
I don't have the CCS mmc_spi code as my compiler is too old so I can't check, but if you're #defines for the MMC pins are declared after the #include for the mmc_spi.c, then the mmc_spi.c will be compiled first, using it's default pins.
Try defining the mmc pins before the include for the mmc_spi. |
|
|
jaime
Joined: 25 Nov 2005 Posts: 56 Location: Porto - Portugal
|
|
Posted: Tue Aug 08, 2006 7:11 am |
|
|
Yes... it works. Thanks
I make a litle program that after init will record serial data and when reach 512 bytes will write the mmc and then read back.
But i'm doing something wrong...
Code: |
#include<18F4550>
#use delay (clock=20000000)
#use rs232(baud=19200, xmit=pin_c6, rcv=pin_c7)
#fuses HS, NOLVP, NOWDT, PUT, BROWNOUT
#define MMC_CS PIN_D0
#define MMC_CLK PIN_D1
#define MMC_DI PIN_D2
#define MMC_DO PIN_D3
#include <mmc_spi.c>
char buffer[513];
char send[513];
int16 size=0;
int32 address=0;
main()
{
printf("\n\rTeste MMC drivers\n\r");
if(mmc_init()==0)
printf("\n\rmmc init ok\n\r");
else
printf("\n\rmmc init fault\n\r");
enable_interrupts(int_rda);
enable_interrupts(global);
printf("\n\rStart...\n\r");
while(1)
{
//starts to record the serial data and when have 512 bytes records it
if(size==512)
{
disable_interrupts(int_rda);
printf("\n\r buffer=%s\n\r",buffer);
if(mmc_write_block(address, size, *buffer)==0)
printf("\n\rwrite ok \n\r");
else
printf("\n\rwrite fault \n\r");
//read
if(mmc_read_block(address, size,*send)==0)
printf("\n\rread ok\n\r");
else
printf("\n\rread fault");
//prints the data
printf("\n\rreading: %s\n\r",send);
size=0;
address++;
enable_interrupts(int_rda);
}
}
}
#int_rda
void trata_rda()
{
buffer[size]=getc();
size++;
}
|
The write and read function in mmc spi is like:
MMC_EC mmc_write_block(int32 address, int16 block_size, int *ptr);
MMC_EC mmc_read_block(int32 address,int16 block_size, int *ptr);
Thanks agian |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Tue Aug 08, 2006 8:16 am |
|
|
Changeto |
|
|
jaime
Joined: 25 Nov 2005 Posts: 56 Location: Porto - Portugal
|
|
Posted: Tue Aug 08, 2006 9:43 am |
|
|
Thanks...
But still have a error in the read function...
Code: | //read
if(mmc_read_block(address, size,*send)==0)
printf("\n\rread ok\n\r");
else
printf("\n\rread fault");
//prints the data
printf("\n\rreading: %s\n\r",send);
|
It prints nothing... any help? |
|
|
jaime
Joined: 25 Nov 2005 Posts: 56 Location: Porto - Portugal
|
|
Posted: Wed Aug 09, 2006 10:00 am |
|
|
i understand that i have errors... lots and big ones.
i was reading about pointers and passing pointers to functions...
Now i change my program and i have a error that i dont understand. Passing the pointer to another function the value of the pointer change.
I print the value of the pointer and then call the write block fuction, and when i enter the write function i print the value and they dont match...
Code: | #include<18F4550>
#device *=16
#use delay (clock=20000000)
#use rs232(baud=19200, xmit=pin_c6, rcv=pin_c7, errors)
#fuses HS, NOLVP, NOWDT, PUT, BROWNOUT
#define MMC_CS PIN_D0
#define MMC_CLK PIN_D1
#define MMC_DI PIN_D2
#define MMC_DO PIN_D3
#include <mmc_spi.c>
int buffer[512];
int16 size=0;
main()
{
int32 address=0;
int *ptra;
int16 f;
ptra = &(buffer[0]);
printf("\n\r Teste MMC drivers\n\r");
if(mmc_init()==0)
printf("\n\rmmc init ok\n\r");
else
printf("\n\rmmc init fault\n\r");
enable_interrupts(int_rda);
enable_interrupts(global);
printf("\n\rStart...\n\r");
while(1)
{
//starts to record the serial data and when have 512 bytes records it
if(size==512)
{
disable_interrupts(int_rda);
//prints the buffer
printf("\n\rWhat enter the buffer:\n\r");
for(f=0;f<=511;f++)
printf("%c,",buffer[f]);
//prints address of buffer to see if match the pointer
printf("\n\r");
printf("\n\rBuffer address = %ld",&(buffer[0]));
printf("\n\rptra points to = %ld",ptra);
printf("\n\r");
//call the write block function from driver
if(mmc_write_block(address, size, *ptra)==0)
printf("\n\rwrite ok \n\r");
else
printf("\n\rwrite fault \n\r");
//clear the buffer
for(f=0;f<=511;f++)
buffer[f]=0;
//prints address of buffer to see if match the pointer
printf("\n\r");
printf("\n\rBuffer address = %ld",&(buffer[0]));
printf("\n\rptra points to = %ld",ptra);
printf("\n\r");
//call the read block function from driver
if(mmc_read_block(address, size,*ptra)==0)
printf("\n\rread ok\n\r");
else
printf("\n\rread fault");
//print the buffer to see if is the same as PIC send
printf("\n\r What the PIC receive must be the same as the buffer:\n\r");
for(f=0;f<=511;f++)
printf("%c,",buffer[f]);
size=0;
address+=512;
enable_interrupts(int_rda);
printf("\n\rStart again\n\r");
}
}
}
#int_rda
void trata_rda()
{
buffer[size]=getc();
size++;
}
|
any help? |
|
|
Ttelmah Guest
|
|
Posted: Wed Aug 09, 2006 10:27 am |
|
|
Ptra, is _already_ a pointer. You are handing the contents of the pointer to the function, not the pointer itself. With this wrong value, the code overwrites the value held in ptra, and hence scrambles the memory in this area. Use one of:
if(mmc_write_block(address, size, ptra)==0)
if(mmc_write_block(address, size, buffer)==0)
-- (the name of an array, _is_it's address)
if(mmc_write_block(address, size, &buffer[0])==0)
Each of these will give the address of the buffer, which you are currently not doing...
Best Wishes |
|
|
jaime
Joined: 25 Nov 2005 Posts: 56 Location: Porto - Portugal
|
|
Posted: Wed Aug 09, 2006 11:38 am |
|
|
thanks a lot... it works. |
|
|
NIBIRU Guest
|
|
Posted: Wed Jun 06, 2007 11:32 am |
|
|
Hi, Jaime I have the same problem, what driver are you using? Can you post the final code please. thanks a lot. |
|
|
mikepic Guest
|
|
Posted: Sun Jun 10, 2007 6:07 am |
|
|
Hi,
I'm triying to test all this in proteus, but it doesn't work.
Has anybody do it? |
|
|
jaime
Joined: 25 Nov 2005 Posts: 56 Location: Porto - Portugal
|
|
Posted: Wed Jun 13, 2007 11:53 am |
|
|
NIBIRU wrote: | Hi, Jaime I have the same problem, what driver are you using? Can you post the final code please. thanks a lot. |
Hello
You can see it in my web page... _________________ www.jagsilva.com |
|
|
Guest
|
|
Posted: Thu Jul 12, 2007 1:23 pm |
|
|
Hi Jaime,
Your web page is no longer available, do you have a new one?
Thanks,
Joao |
|
|
jaime
Joined: 25 Nov 2005 Posts: 56 Location: Porto - Portugal
|
|
Posted: Thu Jul 12, 2007 1:31 pm |
|
|
hello
the link was wrong but the page working.
thanks
jaime _________________ www.jagsilva.com |
|
|
|
|
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
|