/*! * \file i2c_eeprom.c * * \brief Target i2c eeprom implementation * * \copyright Revised BSD License, see section \ref LICENSE. * * \code * * _ __ _ ________ _ * | |/ /(_)___ / ____/ /_ (_)___ * | // / __ \/ / / __ \/ / __ \ * / |/ / / / / /___/ / / / / /_/ / * /_/|_/_/_/ /_/\____/_/ /_/_/ .___/ * /_/ * (C) 2022-2025 XinChip * * \endcode * * \author ( XinChip ) Alex-J * * \author ( XinChip ) */ /*----------------------------------------------------------------------------------- INCLUDE HEADE FILES ------------------------------------------------------------------------------------*/ #include "i2c_eeprom.h" #include "xc6xxx_hal_i2c.h" /*------------------------------------------------------------------------------------ Macros -------------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------------ Global Variables -------------------------------------------------------------------------------------*/ /*------------------------------------------------------------------------------------ Functions -------------------------------------------------------------------------------------*/ /** * @brief i2c_eeprom_test_demo * @details * @param void * @retval void */ void i2c_eeprom_demo(void) { uint8_t txbuff[512] = {"XC66xx I2C TEST \n"}; uint8_t rxbuff[sizeof(txbuff)] = {0}; I2C_InitTypeDef I2C_InitStruct = {0}; GPIO_InitTypeDef GPIO_InitStruct = {0}; GPIO_InitStruct.Mux = GPIO_Mux0; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Int = NOT_INT; GPIO_InitStruct.Pin = GPIO_3; GPIO_InitStruct.Dir = GPIO_DIR_OUTPUT; GPIO_InitStruct.FunSel = I2C_SCL; GPIO_Init(&GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_2; GPIO_InitStruct.Dir = GPIO_DIR_INPUT; GPIO_InitStruct.FunSel = I2C_SDA; GPIO_Init(&GPIO_InitStruct); I2C_InitStruct.I2C_ClockSpeed = I2C_ClockSpeed_1M; I2C_InitStruct.I2C_Mode = I2C_Mode_MASTER; I2C_InitStruct.I2C_OwnAddress1 = 0x50; I2C_Init(XC_I2C, &I2C_InitStruct); for (int i = 0; i < sizeof(txbuff) / 2; i++) { txbuff[i] = i; } for (int i = sizeof(txbuff) / 2; i < sizeof(txbuff); i++) { txbuff[i] = sizeof(txbuff) - i - 1; } DEBUG("Start Write 24Cxx....\r\n"); AT24CXX_Write(0, (uint8_t *)txbuff, sizeof(txbuff)); DEBUG("24Cxx Write Sucess!\r\n"); DEBUG("Start Read 24Cxx....\r\n"); AT24CXX_Read(0, rxbuff, sizeof(rxbuff)); DEBUG("The Data Readed Is: \r\n"); for (int i = 0; i < sizeof(rxbuff); i++) { DEBUG("[%d-%d] ", i, rxbuff[i]); } }