1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- #include "M24C32.h"
- uint8_t writedata[1] = {0xAA};
- uint8_t Readdata[1] = {0,};
- void I2c_Status_Check(I2C_HandleTypeDef* hi2cx,HAL_StatusTypeDef status){
- if(HAL_OK == status){
- printf("HAL_OK\n");
- }
- else if(HAL_ERROR == status){
- printf("HAL_ERROR\n");
- }else if(HAL_BUSY == status){
- printf("HAL_ERROR\n");
- }else if(HAL_TIMEOUT == status){
- printf("HAL_ERROR\n");
- }
- }
- void M24C32_Data_Write(I2C_HandleTypeDef* hi2cx,uint8_t* data,uint16_t address,uint8_t size){
- HAL_StatusTypeDef status = HAL_ERROR;
- for(uint8_t i = 0; i < size; i++){
- status = HAL_I2C_Mem_Write(hi2cx,0xA0,address + i, I2C_MEMADD_SIZE_16BIT, &data[i],1, 2000);
- HAL_Delay(5);
- if(status > HAL_OK)
- printf("EEPROM SAVE ERROR!!! \n");
- }
- // I2c_Status_Check(status);
- }
- uint8_t M24C32_Data_Read(I2C_HandleTypeDef* hi2cx,uint16_t address){
- uint8_t data[1] = {0};
- HAL_StatusTypeDef status = HAL_ERROR;
- status = HAL_I2C_Mem_Read(hi2cx,0xA1, address,I2C_MEMADD_SIZE_16BIT, &data[0],1, 2000);
- // I2c_Status_Check(status);
- // printf("Readdata[0] : %02x\n",data);
- return data[0];
- }
|