Hello,
I need help with I2C interface on my Hercules RM48. Im trying to communicate with microchips 24LC64 EEPROM IC but I have no luck. For start Im tryng to write to I2C
I configured I2C in HALcoGen like:
- add_mode-> 10bit
- transmiter
- bit count -> 8
- data count -> 8
This is my write function:
uint32_t ee_i2c_write (uint16_t reg_adr, uint8_t * reg_data,
uint16_t length)
{
uint16_t delay;
uint8_t data[40];
data[0] = reg_adr >> 8;
data[1] = reg_adr & 0xFF;
uint8_t slave_addr = EEPROM_I2C_ADDR & 0xFE;
if (EEPROM_PAGE_SIZE < length)
return 0;
memcpy(&data[2], reg_data, length);
/* Configure address of Slave to talk to */
i2cSetSlaveAdd(i2cREG1, slave_addr);
/* Set direction to Transmitter */
/* Note: Optional - It is done in Init */
i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
/* Data Count + 1 ( Word Address) */
i2cSetCount(i2cREG1, length + 1);
/* Set mode as Master */
i2cSetMode(i2cREG1, I2C_MASTER);
/* Set Stop after programmed Count */
i2cSetStop(i2cREG1);
/* Transmit Start Condition */
i2cSetStart(i2cREG1);
/* Saw this in TI example */
i2cSendByte(i2cREG1, 0x00);
/* Set Stop after programmed Count */
i2cSetStop(i2cREG1);
/* Transmit Start Condition */
i2cSetStart(i2cREG1);
/* Tranmit DATA_COUNT number of data in Polling mode */
i2cSend(i2cREG1, length, reg_data);
/* Wait until Bus Busy is cleared */
while(i2cIsBusBusy(i2cREG1) == true);
/* Wait until Stop is detected */
while(i2cIsStopDetected(i2cREG1) == 0);
/* Clear the Stop condition */
i2cClearSCD(i2cREG1);
/* Depends on how quick the Slave gets ready */
for(delay=0;delay<100000;delay++);
return 1;
}This are SDA and SCL signals that i get: