programme bts

Dependencies:   mbed ID12RFID SDFileSystem

Revision:
4:3269abcc9c73
Parent:
3:46c0511e25af
diff -r 46c0511e25af -r 3269abcc9c73 eeprom_flash.cpp
--- a/eeprom_flash.cpp	Sun Feb 09 09:56:51 2020 +0000
+++ b/eeprom_flash.cpp	Tue Mar 16 14:58:12 2021 +0000
@@ -3,76 +3,164 @@
 Serial pc(USBTX, USBRX); //Initalise PC serial comms
 DigitalOut myled(LED1);
 /*
- * Must call this first to enable writing
- */
+* Must call this first to enable writing
+*/
 void enableEEPROMWriting() {
-    HAL_StatusTypeDef status = HAL_FLASH_Unlock();
-    FLASH_PageErase(EEPROM_START_ADDRESS); // required to re-write
-    CLEAR_BIT(FLASH->CR, FLASH_CR_PER);    // Bug fix: bit PER has been set in Flash_PageErase(), must clear it here
+HAL_StatusTypeDef status = HAL_FLASH_Unlock();
+FLASH_PageErase(EEPROM_START_ADDRESS); // required to re-write
+CLEAR_BIT(FLASH->CR, FLASH_CR_PER); // Bug fix: bit PER has been set in Flash_PageErase(), must clear it here
 }
-
 void disableEEPROMWriting() {
-    HAL_FLASH_Lock();
+HAL_FLASH_Lock();
 }
-
 /*
- * Writing functions
- * Must call enableEEPROMWriting() first
- */
+* Writing functions
+* Must call enableEEPROMWriting() first
+*/
 HAL_StatusTypeDef writeEEPROMHalfWord(uint32_t address, uint16_t data) {
-    HAL_StatusTypeDef status;
-    address = address + EEPROM_START_ADDRESS;
-    status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, address, data);
-    return status;
+HAL_StatusTypeDef status;
+address = address + EEPROM_START_ADDRESS;
+status = HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, address, data);
+return status;
 }
-
 /*
- * Reading functions
- */
+* Reading functions
+*/
 uint16_t readEEPROMHalfWord(uint32_t address) {
-    uint16_t val = 0;
-    address = address + EEPROM_START_ADDRESS;
-    val = *(__IO uint16_t*)address;
-     return val;
+uint16_t val = 0;
+address = address + EEPROM_START_ADDRESS;
+val = *(__IO uint16_t*)address;
+return val;
 }
-
 //Programme de test
-
 int main() {
+int tab[40]= {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};
 int adresse = 0x00;
-char donnee1 = 11;
-char donnee2 = 22;
-char donnee3 = 33;
 int lecture;
 pc.baud(9600);
-
 /* Ecriture*/
 enableEEPROMWriting(); //autorisation d'ecriture dans l'eeprom
-writeEEPROMHalfWord(adresse, donnee1);
-writeEEPROMHalfWord(adresse+2, donnee2);
-writeEEPROMHalfWord(adresse+4, donnee3);
+writeEEPROMHalfWord(adresse, tab[0]);
+writeEEPROMHalfWord(adresse+2, tab[1]);
+writeEEPROMHalfWord(adresse+4, tab[2]);
+writeEEPROMHalfWord(adresse+6, tab[3]);
+writeEEPROMHalfWord(adresse+8, tab[4]);
+writeEEPROMHalfWord(adresse+10, tab[5]);
+writeEEPROMHalfWord(adresse+12, tab[6]);
+writeEEPROMHalfWord(adresse+14, tab[7]);
+writeEEPROMHalfWord(adresse+16, tab[8]);
+writeEEPROMHalfWord(adresse+18, tab[9]);
+writeEEPROMHalfWord(adresse+20, tab[10]);
+writeEEPROMHalfWord(adresse+22, tab[11]);
+writeEEPROMHalfWord(adresse+24, tab[12]);
+writeEEPROMHalfWord(adresse+26, tab[13]);
+writeEEPROMHalfWord(adresse+28, tab[14]);
+writeEEPROMHalfWord(adresse+30, tab[15]);
+writeEEPROMHalfWord(adresse+32, tab[16]);
+writeEEPROMHalfWord(adresse+34, tab[17]);
+writeEEPROMHalfWord(adresse+36, tab[18]);
+writeEEPROMHalfWord(adresse+38, tab[19]);
+writeEEPROMHalfWord(adresse+40, tab[20]);
+writeEEPROMHalfWord(adresse+42, tab[21]);
+writeEEPROMHalfWord(adresse+44, tab[22]);
+writeEEPROMHalfWord(adresse+46, tab[23]);
+writeEEPROMHalfWord(adresse+48, tab[24]);
+writeEEPROMHalfWord(adresse+50, tab[25]);
+writeEEPROMHalfWord(adresse+52, tab[26]);
+writeEEPROMHalfWord(adresse+54, tab[27]);
+writeEEPROMHalfWord(adresse+56, tab[28]);
+writeEEPROMHalfWord(adresse+58, tab[29]);
+writeEEPROMHalfWord(adresse+60, tab[30]);
+writeEEPROMHalfWord(adresse+62, tab[31]);
+writeEEPROMHalfWord(adresse+64, tab[32]);
+writeEEPROMHalfWord(adresse+66, tab[33]);
+writeEEPROMHalfWord(adresse+68, tab[34]);
+writeEEPROMHalfWord(adresse+70, tab[35]);
+writeEEPROMHalfWord(adresse+72, tab[36]);
+writeEEPROMHalfWord(adresse+74, tab[37]);
+writeEEPROMHalfWord(adresse+76, tab[38]);
+writeEEPROMHalfWord(adresse+78, tab[39]);
 disableEEPROMWriting(); //Interdiction d'ecriture
-
- myled=!myled;
-        wait(0.5);
-        myled=!myled;
-        wait(0.5);
-
+myled=!myled;
+wait(0.5);
+myled=!myled;
+wait(0.5);
 /*lecture et affichage*/
 lecture=readEEPROMHalfWord(adresse);
-if (lecture==11)
-    {
-        myled=!myled;
-        wait(0.5);
-        myled=!myled;
-        wait(0.5);
-        myled=!myled;
-        wait(0.5);
-    }
 pc.printf ("valeur lue: %d\n\r",lecture);
 lecture=readEEPROMHalfWord(adresse+2);
 pc.printf ("valeur lue: %d\n\r",lecture);
 lecture=readEEPROMHalfWord(adresse+4);
 pc.printf ("valeur lue: %d\n\r",lecture);
- while(1);
-}
\ No newline at end of file
+lecture=readEEPROMHalfWord(adresse+6);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+8);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+10);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+12);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+14);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+16);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+18);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+20);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+22);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+24);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+26);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+28);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+30);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+32);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+34);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+36);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+38);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+40);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+42);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+44);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+46);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+48);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+50);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+52);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+54);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+56);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+58);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+60);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+62);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+64);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+68);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+70);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+72);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+76);
+pc.printf ("valeur lue: %d\n\r",lecture);
+lecture=readEEPROMHalfWord(adresse+78);
+pc.printf ("valeur lue: %d\n\r",lecture);
+while(1);
+}