sd lecture

Dependencies:   mbed Lecture_SD

Files at this revision

API Documentation at this revision

Comitter:
valentinbruchet
Date:
Wed May 05 08:21:36 2021 +0000
Parent:
4:3269abcc9c73
Commit message:
SD lecture;

Changed in this revision

SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
eeprom_flash.cpp Show annotated file Show diff for this revision Revisions of this file
eeprom_flash.h Show diff for this revision Revisions of this file
diff -r 3269abcc9c73 -r 66c8b598de04 SDFileSystem.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Wed May 05 08:21:36 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/valentinbruchet/code/Lecture_SD/#784b2bd6d8c0
diff -r 3269abcc9c73 -r 66c8b598de04 eeprom_flash.cpp
--- a/eeprom_flash.cpp	Tue Mar 16 14:58:12 2021 +0000
+++ b/eeprom_flash.cpp	Wed May 05 08:21:36 2021 +0000
@@ -1,166 +1,58 @@
 #include "mbed.h"
-#include "eeprom_flash.h"
-Serial pc(USBTX, USBRX); //Initalise PC serial comms
-DigitalOut myled(LED1);
-/*
-* 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
-}
-void disableEEPROMWriting() {
-HAL_FLASH_Lock();
-}
-/*
-* 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;
-}
-/*
-* Reading functions
-*/
-uint16_t readEEPROMHalfWord(uint32_t address) {
-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;
-int lecture;
-pc.baud(9600);
-/* Ecriture*/
-enableEEPROMWriting(); //autorisation d'ecriture dans l'eeprom
-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);
-/*lecture et affichage*/
-lecture=readEEPROMHalfWord(adresse);
-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);
-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);
-}
+#include "SDFileSystem.h"
+
+SDFileSystem sd(PA_7, PA_6, PA_5, PB_6, "sd");
+char numberstring[40];
+char numberrfid[100];
+int number;
+int number1;
+ 
+int main() 
+{
+    printf("Bienvenu!\n\r");    
+    FILE *fp1 = fopen("/sd/valeur_rfid.txt", "r");
+    fgets(numberrfid, 100, fp1);    
+    
+    if(fp1 == NULL)
+     {
+        error("Impossible d'ouvrir le fichier pour la lecture\n\r");
+    }
+    sscanf(numberrfid, "%d", &number1);
+    printf ("%d\n\r", number1);
+    sscanf(numberrfid+8, "%d", &number1);
+    printf ("%d\n\r", number1);
+    sscanf(numberrfid+17, "%d", &number1);
+    printf ("%d\n\r", number1);
+    sscanf(numberrfid+25, "%d", &number1);
+    printf ("%d\n\r", number1);
+    sscanf(numberrfid+34, "%d", &number1);
+    printf ("%d\n\r", number1);
+    fclose(fp1); 
+    printf("A bientot!\n\r");
+    
+    FILE *fp = fopen("/sd/valeur_temporisation.txt", "r");
+    fgets(numberstring, 40, fp);    
+    
+    if(fp == NULL)
+     {
+        error("Impossible d'ouvrir le fichier pour la lecture\n\r");
+    }
+    sscanf(numberstring, "%d", &number);
+    printf ("%d\n\r", number);
+    sscanf(numberstring+3, "%d", &number);
+    printf ("%d\n\r", number);
+    sscanf(numberstring+6, "%d", &number);
+    printf ("%d\n\r", number);
+    sscanf(numberstring+9, "%d", &number);
+    printf ("%d\n\r", number);
+    sscanf(numberstring+11, "%d", &number);
+    printf ("%d\n\r", number);
+    sscanf(numberstring+14, "%d", &number);
+    printf ("%d\n\r", number);
+    sscanf(numberstring+16, "%d", &number);
+    printf ("%d\n\r", number);
+    sscanf(numberstring+18, "%d", &number);
+    printf ("%d\n\r", number);
+    fclose(fp); 
+    printf("A bientot!\n\r");
+}
\ No newline at end of file
diff -r 3269abcc9c73 -r 66c8b598de04 eeprom_flash.h
--- a/eeprom_flash.h	Tue Mar 16 14:58:12 2021 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,20 +0,0 @@
-#ifndef __EEPROM_FLASH_H
-#define __EEPROM_FLASH_H
-
-#include "mbed.h"
-
-//#define EEPROM_START_ADDRESS   ((uint32_t)0x08019000) // EEPROM emulation start address: after 100KByte of used Flash memory
-#define EEPROM_START_ADDRESS   ((uint32_t)0x0801C000) // EEPROM emulation start address: after 112KByte of used Flash memory
-
-void enableEEPROMWriting(); // Unlock and keep PER cleared
-void disableEEPROMWriting(); // Lock
-
-// Write functions
-HAL_StatusTypeDef writeEEPROMHalfWord(uint32_t address, uint16_t data);
-HAL_StatusTypeDef writeEEPROMWord(uint32_t address, uint32_t data);
-
-// Read functions
-uint16_t readEEPROMHalfWord(uint32_t address);
-uint32_t readEEPROMWord(uint32_t address);
-
-#endif
\ No newline at end of file