PIC16f877 serial interface with Alfat SD memory card

Discussion in 'Embedded Systems and Microcontrollers' started by ranaz, Sep 1, 2008.

  1. ranaz

    Thread Starter New Member

    Mar 7, 2007
    5
    0
    hi. i m trying to send and recieve data to and from memory card through PIC 16f877A.
    PIC serial interrupts work fine if i use hyper terminal. also card works fine with hyperterminal. so this means there is no fualt as far as connections r concerned. also PIC succesfuly writes data on the card. BUT.............
    when i try to retreive it !!!!!!!!!!!!!!!!!!!!! nothing happens. interrupt service routine is not even invoked once. here is the code i'm using:(by the way compiler is "CCS C"


    #include <16F877A.h>
    #fuses HS,NOLVP,NOWDT,PUT,NOBROWNOUT
    #use delay(clock=10000000)
    #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

    char tester;
    char str_ch[30];
    int j;

    //interrupt service routine
    #int_rda
    void serial_isr( ){
    tester=getc( );
    str_ch[j]=tester;
    j=j+1;
    }


    //main programm
    void main( )
    {
    int k;
    j=0;


    enable_interrupts(int_rda);
    enable_interrupts(GLOBAL);

    //read data from this file in memory card
    printf("O 1R>DSAMP.LOG\X0d");
    for(k=0;k<2;k++){
    //read 2 bytes of data
    printf("R 1^>2\X0d");
    //at this point it should enter interrupt service routine.
    // but tht does not happen


    }


    //write the read data to this file
    printf("O 2W>VOLTASTR.LOG\X0d");
    for(k=0;k<j;k++){
    printf("character is %c\n",str_ch[k]);
    }
    delay_ms(1);
    printf("C 1\X0d");

    delay_ms(1);
    printf("C 2\X0d");
    }


    any help wud be greatly appreciated.
     
  2. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    Just re-indenting your source, and using CODE blocks to preserve the formatting.

    Code ( (Unknown Language)):
    1. #include <16F877A.h>
    2. #fuses HS,NOLVP,NOWDT,PUT,NOBROWNOUT
    3. #use delay(clock=10000000)
    4. #use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
    5.  
    6. char tester;
    7. char str_ch[30];
    8. int j;
    9.  
    10. //interrupt service routine
    11. #int_rda
    12. void serial_isr( ){
    13.     tester=getc( );
    14.     str_ch[j]=tester;
    15.     j=j+1;
    16. }
    17.  
    18.  
    19. //main programm
    20. void main( )
    21. {
    22.     int k;
    23.     j=0;
    24.  
    25.     enable_interrupts(int_rda);
    26.     enable_interrupts(GLOBAL);
    27.  
    28.     //read data from this file in memory card
    29.     printf("O 1R>DSAMP.LOG\X0d");
    30.     for(k=0;k<2;k++){
    31.         //read 2 bytes of data
    32.         printf("R 1^>2\X0d");
    33.         //at this point it should enter interrupt service routine.
    34.         // but tht does not happen
    35.  
    36.     }
    37.  
    38.     //write the read data to this file
    39.     printf("O 2W>VOLTASTR.LOG\X0d");
    40.     for(k=0;k<j;k++){
    41.         printf("character is %c\n",str_ch[k]);
    42.     }
    43.     delay_ms(1);
    44.     printf("C 1\X0d");
    45.  
    46.     delay_ms(1);
    47.     printf("C 2\X0d");
    48. }
    49.  
     
Loading...