اطلاعیه

Collapse
No announcement yet.

مشکل با راه اندازی mmc و کتابخانه ff.h

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    مشکل با راه اندازی mmc و کتابخانه ff.h

    سلام این کد مربوط به mmc هست نمیدونم ایرادش کجاست کسی میتونه ایرادشو بگه؟



    کد:
    #include <mega32.h>
     #include <stdio.h>
    // Alphanumeric LCD Module functions
    #include <alcd.h>
    
     #include "ff.h"
    
     #include <delay.h>
    // Timer 0 overflow interrupt service routine
    interrupt [TIM0_OVF] void timer0_ovf_isr(void)
    {
    // Reinitialize Timer 0 value
    TCNT0=0xD8;
    disk_timerproc();
    
    }
    
    FATFS fs;   // Work area (file system object) for logical drive
    FIL ftest; 
    char buffer[20]; 
    
    void main(void)
    {
    // Declare your local variables here
     unsigned int bw;     // File R/W count
    
    // Input/Output Ports initialization
    // Port A initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTA=0x00;
    DDRA=0x00;
    
    // Port B initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTB=0x00;
    DDRB=0x00;
    
    // Port C initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTC=0x00;
    DDRC=0x00;
    
    // Port D initialization
    // Func7=In Func6=In Func5=In Func4=In Func3=In Func2=In Func1=In Func0=In 
    // State7=T State6=T State5=T State4=T State3=T State2=T State1=T State0=T 
    PORTD=0x00;
    DDRD=0x00;
    
    // Timer/Counter 0 initialization
    // Clock source: System Clock
    // Clock value: 7.813 kHz
    // Mode: Normal top=0xFF
    // OC0 output: Disconnected
    TCCR0=0x05;
    TCNT0=0xD8;
    OCR0=0x00;
    
    // Timer/Counter 1 initialization
    // Clock source: System Clock
    // Clock value: Timer1 Stopped
    // Mode: Normal top=0xFFFF
    // OC1A output: Discon.
    // OC1B output: Discon.
    // Noise Canceler: Off
    // Input Capture on Falling Edge
    // Timer1 Overflow Interrupt: Off
    // Input Capture Interrupt: Off
    // Compare A Match Interrupt: Off
    // Compare B Match Interrupt: Off
    TCCR1A=0x00;
    TCCR1B=0x00;
    TCNT1H=0x00;
    TCNT1L=0x00;
    ICR1H=0x00;
    ICR1L=0x00;
    OCR1AH=0x00;
    OCR1AL=0x00;
    OCR1BH=0x00;
    OCR1BL=0x00;
    
    // Timer/Counter 2 initialization
    // Clock source: System Clock
    // Clock value: Timer2 Stopped
    // Mode: Normal top=0xFF
    // OC2 output: Disconnected
    ASSR=0x00;
    TCCR2=0x00;
    TCNT2=0x00;
    OCR2=0x00;
    
    // External Interrupt(s) initialization
    // INT0: Off
    // INT1: Off
    // INT2: Off
    MCUCR=0x00;
    MCUCSR=0x00;
    
    // Timer(s)/Counter(s) Interrupt(s) initialization
    TIMSK=0x01;
    
    // USART initialization
    // USART disabled
    UCSRB=0x00;
    
    // Analog Comparator initialization
    // Analog Comparator: Off
    // Analog Comparator Input Capture by Timer/Counter 1: Off
    ACSR=0x80;
    SFIOR=0x00;
    
    // ADC initialization
    // ADC disabled
    ADCSRA=0x00;
    
    // SPI initialization
    // SPI disabled
    SPCR=0x00;
    
    // TWI initialization
    // TWI disabled
    TWCR=0x00;
    
    // Alphanumeric LCD initialization
    // Connections specified in the
    // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
    // RS - PORTA Bit 0
    // RD - PORTA Bit 1
    // EN - PORTA Bit 2
    // D4 - PORTA Bit 4
    // D5 - PORTA Bit 5
    // D6 - PORTA Bit 6
    // D7 - PORTA Bit 7
    // Characters/line: 8
    lcd_init(8);
    
    // Global enable interrupts
    #asm("sei")
          lcd_puts("salam");delay_ms(5000);lcd_clear();
    
         f_mount(0,&fs);
         f_open(&ftest, "read.txt", FA_CREATE_ALWAYS | FA_WRITE);
         f_read(&ftest,&buffer,15,&bw); 
         lcd_puts(buffer);delay_ms(5000);lcd_clear();
    while (1);
       
    }

    #2
    پاسخ : مشکل با راه اندازی mmc و کتابخانه ff.h

    این کد تست کن . 100% جواب میده . خودش یه فایل درست میکنه و یک متن داخلش میریزه و بعد فایل میبنده دوباره باز میکنه و متن نمایش میده
    [code=c]
    #include <mega32a.h>
    #define xtal 8000000
    #include <alcd.h>
    #include <sdcard.h>
    #include <ff.h>
    #include <delay.h>
    #include <stdio.h>

    FRESULT res;
    char path[]="0:/sepehr.txt";
    char text[]="I like CodeVisionAVR!";

    unsigned int nbytes;
    interrupt [TIM0_OVF] void timer0_ovf_isr(void)
    {
    TCNT0=0xB2;
    disk_timerproc();
    }

    void main(void)
    {
    FATFS drive;
    FIL file;
    int i;
    //unsigned char status;
    char buffer[50];

    // Timer Period: 9.984 ms
    TCCR0=(0<<WGM00) | (0<<COM01) | (0<<COM00) | (0<<WGM01) | (1<<CS02) | (0<<CS01) | (1<<CS00);
    TCNT0=0xb2;
    OCR0=0x00;
    TIMSK=0x01;
    #asm("sei&quot

    lcd_init(20);
    lcd_clear();
    lcd_putsf("Init fat"
    while(f_mount(0,&drive)!=FR_OK) delay_ms(100);
    lcd_putsf(" OK"
    delay_ms(2000);
    lcd_clear();
    lcd_putsf("open file"
    delay_ms(1000);
    lcd_clear();

    if ((res=f_open(&file,"0:/sepehr2.txt",FA_CREATE_ALWAYS | FA_WRITE))==FR_OK)
    lcd_putsf("File created OK"
    else
    lcd_putsf("File created ERROR"
    delay_ms(1000);
    lcd_clear();

    if ((res=f_write(&file,text,sizeof(text)-1,&nbytes))==FR_OK)
    lcd_putsf(" bytes written ok "
    else

    lcd_putsf(" ERROR"


    delay_ms(1000);
    lcd_clear();

    f_close(&file);

    while ((f_open(&file,"sepehr.txt", FA_READ ))!=FR_OK) ;
    lcd_putsf(" OK"
    delay_ms(2000);
    lcd_clear();
    lcd_putsf("read file"
    while (f_read(&file, buffer, 20, &i)!=FR_OK) ;
    lcd_putsf(" OK"
    delay_ms(100);
    lcd_clear();
    lcd_puts(buffer);
    f_close(&file);
    while (1)
    {
    // Place your code here

    }
    }
    [/code]


    این کد هم به روش سکتور عمل میکنه
    [code=c]
    #include <mega32.h>
    #include <delay.h>
    #include <spi.h>
    #include "sdcard.h"
    #include <alcd.h>

    char BUFFER[512];

    interrupt [TIM1_OVF] void timer1_ovf_isr(void)
    {
    // Reinitialize Timer1 value
    TCNT1H=0xD8F0 >> 8;
    TCNT1L=0xD8F0 & 0xff;
    // Place your code here
    disk_timerproc();
    }



    void main(void)
    {
    unsigned char status;
    DDRB=0xB0;

    TCCR1A=(0<<COM1A1) | (0<<COM1A0) | (0<<COM1B1) | (0<<COM1B0) | (0<<WGM11) | (0<<WGM10);
    TCCR1B=(0<<ICNC1) | (0<<ICES1) | (0<<WGM13) | (0<<WGM12) | (0<<CS12) | (1<<CS11) | (0<<CS10);
    TCNT1H=0xD8;
    TCNT1L=0xF0;

    // Timer(s)/Counter(s) Interrupt(s) initialization
    TIMSK=(0<<OCIE2) | (0<<TOIE2) | (0<<TICIE1) | (0<<OCIE1A) | (0<<OCIE1B) | (1<<TOIE1) | (0<<OCIE0) | (0<<TOIE0);

    // SPI initialization
    // SPI Type: Master
    // SPI Clock Rate: 2000.000 kHz
    // SPI Clock Phase: Cycle Start
    // SPI Clock Polarity: Low
    // SPI Data Order: MSB First
    SPCR=0x50;
    SPSR=0x00;
    lcd_init(16);

    #asm("sei&quot

    status=disk_initialize(0);
    /* clear the LCD */
    lcd_clear();
    /* display disk initialization result on the LCD */
    if (status & STA_NOINIT) lcd_puts("Disk init failed"
    else
    if (status & STA_NODISK) lcd_puts("Card not present"
    else
    if (status & STA_PROTECT) lcd_puts("Card write\nprotected"
    /* all status flags are 0, disk initialization OK */
    else lcd_puts("Init OK"
    /* wait 2 seconds */
    delay_ms(2000);
    lcd_clear();

    while (1)
    {
    disk_write(0,"buffer1",0,1);
    disk_write(0,"buffer2",1,1);
    disk_write(0,"buffer3",2,1);
    disk_read(0,BUFFER,0,1);
    lcd_gotoxy(0,0);
    lcd_puts(BUFFER);
    delay_ms(1000);
    disk_read(0,BUFFER,1,1);
    lcd_gotoxy(0,0);
    lcd_puts(BUFFER);
    delay_ms(1000);

    disk_read(0,BUFFER,2,1);
    lcd_gotoxy(0,0);
    lcd_puts(BUFFER);
    delay_ms(1000);

    }
    }

    [/code]


    دیدگاه


      #3
      پاسخ : مشکل با راه اندازی mmc و کتابخانه ff.h

      the estimated data stack of 1314 byte exceeds the 512
      این اخطار و چکارش کنم؟
      ارور از کتابخانه هاش میگیره. کتابخانه هاشو هم میشه بفرستی؟
      ff.lib رو خطا گرفته.کتابخانه های fft رو از کجا بگیرم؟حدس میزنم به خاطر همین کتابخانه هاشه اذیت میکنه.
      این خطا رو گرفته
      Library error: C:\cvavr\lib\ff.lib(241): undefined member 'wflag'

      دیدگاه


        #4
        پاسخ : مشکل با راه اندازی mmc و کتابخانه ff.h

        من دیتا استک 1500 گزاشتم این خطا بر طرف شد
        باید بری قسمت Configure Project / Code Generator/Data Stack Size
        باید 1500 به بالا بزاری

        دیدگاه


          #5
          پاسخ : مشکل با راه اندازی mmc و کتابخانه ff.h

          از کتابخانه های خود کدویژن استفاده کردید؟ یا کتابخانه اضافه کردید؟
          کدوم ورژن کدویژن رو استفاده کردید؟

          دیدگاه


            #6
            پاسخ : مشکل با راه اندازی mmc و کتابخانه ff.h

            از کتابخانه خود کد ویژن استفاده کردم . ورژن 3.14
            البته با ورژن های دیگه هم تست کردم
            راستی شما توی قسمت
            Configure Project /Librare /mmc
            فعال کردین ؟؟؟

            دیدگاه


              #7
              پاسخ : مشکل با راه اندازی mmc و کتابخانه ff.h

              قسمت lcd,mmc رو فعال کردم اما خطا میده.حالا کدویژن و دوباره نصب کنم شاید مشکل اینه.
              ورژن 3.14 کجا میشه دانلود کرد؟ با کدوم ورژن ها تست کردید؟

              اضافه شده در تاریخ :
              روی کدویژن 3.12چک کردم ارور داد.چه کدویژنیو نصب کنم؟ورژن3.14رو از کجا میشه گرفت؟

              دیدگاه


                #8
                پاسخ : مشکل با راه اندازی mmc و کتابخانه ff.h

                ببین این پروژه کامله
                برات پ کردم ببین باز هم خطا میده

                http://s6.picofile.com/file/82440593..._File.rar.html

                دیدگاه


                  #9
                  پاسخ : مشکل با راه اندازی mmc و کتابخانه ff.h

                  سلام برنامه ای که دادید عالی جواب میداد اما با یک مشکل برخورد کردم من همون برنامه رو چندتا چیز اضافه کردم مثلا وقفه سریال ولی هیچ جای برنامه تغییر ندادم فقط بعضی قسمت ها رو فعال کردم که بعدا توش کد بنویسم ولی برعکس برنامه ای که دوست خوبمون فرستاد این برنامه قسمت ایجاد فایل و ایراد میگیره چند بار امتحان کردم ولی درست نشد که نشد :angry: :angry: :angry: :angry: :angry: کسی میتونه بگه چرا برنامه ای که تو پست قبلی عالی جواب میده توی برنامه زیر جواب نمیده؟؟؟؟!!!!! فعال کردن بعضی از امکانات میکرو میتونه دلیلش باشه؟!!!
                  کد:
                  
                  #include <mega32.h>
                  
                  
                  #define xtal 8000000
                  #include <alcd.h>
                  #include <sdcard.h>
                  #include <ff.h>
                  #include <delay.h>
                  #include <stdio.h>
                  // Declare your global variables here
                   
                  FRESULT res;
                  char path[]="0:/sepehr.txt";
                  char text[]="I like CodeVisionAVR!";
                  unsigned int nbytes;
                  #define DATA_REGISTER_EMPTY (1<<UDRE)
                  #define RX_COMPLETE (1<<RXC)
                  #define FRAMING_ERROR (1<<FE)
                  #define PARITY_ERROR (1<<UPE)
                  #define DATA_OVERRUN (1<<DOR)
                  
                  // USART Receiver buffer
                  #define RX_BUFFER_SIZE 8
                  char rx_buffer[RX_BUFFER_SIZE];
                  
                  #if RX_BUFFER_SIZE <= 256
                  unsigned char rx_wr_index=0,rx_rd_index=0;
                  #else
                  unsigned int rx_wr_index=0,rx_rd_index=0;
                  #endif
                  
                  #if RX_BUFFER_SIZE < 256
                  unsigned char rx_counter=0;
                  #else
                  unsigned int rx_counter=0;
                  #endif
                  
                  // This flag is set on USART Receiver buffer overflow
                  bit rx_buffer_overflow;
                  
                  // USART Receiver interrupt service routine
                  interrupt [USART_RXC] void usart_rx_isr(void)
                  {
                  char status,data;
                  status=UCSRA;
                  data=UDR;
                  if ((status & (FRAMING_ERROR | PARITY_ERROR | DATA_OVERRUN))==0)
                    {
                    rx_buffer[rx_wr_index++]=data;
                  #if RX_BUFFER_SIZE == 256
                    // special case for receiver buffer size=256
                    if (++rx_counter == 0) rx_buffer_overflow=1;
                  #else
                    if (rx_wr_index == RX_BUFFER_SIZE) rx_wr_index=0;
                    if (++rx_counter == RX_BUFFER_SIZE)
                     {
                     rx_counter=0;
                     rx_buffer_overflow=1;
                     }
                  #endif
                    }
                  }
                  
                  #ifndef _DEBUG_TERMINAL_IO_
                  // Get a character from the USART Receiver buffer
                  #define _ALTERNATE_GETCHAR_
                  #pragma used+
                  char getchar(void)
                  {
                  char data;
                  while (rx_counter==0);
                  data=rx_buffer[rx_rd_index++];
                  #if RX_BUFFER_SIZE != 256
                  if (rx_rd_index == RX_BUFFER_SIZE) rx_rd_index=0;
                  #endif
                  #asm("cli")
                  --rx_counter;
                  #asm("sei")
                  return data;
                  }
                  #pragma used-
                  #endif
                  
                  // Standard Input/Output functions
                  #include <stdio.h>
                  
                  // Timer 0 overflow interrupt service routine
                  interrupt [TIM0_OVF] void timer0_ovf_isr(void)
                  {
                  TCNT0=0xB2;
                  disk_timerproc(); 
                  
                  }
                  
                  void main(void)
                  {
                  // Declare your local variables here
                  FATFS drive;
                  FIL file;
                  int i;
                  //unsigned char status;
                  char buffer[50];
                  
                  // Input/Output Ports initialization
                  // Port A initialization
                  // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In 
                  DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) | (0<<DDA1) | (0<<DDA0);
                  // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T 
                  PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (0<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) | (0<<PORTA1) | (0<<PORTA0);
                  
                  // Port B initialization
                  // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In 
                  DDRB=(0<<DDB7) | (0<<DDB6) | (0<<DDB5) | (0<<DDB4) | (0<<DDB3) | (0<<DDB2) | (0<<DDB1) | (0<<DDB0);
                  // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T 
                  PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);
                  
                  // Port C initialization
                  // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In 
                  DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) | (0<<DDC0);
                  // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T 
                  PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);
                  
                  // Port D initialization
                  // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In 
                  DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) | (0<<DDD0);
                  // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T 
                  PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0);
                  
                  // Timer/Counter 0 initialization
                  // Timer Period: 9.984 ms
                  TCCR0=(0<<WGM00) | (0<<COM01) | (0<<COM00) | (0<<WGM01) | (1<<CS02) | (0<<CS01) | (1<<CS00);
                  TCNT0=0xb2;
                  OCR0=0x00;
                  TIMSK=0x01;
                  #asm("sei")
                  
                  // Timer/Counter 1 initialization
                  // Clock source: System Clock
                  // Clock value: Timer1 Stopped
                  // Mode: Normal top=0xFFFF
                  // OC1A output: Disconnected
                  // OC1B output: Disconnected
                  // Noise Canceler: Off
                  // Input Capture on Falling Edge
                  // Timer1 Overflow Interrupt: Off
                  // Input Capture Interrupt: Off
                  // Compare A Match Interrupt: Off
                  // Compare B Match Interrupt: Off
                  TCCR1A=(0<<COM1A1) | (0<<COM1A0) | (0<<COM1B1) | (0<<COM1B0) | (0<<WGM11) | (0<<WGM10);
                  TCCR1B=(0<<ICNC1) | (0<<ICES1) | (0<<WGM13) | (0<<WGM12) | (0<<CS12) | (0<<CS11) | (0<<CS10);
                  TCNT1H=0x00;
                  TCNT1L=0x00;
                  ICR1H=0x00;
                  ICR1L=0x00;
                  OCR1AH=0x00;
                  OCR1AL=0x00;
                  OCR1BH=0x00;
                  OCR1BL=0x00;
                  
                  // Timer/Counter 2 initialization
                  // Clock source: System Clock
                  // Clock value: Timer2 Stopped
                  // Mode: Normal top=0xFF
                  // OC2 output: Disconnected
                  ASSR=0<<AS2;
                  TCCR2=(0<<PWM2) | (0<<COM21) | (0<<COM20) | (0<<CTC2) | (0<<CS22) | (0<<CS21) | (0<<CS20);
                  TCNT2=0x00;
                  OCR2=0x00;
                  
                  // Timer(s)/Counter(s) Interrupt(s) initialization
                  TIMSK=(0<<OCIE2) | (0<<TOIE2) | (0<<TICIE1) | (0<<OCIE1A) | (0<<OCIE1B) | (0<<TOIE1) | (0<<OCIE0) | (1<<TOIE0);
                  
                  // External Interrupt(s) initialization
                  // INT0: Off
                  // INT1: Off
                  // INT2: Off
                  MCUCR=(0<<ISC11) | (0<<ISC10) | (0<<ISC01) | (0<<ISC00);
                  MCUCSR=(0<<ISC2);
                  
                  // USART initialization
                  // Communication Parameters: 8 Data, 1 Stop, No Parity
                  // USART Receiver: On
                  // USART Transmitter: On
                  // USART Mode: Asynchronous
                  // USART Baud Rate: 4800
                  UCSRA=(0<<RXC) | (0<<TXC) | (0<<UDRE) | (0<<FE) | (0<<DOR) | (0<<UPE) | (0<<U2X) | (0<<MPCM);
                  UCSRB=(1<<RXCIE) | (0<<TXCIE) | (0<<UDRIE) | (1<<RXEN) | (1<<TXEN) | (0<<UCSZ2) | (0<<RXB8) | (0<<TXB8);
                  UCSRC=(1<<URSEL) | (0<<UMSEL) | (0<<UPM1) | (0<<UPM0) | (0<<USBS) | (1<<UCSZ1) | (1<<UCSZ0) | (0<<UCPOL);
                  UBRRH=0x00;
                  UBRRL=0x67;
                  
                  // Analog Comparator initialization
                  // Analog Comparator: Off
                  // The Analog Comparator's positive input is
                  // connected to the AIN0 pin
                  // The Analog Comparator's negative input is
                  // connected to the AIN1 pin
                  ACSR=(1<<ACD) | (0<<ACBG) | (0<<ACO) | (0<<ACI) | (0<<ACIE) | (0<<ACIC) | (0<<ACIS1) | (0<<ACIS0);
                  SFIOR=(0<<ACME);
                  
                  // ADC initialization
                  // ADC disabled
                  ADCSRA=(0<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIF) | (0<<ADIE) | (0<<ADPS2) | (0<<ADPS1) | (0<<ADPS0);
                  
                  // SPI initialization
                  // SPI disabled
                  SPCR=(0<<SPIE) | (0<<SPE) | (0<<DORD) | (0<<MSTR) | (0<<CPOL) | (0<<CPHA) | (0<<SPR1) | (0<<SPR0);
                  
                  // TWI initialization
                  // TWI disabled
                  TWCR=(0<<TWEA) | (0<<TWSTA) | (0<<TWSTO) | (0<<TWEN) | (0<<TWIE);
                  
                  // Alphanumeric LCD initialization
                  // Connections are specified in the
                  // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
                  // RS - PORTA Bit 0
                  // RD - PORTA Bit 1
                  // EN - PORTA Bit 2
                  // D4 - PORTA Bit 4
                  // D5 - PORTA Bit 5
                  // D6 - PORTA Bit 6
                  // D7 - PORTA Bit 7
                  // Characters/line: 16
                  lcd_init(16);
                  
                  // Global enable interrupts
                       
                  lcd_init(20);
                  lcd_clear();
                  lcd_putsf("Init fat");
                  while(f_mount(0,&drive)!=FR_OK) delay_ms(100);
                  lcd_putsf("  OK");
                  delay_ms(2000);
                  lcd_clear();
                  lcd_putsf("open file");
                  delay_ms(1000);
                  lcd_clear();
                  
                  if ((res=f_open(&file,"0:/sepehr2.txt",FA_CREATE_ALWAYS | FA_WRITE))==FR_OK)
                    lcd_putsf("File created OK");
                  else
                   lcd_putsf("File created ERROR");
                  delay_ms(1000);
                  lcd_clear();
                  
                  if ((res=f_write(&file,text,sizeof(text)-1,&nbytes))==FR_OK)
                    lcd_putsf(" bytes written ok ");
                  else
                   
                    lcd_putsf(" ERROR");
                  
                  
                  delay_ms(1000);
                  lcd_clear();
                  
                  f_close(&file);
                  
                  while ((f_open(&file,"sepehr2.txt", FA_READ ))!=FR_OK) ;
                  lcd_putsf("  OK");
                  delay_ms(2000);
                  lcd_clear();
                  lcd_putsf("read file");
                  while (f_read(&file, buffer, 20, &i)!=FR_OK) ;
                  lcd_putsf("  OK");
                  delay_ms(100);
                  lcd_clear();
                  lcd_puts(buffer);
                  f_close(&file);
                  
                  while (1)
                     {
                  
                     }
                  }

                  دیدگاه


                    #10
                    پاسخ : مشکل با راه اندازی mmc و کتابخانه ff.h

                    سلام
                    من این کد رو نوشتم کامپایل میشه ولی وقتی میکرو رو شروع به کار میکنه آخرش error=3 میده
                    مشکل کجاست؟
                    /*******************************************************This program was created by the
                    CodeWizardAVR V3.12 Advanced
                    Automatic Program Generator
                    © Copyright 1998-2014 Pavel Haiduc, HP InfoTech s.r.l.
                    http://www.hpinfotech.com


                    Project :
                    Version :
                    Date : 2/4/2017
                    Author :
                    Company :
                    Comments:




                    Chip type : ATmega32A
                    Program type : Application
                    AVR Core Clock frequency: 4.000000 MHz
                    Memory model : Small
                    External RAM size : 0
                    Data Stack size : 512
                    *******************************************************/


                    #include <mega32a.h>
                    #include <ff.h>
                    #include <delay.h>
                    #include <stdio.h>


                    // Alphanumeric LCD functions
                    #include <alcd.h>




                    // Timer 0 overflow interrupt service routine
                    interrupt [TIM0_OVF] void timer0_ovf_isr(void)
                    {
                    // Reinitialize Timer 0 value
                    TCNT0=0x64;
                    // Place your code here
                    disk_timerproc ();
                    }


                    // SPI functions
                    #include <spi.h>


                    FRESULT res;
                    char init;
                    FATFS drive;
                    FIL file;
                    char buffer[16]="ERROR";
                    unsigned int bytes;
                    /*flash char *flash error_msg[]={"FR_DISK_ERR","FR_INT_ERR","FR_INT_ERR","FR_NOT_READY","FR_NO_FILE","FR_NO_PATH","FR_INVALID_NAME","FR_DENIED",
                    "FR_EXIST","FR_INVALID_OBJECT","FR_WRITE_PROTECTED","FR_INVALID_DRIVE","FR_NOT_ENABLED","FR_NO_FILESYSTEM",
                    "FR_MKFS_ABORTED","FR_TIMEOUT"};*/
                    void error(FRESULT res)
                    {
                    if ((res >= FR_DISK_ERR) && (res <= FR_TIMEOUT))
                    {
                    sprintf(buffer,"Error= %d",res);
                    lcd_puts(buffer);
                    }
                    /* stop here */
                    while (1);
                    }
                    void main(void)
                    {
                    // Declare your local variables here




                    // Input/Output Ports initialization
                    // Port A initialization
                    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
                    DDRA=(0<<DDA7) | (0<<DDA6) | (0<<DDA5) | (0<<DDA4) | (0<<DDA3) | (0<<DDA2) | (0<<DDA1) | (0<<DDA0);
                    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
                    PORTA=(0<<PORTA7) | (0<<PORTA6) | (0<<PORTA5) | (1<<PORTA4) | (0<<PORTA3) | (0<<PORTA2) | (0<<PORTA1) | (0<<PORTA0);


                    // Port B initialization
                    // Function: Bit7=Out Bit6=In Bit5=Out Bit4=Out Bit3=In Bit2=In Bit1=In Bit0=In
                    DDRB=(1<<DDB7) | (0<<DDB6) | (1<<DDB5) | (1<<DDB4) | (0<<DDB3) | (0<<DDB2) | (0<<DDB1) | (0<<DDB0);
                    // State: Bit7=0 Bit6=T Bit5=0 Bit4=0 Bit3=T Bit2=T Bit1=T Bit0=T
                    PORTB=(0<<PORTB7) | (0<<PORTB6) | (0<<PORTB5) | (0<<PORTB4) | (0<<PORTB3) | (0<<PORTB2) | (0<<PORTB1) | (0<<PORTB0);


                    // Port C initialization
                    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
                    DDRC=(0<<DDC7) | (0<<DDC6) | (0<<DDC5) | (0<<DDC4) | (0<<DDC3) | (0<<DDC2) | (0<<DDC1) | (0<<DDC0);
                    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
                    PORTC=(0<<PORTC7) | (0<<PORTC6) | (0<<PORTC5) | (0<<PORTC4) | (0<<PORTC3) | (0<<PORTC2) | (0<<PORTC1) | (0<<PORTC0);


                    // Port D initialization
                    // Function: Bit7=In Bit6=In Bit5=In Bit4=In Bit3=In Bit2=In Bit1=In Bit0=In
                    DDRD=(0<<DDD7) | (0<<DDD6) | (0<<DDD5) | (0<<DDD4) | (0<<DDD3) | (0<<DDD2) | (0<<DDD1) | (0<<DDD0);
                    // State: Bit7=T Bit6=T Bit5=T Bit4=T Bit3=T Bit2=T Bit1=T Bit0=T
                    PORTD=(0<<PORTD7) | (0<<PORTD6) | (0<<PORTD5) | (0<<PORTD4) | (0<<PORTD3) | (0<<PORTD2) | (0<<PORTD1) | (0<<PORTD0);


                    // Timer/Counter 0 initialization
                    // Clock source: System Clock
                    // Clock value: 15.625 kHz
                    // Mode: Normal top=0xFF
                    // OC0 output: Disconnected
                    // Timer Period: 9.984 ms
                    TCCR0=(0<<WGM00) | (0<<COM01) | (0<<COM00) | (0<<WGM01) | (1<<CS02) | (0<<CS01) | (0<<CS00);
                    TCNT0=0x64;
                    OCR0=0x00;


                    // Timer/Counter 1 initialization
                    // Clock source: System Clock
                    // Clock value: Timer1 Stopped
                    // Mode: Normal top=0xFFFF
                    // OC1A output: Disconnected
                    // OC1B output: Disconnected
                    // Noise Canceler: Off
                    // Input Capture on Falling Edge
                    // Timer1 Overflow Interrupt: Off
                    // Input Capture Interrupt: Off
                    // Compare A Match Interrupt: Off
                    // Compare B Match Interrupt: Off
                    TCCR1A=(0<<COM1A1) | (0<<COM1A0) | (0<<COM1B1) | (0<<COM1B0) | (0<<WGM11) | (0<<WGM10);
                    TCCR1B=(0<<ICNC1) | (0<<ICES1) | (0<<WGM13) | (0<<WGM12) | (0<<CS12) | (0<<CS11) | (0<<CS10);
                    TCNT1H=0x00;
                    TCNT1L=0x00;
                    ICR1H=0x00;
                    ICR1L=0x00;
                    OCR1AH=0x00;
                    OCR1AL=0x00;
                    OCR1BH=0x00;
                    OCR1BL=0x00;


                    // Timer/Counter 2 initialization
                    // Clock source: System Clock
                    // Clock value: Timer2 Stopped
                    // Mode: Normal top=0xFF
                    // OC2 output: Disconnected
                    ASSR=0<<AS2;
                    TCCR2=(0<<PWM2) | (0<<COM21) | (0<<COM20) | (0<<CTC2) | (0<<CS22) | (0<<CS21) | (0<<CS20);
                    TCNT2=0x00;
                    OCR2=0x00;


                    // Timer(s)/Counter(s) Interrupt(s) initialization
                    TIMSK=(0<<OCIE2) | (0<<TOIE2) | (0<<TICIE1) | (0<<OCIE1A) | (0<<OCIE1B) | (0<<TOIE1) | (0<<OCIE0) | (1<<TOIE0);


                    // External Interrupt(s) initialization
                    // INT0: Off
                    // INT1: Off
                    // INT2: Off
                    MCUCR=(0<<ISC11) | (0<<ISC10) | (0<<ISC01) | (0<<ISC00);
                    MCUCSR=(0<<ISC2);


                    // USART initialization
                    // USART disabled
                    UCSRB=(0<<RXCIE) | (0<<TXCIE) | (0<<UDRIE) | (0<<RXEN) | (0<<TXEN) | (0<<UCSZ2) | (0<<RXB8) | (0<<TXB8);


                    // Analog Comparator initialization
                    // Analog Comparator: Off
                    // The Analog Comparator's positive input is
                    // connected to the AIN0 pin
                    // The Analog Comparator's negative input is
                    // connected to the AIN1 pin
                    ACSR=(1<<ACD) | (0<<ACBG) | (0<<ACO) | (0<<ACI) | (0<<ACIE) | (0<<ACIC) | (0<<ACIS1) | (0<<ACIS0);
                    SFIOR=(0<<ACME);


                    // ADC initialization
                    // ADC disabled
                    ADCSRA=(0<<ADEN) | (0<<ADSC) | (0<<ADATE) | (0<<ADIF) | (0<<ADIE) | (0<<ADPS2) | (0<<ADPS1) | (0<<ADPS0);


                    // SPI initialization
                    // SPI Type: Master
                    // SPI Clock Rate: 1000.000 kHz
                    // SPI Clock Phase: Cycle Start
                    // SPI Clock Polarity: Low
                    // SPI Data Order: MSB First
                    SPCR=(0<<SPIE) | (1<<SPE) | (0<<DORD) | (1<<MSTR) | (0<<CPOL) | (0<<CPHA) | (0<<SPR1) | (0<<SPR0);
                    SPSR=(0<<SPI2X);


                    // TWI initialization
                    // TWI disabled
                    TWCR=(0<<TWEA) | (0<<TWSTA) | (0<<TWSTO) | (0<<TWEN) | (0<<TWIE);


                    // Alphanumeric LCD initialization
                    // Connections are specified in the
                    // Project|Configure|C Compiler|Libraries|Alphanumeric LCD menu:
                    // RS - PORTA Bit 0
                    // RD - PORTA Bit 1
                    // EN - PORTA Bit 2
                    // D4 - PORTA Bit 3
                    // D5 - PORTA Bit 4
                    // D6 - PORTA Bit 5
                    // D7 - PORTA Bit 6
                    // Characters/line: 16
                    lcd_init(16);


                    // Global enable interrupts
                    #asm("sei")
                    PORTB.4=0;
                    delay_ms(1000);




                    //******** mount ***********


                    lcd_gotoxy(0,0);
                    lcd_clear();
                    res=f_mount (0,&drive);
                    if(res==FR_OK)
                    { lcd_puts("mount success");
                    delay_ms(3000);
                    }
                    else
                    error(res);




                    //********Disk initialize**********
                    /*lcd_gotoxy(0,0);
                    lcd_clear();
                    init=disk_initialize (0);
                    if(init==STA_NOINIT)
                    lcd_puts("init error");
                    else
                    lcd_puts("init success");
                    delay_ms(3000);
                    lcd_gotoxy(0,0);
                    lcd_clear();
                    init=disk_status (0);
                    if(init==STA_NOINIT)
                    lcd_puts("STA_NOINIT");
                    else if(init==STA_NODISK)
                    lcd_puts("STA_NODISK");
                    else if(init==STA_PROTECT)
                    lcd_puts("STA_PROTECT");
                    delay_ms(3000);*/




                    //******** open ***********
                    lcd_gotoxy(0,0);
                    lcd_clear();
                    res=f_open(&file,"0:/test.txt",FA_READ);
                    if(res==FR_OK)
                    { lcd_puts("open success");
                    delay_ms(3000);
                    }
                    else
                    error(res);




                    //******** read ***********
                    lcd_gotoxy(0,0);
                    lcd_clear();
                    res=f_read(&file,buffer,8, &bytes);
                    if(res==FR_OK)
                    {
                    lcd_puts("read success");
                    delay_ms(3000);
                    }
                    else
                    error(res);




                    //******** close ***********
                    lcd_gotoxy(0,0);
                    lcd_clear();
                    res=f_close(&file);
                    if(res==FR_OK)
                    {
                    lcd_puts("close success");
                    delay_ms(3000);
                    }
                    else
                    error(res);


                    while (1)
                    {
                    // Place your code here
                    lcd_gotoxy(0,0);
                    lcd_clear();
                    lcd_puts(buffer);
                    delay_ms(3000);
                    }
                    }


                    دیدگاه


                      #11
                      پاسخ : مشکل با راه اندازی mmc و کتابخانه ff.h

                      با درود خدمت همه همکاران عزیز. این تاپیک داشت خیلی خوب جلو میرفت نمیدونم چرا وسط راه متوقف شد. یعنی با همین مشکل جواب گرفتن؟!!!
                      در هر صورت خواستم عرض کنم که منم همچین مشکل مشابه ای دارم. از کد برنامه ای مشابه برنامه بالا دارم استفاده میکنم. در برنامه من هم در قسمت
                      کد:
                      init=disk_initialize(0);
                      کد:
                      [FONT=Yekan][/FONT]
                      برنامه متوقف میشه. در حال حاضر از میکرو MEGA32 از نوع DIP و با کریستال 11059200 هرتز کار میکنم. و جالب اینکه حتی وقتی ماژول مموری کارت به میکرو وصل نیست هم دستور
                      کد:
                      res=f_mount (0,&drive);
                      کد:
                      [FONT=Yekan][/FONT]
                      عدد 0 رو برمیگردونه که یعنی برنامه اتصال کارت به میکرو رو تایید میکنه!!! خواهش میکنم دوستانی که موفق به رفع مشکل شدند، لطفا منو هم راهنمایی کنن.
                      پیشاپیش از توجه ای که به این مشکل بنده دارید سپاسگزارم

                      دیدگاه

                      لطفا صبر کنید...
                      X