Eeprom.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * V1.0
  3. */
  4. #include <Eeprom.h>
  5. /****Private fonction */
  6. HAL_StatusTypeDef readEeprom(uint16_t Add,uint8_t *tab, int len){
  7. HAL_StatusTypeDef res;
  8. uint8_t add[2];
  9. add[0]=Add>>8;
  10. add[1]=Add;
  11. if ((res = HAL_I2C_Master_Transmit(EEprom.I2C,EepromADD,add,2,1000)) != HAL_OK){
  12. return res;
  13. }
  14. res = HAL_I2C_Master_Receive(EEprom.I2C,EepromADD,tab,len,1000);
  15. return res;
  16. }
  17. HAL_StatusTypeDef writeEeprom(uint16_t Add,uint8_t *tab, int len){
  18. HAL_StatusTypeDef res;
  19. uint8_t data[2+len];
  20. data[0]=Add>>8;
  21. data[1]=Add;
  22. for(int i =0;i<len;i++)
  23. data[i+2]=tab[i];
  24. HAL_GPIO_WritePin(EEprom.WC_PORT,EEprom.WC_PIN,0);
  25. if ((res = HAL_I2C_Master_Transmit(EEprom.I2C,EepromADD,data,2+len,1000)) != HAL_OK){
  26. HAL_GPIO_WritePin(EEprom.WC_PORT,EEprom.WC_PIN,1);
  27. return res;
  28. }
  29. //introduire un delay
  30. for(int i =0;i<5000;i++)
  31. data[2]=i;
  32. HAL_GPIO_WritePin(EEprom.WC_PORT,EEprom.WC_PIN,1);
  33. return res;
  34. }
  35. /** Public Fonction*/
  36. void initEprom(I2C_HandleTypeDef *typ,GPIO_TypeDef *port, uint16_t pin){
  37. EEprom.I2C = typ;
  38. EEprom.WC_PORT = port;
  39. EEprom.WC_PIN = pin;
  40. HAL_GPIO_WritePin(EEprom.WC_PORT,EEprom.WC_PIN,1);
  41. }