/** * @brief Main program * @param None * @retval None */ int main() { int i; /*System clock configuration*/ SystemInit(); /* UART0 and UART1 configuration*/ UART_StructInit(&UART_InitStructure); /* Configure UART0 */ UART_Init(UART1,&UART_InitStructure); printf("######## I2C EEPROM TEST #########\r\n"); /* I2C Init */ /* I2C confiugred as follow: * - I2C master mode * - I2C slave address : 0xA0 * - I2C Prescale : 0x61 * /If MCU clock is 20MHz and Prescale value is 0x61, SCL occurs 100KHz as clock. * - I2C Timeout : 0xFFFF */ conf.mode = I2C_Master; conf.slave_address = 0xA0; conf.master.prescale = 0x61; conf.master.timeout = 0xFFFF; /* Cofigure I2C0 */ I2C_Init(I2C0, conf); /* EEPROM Write Test*/ /* It can transmit up to 9data bytes to the EEPROM(24AA02) ( mem_address 1byte, data 8bytes ) */ if( I2C_Burst_Write(I2C0,conf.slave_address,&Transmit_Data[0],9,1) == -1 ) return -1; /*It must be use the delay function between Write operation and Read operation */ I2C_Delay(0x000F0000); /*I2C Core reset */ I2C_Reset(I2C0); // EEPROM Read Test /* I2C Start */ I2C_Start(I2C0,conf.slave_address,I2C_WRITE_SA7); /* The memory address of EEPROM send to EEPROM and it wait the ack signal */ I2C_SendDataAck(I2C0,0x00); /*Once the Slave address and memotu address are clocked in and *acknowledged by the EEPROM, the W7500 must generate another start condition.*/ I2C_Restart_Structure(I2C0,conf.slave_address,I2C_READ_SA7); /* EEPROM Read Test*/ for(i=0;i<MAX_SIZE;i++) { if(i != MAX_SIZE-1) Recv_Data[i] = I2C_ReceiveData(I2C0,0); else Recv_Data[i] = I2C_ReceiveData(I2C0,1); } for(i=0;i<MAX_SIZE-2;i+=2) printf("[%02d]:%02x, [%02d]:%02x\r\n",i,Recv_Data[i],i+1,Recv_Data[i+1]); return 0; }
int i2c_byte_write(i2c_t *obj, int data) { I2cHandle = (I2C_TypeDef *)(obj->i2c); return I2C_SendDataAck(I2cHandle,(uint8_t)data); }