M24C32.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "M24C32.h"
  2. uint8_t writedata[1] = {0xAA};
  3. uint8_t Readdata[1] = {0,};
  4. void I2c_Status_Check(I2C_HandleTypeDef* hi2cx,HAL_StatusTypeDef status){
  5. if(HAL_OK == status){
  6. printf("HAL_OK\n");
  7. }
  8. else if(HAL_ERROR == status){
  9. printf("HAL_ERROR\n");
  10. }else if(HAL_BUSY == status){
  11. printf("HAL_ERROR\n");
  12. }else if(HAL_TIMEOUT == status){
  13. printf("HAL_ERROR\n");
  14. }
  15. }
  16. void M24C32_Data_Write(I2C_HandleTypeDef* hi2cx,uint8_t* data,uint16_t address,uint8_t size){
  17. HAL_StatusTypeDef status = HAL_ERROR;
  18. for(uint8_t i = 0; i < size; i++){
  19. status = HAL_I2C_Mem_Write(hi2cx,0xA0,address + i, I2C_MEMADD_SIZE_16BIT, &data[i],1, 2000);
  20. HAL_Delay(5);
  21. if(status > HAL_OK)
  22. printf("EEPROM SAVE ERROR!!! \n");
  23. }
  24. // I2c_Status_Check(status);
  25. }
  26. uint8_t M24C32_Data_Read(I2C_HandleTypeDef* hi2cx,uint16_t address){
  27. uint8_t data[1] = {0};
  28. HAL_StatusTypeDef status = HAL_ERROR;
  29. status = HAL_I2C_Mem_Read(hi2cx,0xA1, address,I2C_MEMADD_SIZE_16BIT, &data[0],1, 2000);
  30. // I2c_Status_Check(status);
  31. // printf("Readdata[0] : %02x\n",data);
  32. return data[0];
  33. }