IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C Discussion :

Probleme de lecture avec EEPROM


Sujet :

C

  1. #1
    Membre du Club
    Profil pro
    Developer
    Inscrit en
    Juin 2004
    Messages
    194
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations professionnelles :
    Activité : Developer

    Informations forums :
    Inscription : Juin 2004
    Messages : 194
    Points : 58
    Points
    58
    Par défaut Probleme de lecture avec EEPROM
    Bonjour,

    j'ai un drôle de problème qui concerne encore un sujet sur l'eeprom,
    voila je fait une ecriture a des adresses d'eeprom
    et je faits une lecture à l'initialisation des datas se trouvant à ces
    adresses puis je fait un printf des datas mais ça ne correspond pas après le reset
    du microcontrolleur, pourquoi pourtant mon code semble logique ?


    voici la capture après le reset:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
     
    Relisez les priorités attribuées puis corriger
     Priority MIC >> PA set to : 1Ah
    Priority GUI >> PA set to : 3h
    Priority RAD >> PA set to : 3h
    Priority AUX >> PA set to : 2h
    Priority IN1 set to : 2h
    Priority IN2 set to : 6h
    Priority IN3 set to : 6h
    Read 1
    Write 1
    CS0 1
    CS1 1
    CS0 0
    CS1 1
    AO 1
    A1 1
    A2 1
    PIO_PWR 0
    PIO_RESET 0
    -> Please press any key to exit
    voici la capture lors de la configuration, ecriture:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
     
     
    Relisez les priorités attribuées puis corriger
     Priority MIC >> PA set to : 3h
    Priority GUI >> PA set to : 4h
    Priority RAD >> PA set to : 2h
    Priority AUX >> PA set to : 5h
    Priority IN1 set to : 6h
    Priority IN2 set to : 7h
    Priority IN3 set to : 8h
    Read 1
    Write 1
    CS0 1
    CS1 1
    CS0 0
    CS1 1
    AO 1
    A1 1
    A2 1
    PIO_PWR 0
    PIO_RESET 0
    -> Please press any key to exit
    Les fonctions basiques :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
     
    /**********************************************************************************
    Function: EEP2408_write_byte
    ***********************************************************************************/
    void EEP2408_write_byte(unsigned char MyByte1, unsigned char MyByte2)
    {
      I2C_TEA6320 = 0;
      I2C_PCF8574 = 0;
      I2C_EEPwrit = 1;	
      I2C_EEPread = 0;
     
      EA = 1;
      I2C_Byte1 = MyByte1; 				// Word Address
      I2C_Byte2 = MyByte2; 				// Data
      I2C_Status = I2C_BUSY;  			// I2C is now busy
      SSCON = 0xC0; 					// enable I2C - no acknowledgements will be generated
      SSCON = SSCON | 0x20; 			// request to transmit a start condition 
     
      while(I2C_Status == I2C_BUSY); 	// wait until I2C is no longer busy
      SSDAT = 0xFF;		//re-init SSDAT
    }
     
    /**********************************************************************************
    Function: EEP2408_read_byte
    ***********************************************************************************/
    void EEP2408_read_byte(unsigned char MyByte1)
    {
      I2C_TEA6320 = 0;
      I2C_PCF8574 = 0;
      I2C_EEPwrit = 0;	
      I2C_EEPread = 1;
     
      EA = 1;
      I2C_Byte1 = MyByte1; 				// Word Address
      I2C_Status = I2C_BUSY;  			// I2C is now busy
      SSCON = 0xC0; 					// enable I2C - no acknowledgements will be generated
      SSCON = SSCON | 0x20; 			// request to transmit a start condition 
     
      while(I2C_Status == I2C_BUSY); 	// wait until I2C is no longer busy
      SSDAT = 0xFF;		//re-init SSDAT
    }


    La fonction à l'initialisation et où je suis sur que le programme passe (test1 = 0 à l'init):

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
     
     
     
    void init_priority(void)
    {
    if (Test1 == 0)
            {
            EEP2408_ADDRESS = 0x05;
    		EEP2408_read_byte(EEP2408_ADDRESS);
     
    		#ifdef DEBUG_ME2   //testali0304
    		printf("\n");
            #endif            //testali0304
        	prior_MicDrive = EEP_READ;
    		pm = EEP_READ;
     
            EEP2408_ADDRESS = 0x06;
    		EEP2408_read_byte(EEP2408_ADDRESS);
    		#ifdef DEBUG_ME2   //testali0304
    		printf("\n");
            #endif            //testali0304
    		prior_MicGui = EEP_READ;
    		pg = EEP_READ;
     
            EEP2408_ADDRESS = 0x07;
    		EEP2408_read_byte(EEP2408_ADDRESS);
    		#ifdef DEBUG_ME2   //testali0304
    		printf("\n");
            #endif            //testali0304
    		prior_Rad = EEP_READ;
    		pr = EEP_READ;
     
            EEP2408_ADDRESS = 0x08;
    		EEP2408_read_byte(EEP2408_ADDRESS);
    		#ifdef DEBUG_ME2   //testali0304
    		printf("\n");
            #endif            //testali0304
    		prior_Aux = EEP_READ;
    		pa = EEP_READ;
     
            EEP2408_ADDRESS = 0x09;
    		EEP2408_read_byte(EEP2408_ADDRESS);
    		#ifdef DEBUG_ME2   //testali0304
    		printf("\n");
            #endif            //testali0304
    		prior_IN1 = EEP_READ;
    		pIN1 = EEP_READ;
     
            EEP2408_ADDRESS = 0x0A;
    		EEP2408_read_byte(EEP2408_ADDRESS);
    		#ifdef DEBUG_ME2   //testali0304
    		printf("\n");
            #endif            //testali0304
    		prior_IN2 = EEP_READ;
    		pIN2 = EEP_READ;
     
            EEP2408_ADDRESS = 0x0B;
    		EEP2408_read_byte(EEP2408_ADDRESS);
    		#ifdef DEBUG_ME2   //testali0304
    		printf("\n");
            #endif            //testali0304
    		prior_IN3 = EEP_READ;
    		pIN3 = EEP_READ;
     
    		}
    		Test1 = 1;
     
    }
    la fonction pour afficher les datas :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
     
     
     
    /*************************************************************************************
    Function: debug_prior
    Remarque: Pémermet de débuger des erreurs à l'attribution des priorités
    **************************************************************************************/
    void debug_prior(void)
    {
       #ifdef DEBUG_MEPrior   //testali0304
       printf ("Relisez les priorités attribuées puis corriger\n\r ");
       printf ("Priority MIC >> PA set to : %Xh\n\r",prior_MicDrive);
       printf ("Priority GUI >> PA set to : %Xh\n\r",prior_MicGui);
       printf ("Priority RAD >> PA set to : %Xh\n\r",prior_Rad);
       printf ("Priority AUX >> PA set to : %Xh\n\r",prior_Aux);
       printf ("Priority IN1 set to : %Xh\n\r",prior_IN1);
       printf ("Priority IN2 set to : %Xh\n\r",prior_IN2);
       printf ("Priority IN3 set to : %Xh\n\r",prior_IN3);
       #endif            //testali0304
     
        Read = P3_7;
        Write = P3_6;
     
        MIC = P1_0;
        RAD = P1_1;
        C_select1 = P5_2;  //0605 re
        C_select2 = P5_3;  //0605 re
        A_O = P0_0;
        A_1 = P0_1;
        A_2 = P0_2;
        PIO_WR = P5_0;
        PIO_RESET = P4_2;  //0605 re
     
       #ifdef DEBUG_MEPrior   //testali0304
    	printf("Read %X\n",Read);
        printf("Write %X\n", Write);
        printf("CS0 %X\n", CS0);
        printf("CS1 %X\n", CS1);
        printf("CS0 %X\n", C_select1);  //0605 ajout
        printf("CS1 %X\n", C_select2);  //0605 ajout
     
        printf("AO %X\n", A_O);
        printf("A1 %X\n", A_1);
        printf("A2 %X\n", A_2);
        printf("PIO_PWR %X\n", PIO_WR);
        printf("PIO_RESET %X\n", PIO_RESET);
       #endif            //testali0304
     
    }


    Enfin les routines du menu pour voir et configurer les priorités donc
    pour ecrire dans l'eeprom.


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
     
     
    // r: To read priority
    	if (STR_IN[31]==0x72)/*||(STR_IN[31]==0x6F))*/
    	{
            debug_prior();
    		Menu_Flag=0;
    #ifdef DEBUG_MEPrior    //testali0304
    		printf("-> Please press any key to exit\n");
    #endif            //testali0304
     
    		for (j=0;j<32;j++) STR_IN[j]=STR_IN[j+1];
    		STR_IN[31]=getchar0();
    #ifdef DEBUG_MEPrior    //testali0304
    	  	printf("%c\n",STR_IN[31]);
    #endif            //testali0304
    	}
     
    // Q: Change Priority 
    if (STR_IN[31]==0x51) /*||(STR_IN[31]==0x71))*/
    {
    #ifdef DEBUG_MEPrior    //testali0304
    printf ("\nVeillez suivre les intructions SVP\n\r"); 
    printf ("\n!CAUTION: Les priorités sont comprises entre 02-->08 inclus \n\r");
    #endif            //testali0304
    ordre = 1;
                  do
    			  {
     if (ordre == 1)
     { 
    ordre = 2;
    prior_cond = 0x00;
    EEP2408_ADDRESS = 0x05;
    #ifdef DEBUG_MEPrior    //testali0304
    printf("La priorité actuel du MIC >> PA est : %Xh\n",prior_MicDrive);
    printf("Introsuisez l'ordre de priorité pour MIC >> PA + <INTER>\n");
    #endif            //testali0304
    		do		
    		{
    			for (j=0;j<32;j++) STR_IN[j]=STR_IN[j+1];
    			STR_IN[31]=getchar0();
    #ifdef DEBUG_MEPrior    //testali0304
    		  	printf("%c",STR_IN[31]);
    #endif            //testali0304
     
    		}
    		while (STR_IN[31]!=0x0D);
    #ifdef DEBUG_MEPrior    //testali0304
    	  	printf("\n\r");
    #endif            //testali0304
     
    		switch (STR_IN[29]) 
     	    {
    			case 0x30:EEP2408_VALUE = 0x00; break;
    			default:
    #ifdef DEBUG_MEPrior    //testali0304
    		            printf("ERROR WRONG PRIORITY Please Try again!\n\r");
    #endif            //testali0304
     
                        ordre = 1;
    					EEP2408_VALUE = 0xEE;
    					prior_cond = 0x01;
    			break;
    		}
     
    		  if ( STR_IN[29] == 0x30)
    		  {
    		switch (STR_IN[30])
     	    {
    			case 0x32:EEP2408_VALUE+= 0x02; break;
    			case 0x33:EEP2408_VALUE+= 0x03; break;
    			case 0x34:EEP2408_VALUE+= 0x04; break;
    			case 0x35:EEP2408_VALUE+= 0x05; break;
    			case 0x36:EEP2408_VALUE+= 0x06; break;
    			case 0x37:EEP2408_VALUE+= 0x07; break;
    			case 0x38:EEP2408_VALUE+= 0x08; break;
    			default: 
    #ifdef DEBUG_MEPrior    //testali0304
    		            printf("ERROR WRONG PRIORITY Please Try again!\n\r");
    #endif            //testali0304
     
                        ordre = 1;
    					EEP2408_VALUE = 0xEE;
    					prior_cond = 0x01;
    			break;
    		}
    #ifdef DEBUG_MEPrior    //testali0304
    printf(" DATA %Xh\n",EEP2408_VALUE);
    #endif            //testali0304
     
    prior_MicDrive = EEP2408_VALUE;
    pm = EEP2408_VALUE; // WARNING CHAR >< INT
    Menu_Flag=0;
    EEP2408_write_byte(EEP2408_ADDRESS,EEP2408_VALUE); // Ecrit dans le EEPROM à l'adresse 05
     
        }
     }
     
     if (ordre == 2)
     { 
    ordre = 3;
    prior_cond = 0x00;
    EEP2408_ADDRESS = 0x06;
    #ifdef DEBUG_MEPrior    //testali0304
    printf("La priorité actuel du GUIDE >> PA est : %Xh\n",prior_MicGui);
    printf("Introsuisez l'ordre de priorité pour GUIDE >> PA + <INTER>\n");
    #endif            //testali0304
     
    		do		
    		{
    			for (j=0;j<32;j++) STR_IN[j]=STR_IN[j+1];
    			STR_IN[31]=getchar0();
    #ifdef DEBUG_MEPrior    //testali0304
    		  	printf("%c",STR_IN[31]);
    #endif            //testali0304
     
    		}
    		while (STR_IN[31]!=0x0D);
    #ifdef DEBUG_MEPrior    //testali0304
    	  	printf("\n\r");
    #endif            //testali0304
     
    		switch (STR_IN[29]) 
     	    {
    			case 0x30:EEP2408_VALUE = 0x00; break;
    			default: 
    #ifdef DEBUG_MEPrior    //testali0304
    		            printf("ERROR WRONG PRIORITY Please Try again!\n\r");
    #endif            //testali0304
                        ordre = 2;
    					EEP2408_VALUE = 0xEE;
    					prior_cond = 0x01;
    			break;
    		}
     
    		  if ( STR_IN[29] == 0x30)
    		  {
    		switch (STR_IN[30])
     	    {
    			case 0x32:EEP2408_VALUE+= 0x02; break;
    			case 0x33:EEP2408_VALUE+= 0x03; break;
    			case 0x34:EEP2408_VALUE+= 0x04; break;
    			case 0x35:EEP2408_VALUE+= 0x05; break;
    			case 0x36:EEP2408_VALUE+= 0x06; break;
    			case 0x37:EEP2408_VALUE+= 0x07; break;
    		    case 0x38:EEP2408_VALUE+= 0x08; break;
    			default: 
    #ifdef DEBUG_MEPrior    //testali0304
    		            printf("ERROR WRONG PRIORITY Please Try again!\n\r");
    #endif            //testali0304
     
                        ordre = 2;
    					EEP2408_VALUE = 0xEE;
    					prior_cond = 0x01;
    			break;
    		}
    #ifdef DEBUG_MEPrior    //testali0304
    printf(" DATA %Xh\n",EEP2408_VALUE);
    #endif            //testali0304
     
    prior_MicGui = EEP2408_VALUE;
    pg = EEP2408_VALUE; // WARNING CHAR >< INT
    Menu_Flag=0;
    EEP2408_write_byte(EEP2408_ADDRESS,EEP2408_VALUE); // Ecrit dans le EEPROM à l'adresse 06
    if (prior_MicDrive == prior_MicGui)
       {
       ordre = 2;
       prior_cond1 = 0x01;
    #ifdef DEBUG_MEPrior    //testali0304
       printf("ERROR!!La Priorité %X déjà Attribuée!! Please Try again!\n\r",EEP2408_VALUE);
    #endif            //testali0304
       }
    else {prior_cond1 = 0x00;}
     
        }
     }
     
      if (ordre == 3)
     { 
    ordre = 4;
    prior_cond = 0x00;
    EEP2408_ADDRESS = 0x07;
    #ifdef DEBUG_MEPrior    //testali0304
    printf("La priorité actuel du RAD >> PA est : %Xh\n",prior_Rad);
    printf("Introsuisez l'ordre de priorité pour RAD >> PA + <INTER>\n");
    #endif            //testali0304
    		do		
    		{
    			for (j=0;j<32;j++) STR_IN[j]=STR_IN[j+1];
    			STR_IN[31]=getchar0();
    #ifdef DEBUG_MEPrior    //testali0304
    		  	printf("%c",STR_IN[31]);
    #endif            //testali0304
    		}
    		while (STR_IN[31]!=0x0D);
     
    ......

    Pouvez vous dire la raison pour laquelle la capture après
    le reset n'est pas la même?

    Merci

  2. #2
    Membre du Club
    Profil pro
    Developer
    Inscrit en
    Juin 2004
    Messages
    194
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations professionnelles :
    Activité : Developer

    Informations forums :
    Inscription : Juin 2004
    Messages : 194
    Points : 58
    Points
    58
    Par défaut
    Rebonjour,

    Autre chose tres important a preciser c est que lorsque je charge dans le microcontrolleur un autre programme, ce programme me montre bien les valeurs que j avais ecrit dans le registre autrement dit il semble que le probleme vient soit dans la lecture soit qqlpart dans le programme qui vient ecraser les datas de l eeprom a leurs adresses ?

    C est fort urgent car ca bloque mon application et c est tres genant il faut a chaque fois rentrer manuellement les configs. Si vous pouvez m aider s il vous plaits

    Merci

  3. #3
    Membre éclairé
    Avatar de bpy1401
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2003
    Messages
    471
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2003
    Messages : 471
    Points : 831
    Points
    831
    Par défaut
    Bonjour Aliveli

    Si j'ai bien compris, ton Eeprom est une eeprom externe reliée à ton Micro par un bus I2C.

    Pour lire une donnée, tu utilise le code suivant

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
        EEP2408_ADDRESS = 0x05;
        EEP2408_read_byte(EEP2408_ADDRESS);
        prior_MicDrive = EEP_READ;
        pm = EEP_READ;
    C'est quoi EEP_READ: Dans le code que tu donne, on ne fait que le lire, mais on n'ecrit jamais dedans.

    Autre question, les eeprom prennent un certain temps pour ecrire (5 ms en moyenne). je ne vois nulle part un test pour voir si ton eeprom a fini son écriture.

    A+
    Page sur Developpez : http://pbriand.developpez.com

  4. #4
    Membre du Club
    Profil pro
    Developer
    Inscrit en
    Juin 2004
    Messages
    194
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations professionnelles :
    Activité : Developer

    Informations forums :
    Inscription : Juin 2004
    Messages : 194
    Points : 58
    Points
    58
    Par défaut
    Salut BriandPatrick,

    Exact, l' Eeprom est une eeprom externe reliée à ton Micro par un bus I2C.
    voila EEP_READ est affecté par une routine i²c, voici le code mais simplement à titre informatif donc inutile de perdre trop de temps la dessus:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
     
    /**********************************************************************************
    Function: i2c_isr
    Remarque: I2C interrupt service routine. An interrupt is requested whenever an event occurs
                      on the I2C bus causing the I2C peripheral to change state
                      The state is held in the SSSTA SFR
                      nothing is passed. nothing is returned.
                      note: if debugging printfs are inserted into this function the execution
                      will be slowed down to the point where the timeout occurs.
    ***********************************************************************************/
     
    void i2c_isr(void) interrupt 8 using 3
    {
    	//printf("  I2C Interrupt\n");
    	//printf("SSSTA  = %X\n",SSSTA);
    	if (I2C_TEA6320) 
    	{
    		switch(SSSTA)
    		{
    		    // START CONDITION TRANSMITTED
    		    case 0x08:
    		  	  //printf("case 0x08\n");
    			  SSCON = SSCON & 0xDF;  			// clear start condition flag so another start condition is not requested 
    			  SSDAT = TEA6320_ADDRESS; 			// transmit slave address + write command (SLA + W)
    			  compteur = 0;
    			  start_timer();  					// start timer 0 to start measuring the timeout period
    		      break;
     
    			// REPEATED START CONDITION TRANSMITTED
    		    case 0x10:
    		  	  //printf("case 0x10\n");
    		      SSCON = SSCON & 0xDF;  			// clear start condition flag so another start condition is not requested
    		      SSDAT = TEA6320_ADDRESS; 			// transmit slave address + write command (SLA + W)
    		 										// this situation will arise if no response was received from TEA6320
    		 										// and another attempt is being made
    		      break;
     
    			// SLAVE ADDRESS + WRITE TRANSMITTED - ACK RECEIVED
    		    case 0x18:
    		  	  //printf("case 0x18\n");
    			  stop_timer();  					// stop timer 0 - a response was received within the timeout period
    		      SSDAT = I2C_Byte1; 				// transmit data byte
    		      break;
     
    			// SLAVE ADDRESS + WRITE TRANSMITTED - NO ACK RECEIVED
    		    case 0x20:
    		  	  //printf("case 0x20\n");
    			  if (TF0) 							// if timer 0 overflowed then timeout period reached. no response.
    			  {
    			    SSCON = SSCON | 0x10; 			// request to transmit a stop condition
    				stop_timer(); 					// stop timer 0
    				I2C_Status = I2C_ERROR;  		// status of operation is ERROR
    			  }
    			  else
    			  {
    		        SSCON = SSCON | 0x20;  			// request to transmit a repeated start - try again to communicate
    			  }
    		      break;
     
    			// DATA BYTE TRANSMITTED - ACK RECEIVED
    		    case 0x28:
    		  	  //printf("case 0x28\n");
    			  compteur++;
    			  switch(compteur)
    			  {
    			  case 0x01:
    			  	SSDAT = I2C_Byte2;
    				//printf("case 0x01\n");
    			  	break;
    			  case 0x02:
    			  	SSCON =SSCON & 0xDF;
    			  	SSCON = SSCON | 0x10;  			// request to transmit a stop condition
    			  	compteur = 0;
    			  	I2C_Status = I2C_OK; 			// status of operation is OK
    				EA = 0;
    				//printf("case 0x02\n");
    			  	break;
    			  }
    			  break;
     
    			// DATA BYTE TRANSMITTED - NO ACK RECEIVED
    			case 0x30:
    		  	  //printf("case 0x30\n");
    			  SSCON = SSCON | 0x10; 			// no response. request to transmit a stop condition
    			  I2C_Status = I2C_ERROR; 			// status of operation is ERROR
    		      break;
     
    			// UNKNOWN STATE
    		    default:
    		  	  //printf("case default\n");
    			  SSCON = SSCON | 0x10; 			// request to transmit stop condition
    			  I2C_Status = I2C_ERROR; 			// status of operation is ERROR
    			  IEN1 = IEN1 & 0xFD;  				// disable the I2C interrupt
    			  break;
    	  	} //switch(SSSTA)...
    	} //if (I2C_TEA6320)...
     
    	if (I2C_PCF8574) 
    	{
    		switch(SSSTA)
    		{
    			// START CONDITION TRANSMITTED
    		    case 0x08:
    		  	  //printf("case 0x08\n");
    			  SSCON&= 0xDF;  			// clear start condition flag so another start condition is not requested 
    			  SSDAT = PCF8574_ADDRESS; 	// transmit slave address + write command (SLA + W)
    			  compteur = 0;
    			  start_timer();  			// start timer 0 to start measuring the timeout period
    		      break;
     
    			// REPEATED START CONDITION TRANSMITTED
    		    case 0x10:
    		  	  //printf("case 0x10\n");
    		      SSCON&= 0xDF;  			// clear start condition flag so another start condition is not requested
    		      SSDAT = PCF8574_ADDRESS; 	// transmit slave address + write command (SLA + W)
    		 								// this situation will arise if no response was received from TEA6320
    		 								// and another attempt is being made
    		      break;
     
    			// SLAVE ADDRESS + WRITE TRANSMITTED - ACK RECEIVED
    		    case 0x18:
    		  	  //printf("case 0x18\n");
    			  stop_timer();  			// stop timer 0 - a response was received within the timeout period
    		      SSDAT = I2C_Byte1; 		// transmit data byte
    		      break;
     
    			// SLAVE ADDRESS + WRITE TRANSMITTED - NO ACK RECEIVED
    		    case 0x20:
    		  	  //printf("case 0x20\n");
    			  if (TF0) 					// if timer 0 overflowed then timeout period reached. no response.
    			  {
    			    SSCON|= 0x10; 			// request to transmit a stop condition
    				stop_timer(); 			// stop timer 0
    				I2C_Status = I2C_ERROR; // status of operation is ERROR
    			  }
    			  else
    			  {
    		        SSCON|= 0x20;  			// request to transmit a repeated start - try again to communicate
    			  }
    		      break;
     
    			// DATA BYTE TRANSMITTED - ACK RECEIVED
    		    case 0x28:
    			  //printf("case 0x28\n");
    			  SSCON&= 0xDF;
    			  SSCON|= 0x10;  			// request to transmit a stop condition
    			  compteur = 0;
    			  I2C_Status = I2C_OK; 		// status of operation is OK
    			  EA = 0;
    			  break;
     
    			// DATA BYTE TRANSMITTED - NO ACK RECEIVED
    			case 0x30:
    		  	  //printf("case 0x30\n");
    			  SSCON|= 0x10; 			// no response. request to transmit a stop condition
    			  I2C_Status = I2C_ERROR; 	// status of operation is ERROR
    		      break;
     
    			// UNKNOWN STATE
    		    default:
    		  	  //printf("case default\n");
    			  SSCON|= 0x10; 			// request to transmit stop condition
    			  I2C_Status = I2C_ERROR; 	// status of operation is ERROR
    			  IEN1&= 0xFD;  			// disable the I2C interrupt
    			  break;
    	  	} //switch(SSSTA)...
    	} //if (I2C_PCF8574)...
     
    	if (I2C_EEPwrit) 
    	{
    		switch(SSSTA)
    		{
    		    // START CONDITION TRANSMITTED
    		    case 0x08:
    		  	  //printf("case 0x08\n");
    			  SSCON&= 0xDF;  			// clear start condition flag so another start condition is not requested 
    			  SSDAT = EEP2408_ADDRESS; 	// transmit slave address + write command (SLA + W)
    			  compteur = 0;
    			  start_timer();			// start timer 0 to start measuring the timeout period
    		      break;
     
    			// REPEATED START CONDITION TRANSMITTED
    		    case 0x10:
    		  	  //printf("case 0x10\n");
    		      SSCON&= 0xDF;  			// clear start condition flag so another start condition is not requested
    		      SSDAT = EEP2408_ADDRESS; 	// transmit slave address + write command (SLA + W)
    		 								// this situation will arise if no response was received from TEA6320
    		 								// and another attempt is being made
    		      break;
     
    			// SLAVE ADDRESS + WRITE TRANSMITTED - ACK RECEIVED
    		    case 0x18:
    		  	  //printf("case 0x18\n");
    			  stop_timer();  			// stop timer 0 - a response was received within the timeout period
    		      SSDAT = I2C_Byte1;		// transmit data byte
    		      break;
     
    			// SLAVE ADDRESS + WRITE TRANSMITTED - NO ACK RECEIVED
    		    case 0x20:
    		  	  //printf("case 0x20\n");
    			  if (TF0) 					// if timer 0 overflowed then timeout period reached. no response.
    			  {
    			    SSCON|= 0x10; 			// request to transmit a stop condition
    				stop_timer(); 			// stop timer 0
    				I2C_Status = I2C_ERROR; // status of operation is ERROR
    			  }
    			  else
    			  {
    		        SSCON|= 0x20;  			// request to transmit a repeated start - try again to communicate
    			  }
    		      break;
     
    			// DATA BYTE TRANSMITTED - ACK RECEIVED
    		    case 0x28:
    		  	  //printf("case 0x28\n");
    			  compteur++;
    			  switch(compteur)
    			  {
    			  case 0x01:
    			  	SSDAT = I2C_Byte2;
    				//printf("case 0x01\n");
    			  	break;
    			  case 0x02:
    			  	SSCON&= 0xDF;
    			  	SSCON|= 0x10;  			// request to transmit a stop condition
    			  	compteur = 0;
    			  	I2C_Status = I2C_OK; 	// status of operation is OK
    				EA = 0;
    				//printf("case 0x02\n");
    			  	break;
    			  }
    			  break;
     
    			// DATA BYTE TRANSMITTED - NO ACK RECEIVED
    			case 0x30:
    		  	  //printf("case 0x30\n");
    			  SSCON|= 0x10; 			// no response. request to transmit a stop condition
    			  I2C_Status = I2C_ERROR; 	// status of operation is ERROR
    		      break;
     
    			// UNKNOWN STATE
    		    default:
    		  	  //printf("case default\n");
    			  SSCON|= 0x10; 			// request to transmit stop condition
    			  I2C_Status = I2C_ERROR; 	// status of operation is ERROR
    			  IEN1&=  0xFD;  			// disable the I2C interrupt
    			  break;
    	  	} //switch(SSSTA)...
    	} //if (I2C_EEPwrit)...
     
    	if (I2C_EEPread) 
    	{
    		switch(SSSTA)
    		{
    		    // START CONDITION TRANSMITTED
    		    case 0x08:
    		  	  //printf("08\n");
    			  SSCON&= 0xDF;  				// clear start condition flag so another start condition is not requested 
    			  SSDAT = EEP2408_ADDRESS;	// transmit slave address + write command (SLA + W)
    			  compteur = 0;
    			  start_timer();				// start timer 0 to start measuring the timeout period
    		      break;
     
    			// REPEATED START CONDITION TRANSMITTED
    		    case 0x10:
    		  	  //printf("10\n");
    		      SSCON&= 0xDF;  				// clear start condition flag so another start condition is not requested
    		      SSDAT = EEP2408_ADDRESS|0x01; // transmit slave address + write command (SLA + R)
    		 									// this situation will arise if no response was received from TEA6320
    		 									// and another attempt is being made
    		      break;
     
    			// SLAVE ADDRESS + WRITE TRANSMITTED - ACK RECEIVED
    		    case 0x18:
    		  	  //printf("18\n");
    			  stop_timer();  			// stop timer 0 - a response was received within the timeout period
    		      SSDAT = I2C_Byte1;		// transmit data byte
    		      break;
     
    			// SLAVE ADDRESS + WRITE TRANSMITTED - NO ACK RECEIVED
    		    case 0x20:
    		  	  //printf("20\n");
    			  if (TF0) 					// if timer 0 overflowed then timeout period reached. no response.
    			  {
    			    SSCON|= 0x10; 			// request to transmit a stop condition
    				stop_timer(); 			// stop timer 0
    				I2C_Status = I2C_ERROR; // status of operation is ERROR
    			  }
    			  else
    			  {
    		        SSCON|= 0x20;  			// request to transmit a repeated start - try again to communicate
    			  }
    		      break;
     
    			// DATA BYTE TRANSMITTED - ACK RECEIVED
    		    case 0x28:
    		  	  //printf("28\n");
    			  compteur++;
    			  switch(compteur)
    			  {
    			  case 0x01:
    			  	SSCON|= 0x20;  			// request to transmit a Start condition
    				//printf("case 0x01\n");
    			  	break;
    			  case 0x02:
    			  	SSCON&= 0xDF;
    			  	SSCON|= 0x10;  			// request to transmit a stop condition
    			  	compteur = 0;
    			  	I2C_Status = I2C_OK; 	// status of operation is OK
    				EA = 0;
    				//printf("case 0x02\n");
    			  	break;
    			  }
    			  break;
     
    			// DATA BYTE TRANSMITTED - NO ACK RECEIVED
    			case 0x30:
    		  	  //printf("30\n");
    			  SSCON|= 0x10; 			// no response. request to transmit a stop condition
    			  I2C_Status = I2C_ERROR; 	// status of operation is ERROR
    		      break;
     
    			// SUCCESS RECEPTION FROM A SLAVE TRANSMITTER
    			case 0x40:
    		  	  //printf("40\n");
      			  I2C_Status = I2C_OK; 	// status of operation is OK
    		      break;
     
    			// SUCCESS RECEPTION FROM A SLAVE TRANSMITTER - NO ACK RECEIVED
    			case 0x58:
    		  	  //printf("58\n");
    			  SSCON|= 0x10;  			// request to transmit a stop condition
    			  EEP_READ = SSDAT;
    			  //EEP_OK=1;
    			  if ((Test == 1)&&(Test1 == 1)) // Affiche EEP_READ que lorsque on veut lire.  voir aussi ADC
    			  {
    			 // printf("EEP_READ: %Xh\n",EEP_READ); //testali0304
    			  }
    			  I2C_Status = I2C_OK; 	// status of operation is OK
    		      break;
     
    			// UNKNOWN STATE
    		    default:
    		  	  //printf("default\n");
    			  SSCON|= 0x10; 			// request to transmit stop condition
    			  I2C_Status = I2C_ERROR; 	// status of operation is ERROR
    			  IEN1&=  0xFD;  			// disable the I2C interrupt
    			  break;
    	  	} //switch(SSSTA)...
    	} //if (I2C_EEPread)...
     
    	SSCON = SSCON & 0xF7; 				// clear the I2C interrupt flag. This causes the next event on the
     										// I2C bus to be performed, possibly resulting in the request of
     										// another I2C interrupt
    }
    Pour l'ecriture j'ai fait un autre type mais c'est vrai que ici j'ai pas de temps mais ça va tout de même bien:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
     
    ..
    seuil_bas1=seuil_bas;
     
    EEP2408_ADDRESS = 0x67;  //addresse du seuil_bas niveau 0  //0306
    EEP2408_VALUE = seuil_bas>>8;
    EEP2408_write_byte(EEP2408_ADDRESS,EEP2408_VALUE);
     
    EEP2408_ADDRESS = 0x68;  //addresse du seuil_bas niveau 0
    EEP2408_VALUE = (seuil_bas & 0xff);
    EEP2408_write_byte(EEP2408_ADDRESS,EEP2408_VALUE);
     
     
     
    seuil_haut1=seuil_haut;
     
    EEP2408_ADDRESS = 0x69;  //addresse du seuil_haut niveau 0
    EEP2408_VALUE = seuil_haut>>8;
    EEP2408_write_byte(EEP2408_ADDRESS,EEP2408_VALUE);
     
    EEP2408_ADDRESS = 0x70;  //addresse du seuil_haut niveau 0
    EEP2408_VALUE = (seuil_haut & 0xff);
    EEP2408_write_byte(EEP2408_ADDRESS,EEP2408_VALUE);
    ..
    Ce que je ne comprend pas trop dans la lecture c'est les printf () entre :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
     
    void init_priority(void)
    {
    if (Test1 == 0)
            {
            EEP2408_ADDRESS = 0x05;
    		EEP2408_read_byte(EEP2408_ADDRESS);
     
    		#ifdef DEBUG_ME2   //testali0304
    		printf("\n");
            #endif            //testali0304
        	prior_MicDrive = EEP_READ;
    		pm = EEP_READ;
     
            EEP2408_ADDRESS = 0x06;
    		EEP2408_read_byte(EEP2408_ADDRESS);
    		#ifdef DEBUG_ME2   //testali0304
    		printf("\n");
            #endif            //testali0304
    		prior_MicGui = EEP_READ;
    		pg = EEP_READ;
     
            EEP2408_ADDRESS = 0x07;
    		EEP2408_read_byte(EEP2408_ADDRESS);
    		#ifdef DEBUG_ME2   //testali0304
    		printf("\n");
            #endif            //testali0304
    		prior_Rad = EEP_READ;
    		pr = EEP_READ;
     
            EEP2408_ADDRESS = 0x08;
    		EEP2408_read_byte(EEP2408_ADDRESS);
    		#ifdef DEBUG_ME2   //testali0304
    		printf("\n");
            #endif            //testali0304
    		prior_Aux = EEP_READ;
    		pa = EEP_READ;
     
            EEP2408_ADDRESS = 0x09;
    		EEP2408_read_byte(EEP2408_ADDRESS);
    		#ifdef DEBUG_ME2   //testali0304
    		printf("\n");
            #endif            //testali0304
    		prior_IN1 = EEP_READ;
    		pIN1 = EEP_READ;
     
            EEP2408_ADDRESS = 0x0A;
    		EEP2408_read_byte(EEP2408_ADDRESS);
    		#ifdef DEBUG_ME2   //testali0304
    		printf("\n");
            #endif            //testali0304
    		prior_IN2 = EEP_READ;
    		pIN2 = EEP_READ;
     
            EEP2408_ADDRESS = 0x0B;
    		EEP2408_read_byte(EEP2408_ADDRESS);
    		#ifdef DEBUG_ME2   //testali0304
    		printf("\n");
            #endif            //testali0304
    		prior_IN3 = EEP_READ;
    		pIN3 = EEP_READ;
     
    		}
    		Test1 = 1;
     
    }
    Merci

  5. #5
    Membre éclairé
    Avatar de bpy1401
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Mars 2003
    Messages
    471
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France, Eure (Haute Normandie)

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2003
    Messages : 471
    Points : 831
    Points
    831
    Par défaut
    Bonjour aliveli

    Pour moi ton printf ne sert à rien, surtout si DEBUG_ME2 n'est pas défini

    Dans le cas ou il le serait, cela fait une tempo dont tu ne maitrise pas le temps et qui peut faire n'importe quoi, comme par exemple envoyé un \n sur la liaison série pour le débug

    en regardant le code de routine d'interruption , je vois que tu peux sortir en erreur, en mettant à jour la variable I2C_Status. Tu peux donc alors ressortir de ta fonction EEP2408_read_byte, sans avoir lu ta donnée.

    Il serait peut être interressant de tester I2C_Status pour vérifier la validité de ta donnée lue

    A+
    Page sur Developpez : http://pbriand.developpez.com

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Probleme de lecture avec lecteur intégré
    Par jerem432 dans le forum Langage
    Réponses: 2
    Dernier message: 24/12/2012, 00h33
  2. Probleme de lecture avec Internet Explorer
    Par manu7607 dans le forum InfoPath
    Réponses: 5
    Dernier message: 24/09/2009, 17h29
  3. Probleme de lecture avec le second accompte
    Par ndurieu dans le forum VBA Outlook
    Réponses: 2
    Dernier message: 25/02/2009, 09h17
  4. Probleme de lecture avec fichie Excel
    Par msahmi dans le forum ASP.NET
    Réponses: 2
    Dernier message: 11/04/2008, 13h45
  5. Probleme de lecture de fichier swf avec c#
    Par Vince57 dans le forum Windows Forms
    Réponses: 4
    Dernier message: 14/06/2006, 14h18

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo