Les fonction I2C ne semble pas marcher si elle sont appellées trop fréquement. Ajout d'une tempo de 1 ms dans la logique i2c
This commit is contained in:
		
							parent
							
								
									7c9dd0bab3
								
							
						
					
					
						commit
						6857a944ba
					
				
							
								
								
									
										26
									
								
								Test.c
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								Test.c
									
									
									
									
									
								
							| @ -478,6 +478,15 @@ int test_i2c_ecriture_pico_annex_nb(){ | |||||||
|     return 1; |     return 1; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void affiche_contacteur(){ | ||||||
|  |     while(1){ | ||||||
|  |         printf(">contacteur_butee_A:%d\n", i2c_annexe_get_contacteur_butee_A()); | ||||||
|  |         printf(">contacteur_butee_C:%d\n", i2c_annexe_get_contacteur_butee_C()); | ||||||
|  |         printf(">contacteur_longer_A:%d\n", i2c_annexe_get_contacteur_longer_A()); | ||||||
|  |         printf(">contacteur_longer_C:%d\n", i2c_annexe_get_contacteur_longer_C()); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /// @brief Test les fonctions définies dans I2C_Annexe
 | /// @brief Test les fonctions définies dans I2C_Annexe
 | ||||||
| /// @return 1 pour continuer le test, 0 pour arrêter le test
 | /// @return 1 pour continuer le test, 0 pour arrêter le test
 | ||||||
| int test_i2c_ecriture_pico_annex_nb_2(){ | int test_i2c_ecriture_pico_annex_nb_2(){ | ||||||
| @ -500,8 +509,11 @@ int test_i2c_ecriture_pico_annex_nb_2(){ | |||||||
|     int continue_test=1; |     int continue_test=1; | ||||||
| 
 | 
 | ||||||
|     time_i2c[0] = time_us_32(); |     time_i2c[0] = time_us_32(); | ||||||
|  |     time_i2c[1] = time_us_32(); | ||||||
|     time_i2c[2] = 0; |     time_i2c[2] = 0; | ||||||
| 
 | 
 | ||||||
|  |     multicore_launch_core1(affiche_contacteur); | ||||||
|  | 
 | ||||||
|     while(continue_test){ |     while(continue_test){ | ||||||
|         lettre = getchar_timeout_us(0); |         lettre = getchar_timeout_us(0); | ||||||
|         if(lettre != PICO_ERROR_TIMEOUT && lettre != '\0'){ |         if(lettre != PICO_ERROR_TIMEOUT && lettre != '\0'){ | ||||||
| @ -554,23 +566,11 @@ int test_i2c_ecriture_pico_annex_nb_2(){ | |||||||
|             } |             } | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
|         time_i2c[1] = time_us_32(); // Pour mesurer le temps d'execution
 |  | ||||||
|         i2c_gestion(i2c0);         |         i2c_gestion(i2c0);         | ||||||
|         i2c_annexe_gestion(); |         i2c_annexe_gestion(); | ||||||
| 
 | 
 | ||||||
|         printf(">contacteur_butee_A:%d\n", i2c_annexe_get_contacteur_butee_A()); |  | ||||||
|         printf(">contacteur_butee_C:%d\n", i2c_annexe_get_contacteur_butee_C()); |  | ||||||
|         printf(">contacteur_longer_A:%d\n", i2c_annexe_get_contacteur_longer_A()); |  | ||||||
|         printf(">contacteur_longer_C:%d\n", i2c_annexe_get_contacteur_longer_C()); |  | ||||||
| 
 |  | ||||||
|         time_i2c[2] += time_us_32() - time_i2c[1]; // Pour mesurer le temps d'execution
 |  | ||||||
|         sleep_us(100); // Attente, ou le reste du code
 |  | ||||||
|     } |     } | ||||||
|     time_i2c[3] = time_us_32() - time_i2c[0]; |     multicore_reset_core1(); | ||||||
| 
 |  | ||||||
|     printf("Temps lecture : %u microsecondes, temps specifique i2c : %u microsecondes.\n", time_i2c[3], time_i2c[2]); |  | ||||||
| 
 | 
 | ||||||
|     return test_continue_test(); |     return test_continue_test(); | ||||||
| } | } | ||||||
|  | |||||||
							
								
								
									
										28
									
								
								i2c_annexe.c
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								i2c_annexe.c
									
									
									
									
									
								
							| @ -10,28 +10,41 @@ | |||||||
| #define TAILLE_DONNEES_EMISSION 3 | #define TAILLE_DONNEES_EMISSION 3 | ||||||
| #define TAILLE_DONNEES_RECEPTION 13 | #define TAILLE_DONNEES_RECEPTION 13 | ||||||
| 
 | 
 | ||||||
| uint donnees_a_envoyer=0; | 
 | ||||||
| 
 | 
 | ||||||
| uint8_t donnees_emission[TAILLE_DONNEES_EMISSION]; | uint8_t donnees_emission[TAILLE_DONNEES_EMISSION]; | ||||||
| uint8_t donnees_reception[TAILLE_DONNEES_RECEPTION]; | uint8_t donnees_reception[TAILLE_DONNEES_RECEPTION]; | ||||||
| 
 | 
 | ||||||
|  | uint donnees_a_envoyer=0; | ||||||
|  | 
 | ||||||
| void i2c_annexe_gestion(){ | void i2c_annexe_gestion(){ | ||||||
|     static enum { |     static enum { | ||||||
|         EMISSION_DONNEES, |         EMISSION_DONNEES, | ||||||
|  |         EMISSION_TEMPO, | ||||||
|         RECEPTION_DONNEES |         RECEPTION_DONNEES | ||||||
| 
 |  | ||||||
|     } etat_i2c_annexe=EMISSION_DONNEES; |     } etat_i2c_annexe=EMISSION_DONNEES; | ||||||
|  | 
 | ||||||
|     enum i2c_resultat_t retour_i2c; |     enum i2c_resultat_t retour_i2c; | ||||||
|  |     static uint32_t temps; | ||||||
|  |     const uint32_t tempo = 1000; | ||||||
| 
 | 
 | ||||||
|     switch(etat_i2c_annexe){ |     switch(etat_i2c_annexe){ | ||||||
|         case EMISSION_DONNEES: |         case EMISSION_DONNEES: | ||||||
|             if(donnees_a_envoyer){ |             if(donnees_a_envoyer){ | ||||||
|                 retour_i2c = i2c_ecrire_registre_nb(ADRESSE_PICO_ANNEXE, ADRESSE_DEBUT_W, donnees_emission, TAILLE_DONNEES_EMISSION); |                 retour_i2c = i2c_ecrire_registre_nb(ADRESSE_PICO_ANNEXE, ADRESSE_DEBUT_W, donnees_emission, TAILLE_DONNEES_EMISSION); | ||||||
|                 if(retour_i2c == I2C_SUCCES){ |                 if(retour_i2c == I2C_SUCCES){ | ||||||
|                     etat_i2c_annexe = RECEPTION_DONNEES; |                     etat_i2c_annexe = EMISSION_TEMPO; | ||||||
|                     donnees_a_envoyer=0; |                     donnees_a_envoyer=0; | ||||||
|  |                     temps = time_us_32(); | ||||||
|                 } |                 } | ||||||
|             }else{ |             }else{ | ||||||
|  |                 etat_i2c_annexe = EMISSION_TEMPO; | ||||||
|  |                 temps = time_us_32(); | ||||||
|  |             } | ||||||
|  |             break; | ||||||
|  |          | ||||||
|  |         case EMISSION_TEMPO: | ||||||
|  |             if(temps + tempo < time_us_32() ){ | ||||||
|                 etat_i2c_annexe = RECEPTION_DONNEES; |                 etat_i2c_annexe = RECEPTION_DONNEES; | ||||||
|             } |             } | ||||||
|             break; |             break; | ||||||
| @ -40,7 +53,7 @@ void i2c_annexe_gestion(){ | |||||||
|             retour_i2c = i2c_lire_registre_nb(ADRESSE_PICO_ANNEXE, ADRESSE_DEBUT_R, donnees_reception, TAILLE_DONNEES_RECEPTION); |             retour_i2c = i2c_lire_registre_nb(ADRESSE_PICO_ANNEXE, ADRESSE_DEBUT_R, donnees_reception, TAILLE_DONNEES_RECEPTION); | ||||||
|             if(retour_i2c == I2C_SUCCES){ |             if(retour_i2c == I2C_SUCCES){ | ||||||
|                 etat_i2c_annexe = EMISSION_DONNEES; |                 etat_i2c_annexe = EMISSION_DONNEES; | ||||||
| 
 |                 temps = time_us_32(); | ||||||
|             } |             } | ||||||
|             break; |             break; | ||||||
|     } |     } | ||||||
| @ -66,8 +79,11 @@ void i2c_annexe_ferme_porte(void){ | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void i2c_annexe_active_propulseur(void){ | void i2c_annexe_active_propulseur(void){ | ||||||
|     donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] |= 0x04; |     if(!(donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] & 0x04)){ | ||||||
|     donnees_a_envoyer=1; |         printf("active propulseur\n"); | ||||||
|  |         donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] |= 0x04; | ||||||
|  |         donnees_a_envoyer=1; | ||||||
|  |     } | ||||||
| } | } | ||||||
| void i2c_annexe_desactive_propulseur(void){ | void i2c_annexe_desactive_propulseur(void){ | ||||||
|     donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] &= 0xFB; |     donnees_emission[ADRESSE_TURBINE_PORTE - ADRESSE_DEBUT_W] &= 0xFB; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user