Other Parts Discussed in Thread: HALCOGEN
Hi Team,
Did you have any example code for the I2C for RTC real time clock project and the configuration for I2C in HALCoGen?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi Team,
Did you have any example code for the I2C for RTC real time clock project and the configuration for I2C in HALCoGen?
This is an example for RTC I posted 2 years ago:
Hi QJ Wang,
// Slave address
#define RV3129_ADDRESS 0x56
// Temperature Page
#define RV3129_TEMP 0x20
#define DATA_COUNT 1
/* Transmit Start Condition */
i2cSetStart(i2cREG1);
/* Configure address of Slave to talk to */
i2cSetSlaveAdd(i2cREG1, RV3129_ADDRESS);
/* Set mode as Master */
i2cSetMode(i2cREG1, I2C_MASTER);
/* Set direction to Transmitter */
/* Note: Optional - It is done in Init */
i2cSetDirection(i2cREG1, I2C_TRANSMITTER);
/* Send the Word Address */
i2cSendByte(i2cREG1, Slave_Word_address);
/* Set Stop after programmed Count */
i2cSetStop(i2cREG1);
/* Tranmit DATA_COUNT number of data in Polling mode */
i2cReceive(i2cREG1, DATA_COUNT, RX_Data_Master);
/* 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);
/* Simple Dealya before starting Next Block */
/* Depends on how quick the Slave gets ready */
for(delay=0;delay<100000;delay++);
I have tried this code as per the Hercules I2C example but I did get any output for this RTC
Please help me to prepare the sequence.
Can you confirm me the configuration of I2C and Code ?
You get the returned data from the RTC, so I2C configuration should be fine.
HI QJ Wang,
No, I didn't receive the data from RTC till now.
I have seen the code for Arduino board.
uint8_t RV3129::readRegister(uint8_t addr)
{
_i2cPort->beginTransmission(RV3129_ADDR);
_i2cPort->write(addr);
_i2cPort->endTransmission();
_i2cPort->requestFrom(RV3129_ADDR, (uint8_t)1);
if (_i2cPort->available()) {
return (_i2cPort->read());
}
else {
return (0xFF); //Error
}
}
bool RV3129::writeRegister(uint8_t addr, uint8_t val)
{
_i2cPort->beginTransmission(RV3129_ADDR);
_i2cPort->write(addr);
_i2cPort->write(val);
if (_i2cPort->endTransmission() != 0)
return (false); //Error: Sensor did not ack
return(true);
}
How to use this code as requestfrom API in TI API and the
beginTransmission API as
/* Clear Stop bit */
i2cREG1->MDR &= ~(I2C_STOP_COND);
/* Clear Start bit */
i2cREG1->MDR &= ~(I2C_START_COND);
/* Clear Repeat mode bit */
// Configure address of Slave to talk to
i2cSetSlaveAdd(i2cREG1, RV3129_WADDR); is 0xAC
How to give the count value is based on the data size ?
/* Configure Data count */
i2cSetCount(i2cREG1, Count+1);
Please confirm as soon as possible.
I have tried this code as per the Hercules I2C example but I did get any output for this RTC
Ok, you didn't get any output from the RTC.
Did you try my code in this post? I wrote this I2C code for RTC: