romel_emperado
Advanced Member level 2
- Joined
- Jul 23, 2009
- Messages
- 606
- Helped
- 45
- Reputation
- 132
- Reaction score
- 65
- Trophy points
- 1,318
- Location
- philippines
- Activity points
- 6,061
Error [983] C:\Documents and Settings\mel\Desktop\PIC184550\materials\PIC18 Petit FAT File System\src_picc18\pff.h; 103.6 storage class redeclared
Error [984] C:\Documents and Settings\mel\Desktop\PIC184550\materials\PIC18 Petit FAT File System\src_picc18\pff.h; 103.6 type redeclared
Error [1098] C:\Documents and Settings\mel\Desktop\PIC184550\materials\PIC18 Petit FAT File System\src_picc18\pff.h; 103.6 conflicting declarations for variable "DIR" (C:\Program Files\HI-TECH Software\PICC-18\PRO\9.66\include\pic18f2550.h:449)
Error [194] C:\Documents and Settings\mel\Desktop\PIC184550\materials\PIC18 Petit FAT File System\src_picc18\pff.h; 142.24 ")" expected
Warning [349] C:\Documents and Settings\mel\Desktop\PIC184550\materials\PIC18 Petit FAT File System\src_picc18\pff.h; 142.39 non-prototyped function declaration for "pf_opendir"
Error [313] C:\Documents and Settings\mel\Desktop\PIC184550\materials\PIC18 Petit FAT File System\src_picc18\pff.h; 142.39 function body expected
Error [194] C:\Documents and Settings\mel\Desktop\PIC184550\materials\PIC18 Petit FAT File System\src_picc18\pff.h; 143.24 ")" expected
Warning [349] C:\Documents and Settings\mel\Desktop\PIC184550\materials\PIC18 Petit FAT File System\src_picc18\pff.h; 143.36 non-prototyped function declaration for "pf_readdir"
Error [313] C:\Documents and Settings\mel\Desktop\PIC184550\materials\PIC18 Petit FAT File System\src_picc18\pff.h; 143.36 function body expected
Warning [374] C:\Documents and Settings\mel\Desktop\PIC184550\materials\PIC18 Petit FAT File System\src_picc18\main.c; 18.5 missing basic type; int assumed
Error [984] C:\Documents and Settings\mel\Desktop\PIC184550\materials\PIC18 Petit FAT File System\src_picc18\main.c; 18.5 type redeclared
Error [1098] C:\Documents and Settings\mel\Desktop\PIC184550\materials\PIC18 Petit FAT File System\src_picc18\main.c; 18.5 conflicting declarations for variable "DIR" (C:\Documents and Settings\mel\Desktop\PIC184550\materials\PIC18 Petit FAT File System\src_picc18\pff.h:103)
Error [372] C:\Documents and Settings\mel\Desktop\PIC184550\materials\PIC18 Petit FAT File System\src_picc18\main.c; 18.5 "," expected
DIR Dir; /* Directory object */
/* Directory object structure */
typedef struct _DIR_
{
WORD index; /* Current read/write index number */
BYTE* fn; /* Pointer to the SFN (in/out) {file[8],ext[3],status[1]} */
CLUST sclust; /* Table start cluster (0:Static table) */
CLUST clust; /* Current cluster */
DWORD sect; /* Current sector */
} DIR;
FRESULT pf_opendir (DIR*, const char*); /* Open a directory */
Error [1098] C:\Documents and Settings\mel\Desktop\romel\pff.h; 104.6 conflicting declarations for variable "DIR" (C:\Program Files\HI-TECH Software\PICC-18\PRO\9.66\include\pic18f4550.h:525)
/ Register: USTAT
extern volatile unsigned char USTAT @ 0xF6C;
// bit and bitfield definitions
extern volatile bit PPBI @ ((unsigned)&USTAT*8)+1;
extern volatile bit DIR @ ((unsigned)&USTAT*8)+2;
extern volatile bit ENDP0 @ ((unsigned)&USTAT*8)+3;
extern volatile bit ENDP1 @ ((unsigned)&USTAT*8)+4;
extern volatile bit ENDP2 @ ((unsigned)&USTAT*8)+5;
extern volatile bit ENDP3 @ ((unsigned)&USTAT*8)+6;
extern union {
struct {
volatile unsigned : 1;
volatile unsigned PPBI : 1;
volatile unsigned DIR : 1;
volatile unsigned ENDP : 4;
};
struct {
volatile unsigned : 3;
volatile unsigned ENDP0 : 1;
volatile unsigned ENDP1 : 1;
volatile unsigned ENDP2 : 1;
volatile unsigned ENDP3 : 1;
};
} USTATbits @ 0xF6C;
...
// Register: USTAT
extern volatile unsigned char USTAT @ 0xF6C;
// bit and bitfield definitions
extern volatile bit PPBI @ ((unsigned)&USTAT*8)+1;
extern volatile bit DIR @ ((unsigned)&USTAT*8)+2;
extern volatile bit ENDP0 @ ((unsigned)&USTAT*8)+3;
extern volatile bit ENDP1 @ ((unsigned)&USTAT*8)+4;
extern volatile bit ENDP2 @ ((unsigned)&USTAT*8)+5;
extern volatile bit ENDP3 @ ((unsigned)&USTAT*8)+6;
...
Part of the problem is the header pic18f2550.h has a "DIR" defined as well:
I'm still hunting the errors down.
BigDog
What issue are you referring, compiling the FATFS routines in HiTech C?
Can you elaborate? Post any compiler messages?
BigDog
but my code actually not working... I was wondering now if a compatibility issue with my SDHC 8G&4G can be the problem...
Possibly. There have been reports of incompatibilities with some SDHCs. Post the manufacture and model of the SDHCs you are attempting to use in your designs.
Have you tried a smaller capacity SDHC, 2GB or less?
Post or upload your code so that we can review it for possible issues. Also the schematic of your design if available.
BigDog
#ifndef MAIN_C
#define MAIN_C
#include <htc.h>
#include <stdio.h>
#include <string.h>
#include "HardwareProfile.h"
#include "pff.h"
#include "lcd.h"
// Config word 1
__CONFIG(1, USBPLL & IESODIS & FCMDIS & HSPLL & PLLPOSTDIV2 & PLLDIV5);
// Config word 2
__CONFIG(2, VREGEN & PWRTDIS & BOREN & BORV20 & WDTDIS & WDTPS32K);
// Config word 3
__CONFIG(3, PBDIGITAL & LPT1DIS & MCLREN);
// Config word 4
__CONFIG(4, XINSTDIS & STVREN & LVPDIS & ICPORTDIS & DEBUGDIS);
// Config word 5, 6 and 7 (protection configuration)
__CONFIG(5, UNPROTECT);
__CONFIG(6, UNPROTECT);
__CONFIG(7, UNPROTECT);
FATFS Fs; /* File system object */
DIR Dir; /* Directory object */
FILINFO Fno; /* File information */
unsigned short rb; /* Return value. */
unsigned char buff[100];
void delay(void);
static void InitialiseSystem(void)
{
// Default Digital
ADCON1 = 0x0F;
// LCD outputs
TRISD = 0b00000000;
// Clear all ports LCD
PORTD = 0b00000000;
// LCD Ilitialization
lcdInit();
}
void main(void)
{
unsigned char i;
InitialiseSystem();
while(1){
delay();
lcdGoto(0, 0);
lcdPuts("insert card!");
if (pf_mount(&Fs) ) continue; /* Initialize FS */
lcdClearDisplay();
lcdPuts("initialized");
while(1){
if (pf_opendir(&Dir, "")) break;
while (!pf_readdir(&Dir, &Fno) && Fno.fname[0]) {
if( strstr(Fno.fname, ".TXT") ){ // TXT file
lcdClearDisplay();
lcdGoto(0, 0);
lcdPuts(Fno.fname);
if(pf_open(Fno.fname)) continue; // open file
if( strstr(Fno.fname, "BLANK") ){
lcdGoto(0, 1);
lcdPuts("writing to a blank file"); // (PFF note: "pf_write" cannot expand file size)
if(pf_write("sample message to SD/MMC card.\r\n", 0, &rb)) continue; // write to file
if(pf_write(0, 0, &rb)) continue; // Finalize the write process
lcdPuts(" done.");
}
else{
if(pf_read(buff, 70, &rb)) continue; // Read data to the buff[]
lcdGoto(0, 2);
lcdPuts(buff); // display txt file content
for(i=0; i<100; i++) buff[i]=0; // clear buffer
}
delay();
delay();
delay();
}
}
}
}
}
void delay(void)
{
long i=0x3FFFF;
while(--i);
}
#endif
/*-----------------------------------------------------------------------*/
/* PFF - Low level disk control module for ATtiny85 (C)ChaN, 2009 */
/*-----------------------------------------------------------------------*/
#include <htc.h>
#include <stdio.h>
#include <string.h>
#include "HardwareProfile.h"
#include "diskio.h"
#include "lcd.h"
#define _WRITE_FUNC 1
/* Definitions for MMC/SDC command */
#define CMD0 (0x40+0) /* GO_IDLE_STATE */
#define CMD1 (0x40+1) /* SEND_OP_COND (MMC) */
#define ACMD41 (0xC0+41) /* SEND_OP_COND (SDC) */
#define CMD8 (0x40+8) /* SEND_IF_COND */
#define CMD12 (0x40+12) /* STOP_TRANSMISSION */
#define CMD16 (0x40+16) /* SET_BLOCKLEN */
#define CMD17 (0x40+17) /* READ_SINGLE_BLOCK */
#define CMD24 (0x40+24) /* WRITE_BLOCK */
#define CMD55 (0x40+55) /* APP_CMD */
#define CMD58 (0x40+58) /* READ_OCR */
/*--------------------------------------------------------------------------
Module Private Functions
---------------------------------------------------------------------------*/
unsigned char CardType;
static void spi_init(void)
{
SS_LATA = 1;
OpenSPI(SPI_FOSC_64, MODE_11, SMPEND);
}
/*-----------------------------------------------------------------------*/
/* Deselect the card and release SPI bus */
/*-----------------------------------------------------------------------*/
static void release_spi (void)
{
SS_LATA = 1;
//rcv_spi
ReadSPI();
}
/*-----------------------------------------------------------------------*/
/* Wait for card ready */
/*-----------------------------------------------------------------------*/
static unsigned char wait_ready (void)
{
unsigned char res;
unsigned short timeout = 0x1FFF;
do
res = ReadSPI();
while ((res != 0xFF) && (--timeout));
lcd_text(0, 3, "Ready");
return res;
}
/*-----------------------------------------------------------------------*/
/* Send a command packet to MMC */
/*-----------------------------------------------------------------------*/
static unsigned char send_cmd (
unsigned char cmd, /* Command unsigned char */
unsigned long arg /* Argument */
)
{
unsigned char n, res;
/* Select the card and wait for ready */
SS_LATA = 1;
SS_LATA = 0;
if (wait_ready() != 0xFF) {
return 0xFF;
}
if (cmd & 0x80) { /* ACMD<n> is the command sequence of CMD55-CMD<n> */
cmd &= 0x7F;
//res = send_cmd(CMD55, 0); // PICC18 Compiler error! (recursive function)
/* Send command packet */
WriteSPI(cmd); /* Start + Command index */
WriteSPI((unsigned char)(arg >> 24)); /* Argument[31..24] */
WriteSPI((unsigned char)(arg >> 16)); /* Argument[23..16] */
WriteSPI((unsigned char)(arg >> 8)); /* Argument[15..8] */
WriteSPI((unsigned char)arg); /* Argument[7..0] */
n = 0x01; /* Dummy CRC + Stop */
if (cmd == CMD0) n = 0x95; /* Valid CRC for CMD0(0) */
if (cmd == CMD8) n = 0x87; /* Valid CRC for CMD8(0x1AA) */
WriteSPI(n);
/* Receive command response */
if (cmd == CMD12) ReadSPI(); /* Skip a stuff unsigned char when stop reading */
n = 10; /* Wait for a valid response in timeout of 10 attempts */
do
res = ReadSPI();
while ((res & 0x80) && --n);
if (res > 1) return res;
}
/* Send command packet */
WriteSPI(cmd); /* Start + Command index */
WriteSPI((unsigned char)(arg >> 24)); /* Argument[31..24] */
WriteSPI((unsigned char)(arg >> 16)); /* Argument[23..16] */
WriteSPI((unsigned char)(arg >> 8)); /* Argument[15..8] */
WriteSPI((unsigned char)arg); /* Argument[7..0] */
n = 0x01; /* Dummy CRC + Stop */
if (cmd == CMD0) n = 0x95; /* Valid CRC for CMD0(0) */
if (cmd == CMD8) n = 0x87; /* Valid CRC for CMD8(0x1AA) */
WriteSPI(n);
/* Receive command response */
if (cmd == CMD12) ReadSPI(); /* Skip a stuff unsigned char when stop reading */
n = 10; /* Wait for a valid response in timeout of 10 attempts */
do
res = ReadSPI();
while ((res & 0x80) && --n);
return res; /* Return with the response value */
}
/*--------------------------------------------------------------------------
//Public Functions
---------------------------------------------------------------------------*/
/*-----------------------------------------------------------------------*/
/* Initialize Disk Drive */
/*-----------------------------------------------------------------------*/
DSTATUS disk_initialize (void)
{
unsigned char n, cmd, ty, ocr[4];
unsigned short tmr;
spi_init();
#if _WRITE_FUNC
if (MMC_SEL) disk_writep(0, 0); /* Finalize write process if it is in progress */
#endif
for (n = 100; n; n--) ReadSPI(); /* Dummy clocks */
ty = 0;
if (send_cmd(CMD0, 0) == 1) { /* Enter Idle state */
if (send_cmd(CMD8, 0x1AA) == 1) { /* SDv2 */
for (n = 0; n < 4; n++) ocr[n] = ReadSPI(); /* Get trailing return value of R7 resp */
if (ocr[2] == 0x01 && ocr[3] == 0xAA) { /* The card can work at vdd range of 2.7-3.6V */
for (tmr = 12000; tmr && send_cmd(ACMD41, 1UL << 30); tmr--) ; /* Wait for leaving idle state (ACMD41 with HCS bit) */
if (tmr && send_cmd(CMD58, 0) == 0) { /* Check CCS bit in the OCR */
for (n = 0; n < 4; n++) ocr[n] = ReadSPI();
ty = (ocr[0] & 0x40) ? CT_SD2 | CT_BLOCK : CT_SD2; /* SDv2 (HC or SC) */
}
}
}
else { /* SDv1 or MMCv3 */
if (send_cmd(ACMD41, 0) <= 1) {
ty = CT_SD1; cmd = ACMD41; /* SDv1 */
} else { /* Proteus 7.x MMC sim model */
ty = CT_MMC; cmd = CMD1; /* MMCv3 */
}
for (tmr = 25000; tmr && send_cmd(cmd, 0); tmr--) ; /* Wait for leaving idle state */
if (!tmr || send_cmd(CMD16, 512) != 0) /* Set R/W block length to 512 */
ty = 0;
}
}
CardType = ty;
release_spi();
return ty ? 0 : STA_NOINIT;
}
/*-----------------------------------------------------------------------*/
/* Read partial sector */
/*-----------------------------------------------------------------------*/
DRESULT disk_readp (
unsigned char *buff, /* Pointer to the read buffer (NULL:Read bytes are forwarded to the stream) */
unsigned long lba, /* Sector number (LBA) */
unsigned short ofs, /* unsigned char offset to read from (0..511) */
unsigned short cnt /* Number of bytes to read (ofs + cnt mus be <= 512) */
)
{
DRESULT res;
unsigned char rc;
unsigned short bc;
if (!(CardType & CT_BLOCK)) lba *= 512; /* Convert to unsigned char address if needed */
res = RES_ERROR;
if (send_cmd(CMD17, lba) == 0) { /* READ_SINGLE_BLOCK */
bc = 30000;
do { /* Wait for data packet in timeout of 100ms */
rc = ReadSPI();
} while (rc == 0xFF && --bc);
if (rc == 0xFE) { /* A data packet arrived */
bc = 514 - ofs - cnt;
/* Skip leading bytes */
if (ofs) {
do ReadSPI(); while (--ofs);
}
/* Receive a part of the sector */
if (buff) { /* Store data to the memory */
do
*buff++ = ReadSPI();
while (--cnt);
} else { /* Forward data to the outgoing stream (depends on the project) */
//do
//xmit(rcv_spi()); /* (Console output) */
//while (--cnt);
}
/* Skip trailing bytes and CRC */
do ReadSPI(); while (--bc);
res = RES_OK;
}
}
release_spi();
return res;
}
/*-----------------------------------------------------------------------*/
/* Write partial sector */
/*-----------------------------------------------------------------------*/
#if _WRITE_FUNC
DRESULT disk_writep (
const unsigned char *buff, /* Pointer to the bytes to be written (NULL:Initiate/Finalize sector write) */
unsigned long sa /* Number of bytes to send, Sector number (LBA) or zero */
)
{
DRESULT res;
unsigned short bc;
static unsigned short wc;
res = RES_ERROR;
if (buff) { /* Send data bytes */
bc = (unsigned short)sa;
while (bc && wc) { /* Send data bytes to the card */
WriteSPI(*buff++);
wc--; bc--;
}
res = RES_OK;
} else {
if (sa) { /* Initiate sector write process */
if (!(CardType & CT_BLOCK)) sa *= 512; /* Convert to unsigned char address if needed */
if (send_cmd(CMD24, sa) == 0) { /* WRITE_SINGLE_BLOCK */
WriteSPI(0xFF); WriteSPI(0xFE); /* Data block header */
wc = 512; /* Set unsigned char counter */
res = RES_OK;
}
} else { /* Finalize sector write process */
bc = wc + 2;
while (bc--) WriteSPI(0); /* Fill left bytes and CRC with zeros */
if ((ReadSPI() & 0x1F) == 0x05) { /* Receive data resp and wait for end of write process in timeout of 300ms */
for (bc = 65000; ReadSPI() != 0xFF && bc; bc--) ; /* Wait ready */
if (bc) res = RES_OK;
}
release_spi();
}
}
return res;
}
#endif
#ifndef HARDWARE_PROFILE_H
#define HARDWARE_PROFILE_H
// Defines required for the USB stack
#define self_power 1
#define USE_USB_BUS_SENSE_IO
#define USB_BUS_SENSE 1
#define DEMO_BOARD PICDEM_FS_USB
#define PICDEM_FS_USB
#define CLOCK_FREQ 48000000
// Fosc frequency (48 Mhz)
#define _XTAL_FREQ 48000000
// Port Controls (Platform dependent)
#define SS_TRIA TRISA5 // sstris = 0
#define SS_LATA LATA5 // select = 0 deselect = 1
#define MMC_SEL 1 // MMC CS status (true:selected)
// Port "D" LCD Input/Output Pins
#define LCD_RS RD0
#define LCD_RW RD1
#define LCD_EN RD2
#define LCD_RST RD3
#define LCD_DB4 RD4
#define LCD_DB5 RD5
#define LCD_DB6 RD6
#define LCD_DB7 RD7
// I/O pin definitions
#define INPUT_PIN 1
#define OUTPUT_PIN 0
#endif
just testing out the CK on PORTB1 and a get a pulsating 5Volt... my PIC is powered by a 5V and my SD slot on a 3.3V.. As i can see the SD card is powered by a ~3V and his clock signal should be at ~3V right? what should i do? a voltage divider with a resistor? or there is an option to set the port output voltage on the PIC?
Gravitech SD/MMC Card Adapter
Gravitech SD/MMC Card Adapter Schematic
I would suggest correcting the voltage mismatch and then retesting your code.
BigDog
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?