Tool/software:
Hello There,
I am currently working on programming 24CSM01 EEPROM via I2C. You can find my configuration and send/read functions below. For reading/writing I set the slave address 0x50 and send the address but MCU does not receive ack from EEPROM. What can be the problem?
A0:0
A1:0
typedef struct { volatile const uint32_t I2C_BASE_U32; const uint32_t I2C_BAUDRATE_U32; const I2C_DutyCycle e_I2C_DUTYCYCLE; const I2C_BitCount e_I2C_BITCOUNT_U32; const I2C_EmulationMode e_I2C_EMULATIONMODE; const I2C_AddressMode e_I2C_ADDRESSMODE; s_I2C_Com_Handler_t s_Com; }s_I2C_Handler_t; s_I2C_Handler_t s_I2CB_Handler = { .I2C_BASE_U32 = I2CB_BASE, .I2C_BAUDRATE_U32 = 100000U, .e_I2C_BITCOUNT_U32 = I2C_BITCOUNT_8, .e_I2C_DUTYCYCLE = I2C_DUTYCYCLE_50, .e_I2C_EMULATIONMODE = I2C_EMULATION_FREE_RUN, .e_I2C_ADDRESSMODE = I2C_ADDR_MODE_7BITS }; void I2C_Init(s_I2C_Handler_t* p_s_I2C_Handler) { I2C_initController(p_s_I2C_Handler->I2C_BASE_U32, DEVICE_SYSCLK_FREQ, p_s_I2C_Handler->I2C_BAUDRATE_U32, p_s_I2C_Handler->e_I2C_DUTYCYCLE); I2C_setBitCount(p_s_I2C_Handler->I2C_BASE_U32, p_s_I2C_Handler->e_I2C_BITCOUNT_U32); I2C_setEmulationMode(p_s_I2C_Handler->I2C_BASE_U32, I2C_EMULATION_FREE_RUN); // // Enable stop condition and register-access-ready interrupts // I2C_enableInterrupt(p_s_I2C_Handler->I2C_BASE_U32, I2C_INT_STOP_CONDITION | I2C_INT_REG_ACCESS_RDY); // // FIFO configuration // I2C_enableFIFO(p_s_I2C_Handler->I2C_BASE_U32); I2C_clearInterruptStatus(p_s_I2C_Handler->I2C_BASE_U32, I2C_INT_RXFF | I2C_INT_TXFF); //to do // I2C_clearInterruptStatus(p_s_I2C_Handler->I2C_BASE_U32, I2C_INT_ARB_LOST | I2C_INT_NO_ACK); // I2C_enableInterrupt(p_s_I2C_Handler->I2C_BASE_U32, I2C_INT_ADDR_SLAVE | I2C_INT_ARB_LOST | I2C_INT_NO_ACK | I2C_INT_STOP_CONDITION); // // Configuration complete. Enable the module. // I2C_enableModule(p_s_I2C_Handler->I2C_BASE_U32); } void I2C_SendMessage(s_I2C_Handler_t* p_s_I2C_Handler, uint16_t slaveAddress_u16, const uint16_t* p_msgbuffer_u16, uint16_t length_u16) { static uint16_t i2c_message_index_u16 = 0u; I2C_setTargetAddress(p_s_I2C_Handler->I2C_BASE_U32, slaveAddress_u16); while(I2C_isBusBusy(p_s_I2C_Handler->I2C_BASE_U32)) { } I2C_setDataCount(p_s_I2C_Handler->I2C_BASE_U32, length_u16); for(i2c_message_index_u16 = 0u; i2c_message_index_u16 < length_u16; i2c_message_index_u16++) { I2C_putData(p_s_I2C_Handler->I2C_BASE_U32, p_msgbuffer_u16[i2c_message_index_u16]); } I2C_setConfig(p_s_I2C_Handler->I2C_BASE_U32, I2C_MASTER_SEND_MODE | p_s_I2C_Handler->e_I2C_ADDRESSMODE); I2C_sendStartCondition(p_s_I2C_Handler->I2C_BASE_U32); I2C_sendStopCondition(p_s_I2C_Handler->I2C_BASE_U32); while(I2C_getStopConditionStatus(p_s_I2C_Handler->I2C_BASE_U32)!=0); while(I2C_getStatus(p_s_I2C_Handler->I2C_BASE_U32) & I2C_STS_TX_EMPTY != I2C_STS_TX_EMPTY); I2C_sendStopCondition(p_s_I2C_Handler->I2C_BASE_U32); DELAY_US(500); } void I2C_ReadMessage(s_I2C_Handler_t* p_s_I2C_Handler, uint16_t slaveAddress_u16, uint16_t* p_readmsgbuffer_u16, uint16_t length_u16) { static uint16_t i2c_message_index_u16 = 0u; I2C_setTargetAddress(p_s_I2C_Handler->I2C_BASE_U32, slaveAddress_u16); I2C_setDataCount(p_s_I2C_Handler->I2C_BASE_U32, length_u16); I2C_setConfig(p_s_I2C_Handler->I2C_BASE_U32, I2C_MASTER_RECEIVE_MODE | p_s_I2C_Handler->e_I2C_ADDRESSMODE); I2C_sendStartCondition(p_s_I2C_Handler->I2C_BASE_U32); for(i2c_message_index_u16 = 0u; i2c_message_index_u16 < length_u16; i2c_message_index_u16++) { *(p_readmsgbuffer_u16 + i2c_message_index_u16) = I2C_getData(p_s_I2C_Handler->I2C_BASE_U32); } I2C_sendStopCondition(p_s_I2C_Handler->I2C_BASE_U32); while(I2C_getStopConditionStatus(p_s_I2C_Handler->I2C_BASE_U32)!=0); I2C_sendStopCondition(p_s_I2C_Handler->I2C_BASE_U32); }
Yasin