Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 3:4ec898e0b61a, committed 2022-04-21
- Comitter:
- Giamarchi
- Date:
- Thu Apr 21 17:22:06 2022 +0000
- Parent:
- 2:f9f2ca55c5f8
- Commit message:
- I2C EEPROM Test
Changed in this revision
fonctions.h | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/fonctions.h Thu Apr 21 17:22:06 2022 +0000 @@ -0,0 +1,62 @@ +//============================================================================== +// Fichier : fonctions.h +// +// Description de fonctions utilisées pour la station météo +//============================================================================== +#include "mbed.h" +// Déclaration des variables et des constantes + +InterruptIn Anem(PB_4); // La ligne est déclarée en interruption +Timer Fenetre_Temps; // Déclaration d'un compteur + +uint16_t nombre; + +void ISR_Compteur(void) // Fonction d'interruption (Interrupt Sub Routine) +{ + nombre++; // Compte le nombre de rotation de l'axe +} + +void Init_Fonctions(void) +{ + Anem.mode(PullUp); // Activation résistance de Pullup + Fenetre_Temps.start(); // Déclenche le timer + Anem.rise(&ISR_Compteur); // Interruption sur front montant + Anem.fall(&ISR_Compteur); +} +//============================================================================== +// Fonction : Girouette +// Entrée : Pas de paramètres en entrée +// Sortie : vitesse du vent en 16bits + +// this function has 63 bytes write limit +void writeEEPROM(int address, unsigned int eeaddress, char *data, int size) +{ + char i2cBuffer[size + 2]; + i2cBuffer[0] = (unsigned char)(eeaddress >> 8); // MSB + i2cBuffer[1] = (unsigned char)(eeaddress & 0xFF); // LSB + + for (int i = 0; i < size; i++) { + i2cBuffer[i + 2] = data[i]; + } + + int result = i2c.write(address, i2cBuffer, size + 2, false); + wait_ms(6); +} + +// Nucleo - L432KC - L031K6 + +// PA_9 Vin +// PA_10 Gnd +// NRST NRST +// Gnd 5V +// PA_12 PA_2 +// PB_0 PA_7 +// PB_7 SDA PA_6 +// PB_6 SCL PA_5 +// PB_1 PA_4 +// NC PA_3 +// NC PA_1 +// PA_8 PA_0 AN0 +// PA_11 Aref +// PB_5 3V3 +// PB_4 PB_3 \ No newline at end of file
--- a/main.cpp Thu Feb 03 17:52:19 2022 +0000 +++ b/main.cpp Thu Apr 21 17:22:06 2022 +0000 @@ -3,28 +3,33 @@ // Initiation à la Programmation // Auteur : Frédéric Giamarchi -// Date : 21 janv. 2022 -// TP : -// Test des Timers +// Date : 26 mars 2022 +// TP : Station Météo +// Test Liaison I2C //============================================================================== // Déclarations des ressources #include "mbed.h" -Timer t; - //============================================================================== // Déclaration des broches DigitalOut DEL_RO(PA_11); // Ligne PA_11 sur la carte Nucléo Serial pc(USBTX, USBRX); // Dialogue Série port USB à 9600 Baud -AnalogIn POT(PA_0); // Ligne PA_0 en entrée analogique +I2C i2c(PB_7, PB_6); // I2C SDA, SCL +//I2C i2c(I2C_SDA, I2C_SCL); //============================================================================== // Déclaration des variables uint8_t variable; // variable de type entier (0 à 255) char c; // variable de type caractère -float temp; // variable de type réel +float temp; // variable de type réel uint16_t mesure; +#define EEPROM_ADR 0b10100000 // EEPROM adresse 24C16 16kbits + +char data[1]; +char data_write[3]; // Array for adresse and data +uint8_t i; + //============================================================================== // Déclaration des Fonctions void Ma_Fonction(void) @@ -37,23 +42,41 @@ int main() // Fonction principale { // Autres valeurs standard : 9600 19200 38400 57600 115200 - pc.baud(38400); - pc.printf("\r\nFabLab TP Test Timer\r\n\n"); - variable = 0; +// pc.baud(38400); + pc.printf("\r\nFabLab Test I2C\r\n\n"); // Test de l'horloge Systeme - pc.printf("Horloge CPU a %d Hz\r\n", SystemCoreClock); +// pc.printf("Horloge CPU a %d Hz\r\n", SystemCoreClock); - t.start(); // Compteur activé -// 10 caractères, chaque caractère compte 10 bits (8 + 1 bit de start et 1 bit de stop) - pc.printf("Bonjour !\n"); - t.stop(); // Compteur stoppé - pc.printf("Duree du texte : %f s\n",t.read()); + i2c.frequency(100000); + +// Type in address + data_write[0] = 0; // Adresse poids fort + data_write[1] = 0; // Adresse poids faible +// Type data + data_write[2] = 1; // Donnée + + for( i = 0; i < 255; i++ ) + { + data_write[1] = i; + data_write[2] = i; + i2c.write(EEPROM_ADR, data_write, 3); + wait_ms(6); // Wait eeprom internal write cycle (5ms) + 1ms + } + +char reg_adr[2] = {0,0}; + + i2c.write(EEPROM_ADR, reg_adr, 2, true); + i2c.read(EEPROM_ADR, data, 1, false); + pc.printf("Nb ecriture: %d\n\r",data[0]); + //============================================================================== // Boucle Infinie while(1) { - + i2c.read(EEPROM_ADR, data, 1); + pc.printf("%d\n\r",data[0]); + wait_ms(500); } // Fin du while(1) //============================================================================== } // Fin du Programme