Part Number: MSP430F5529
Hi,
I am having some trouble with communicating with the DS3231 RTC chip. Here is my code below.
I am using the UCB1SCL and UCB1SDA pins on the Launchpad.
The address of the real time clock is 0xD0, that includes the R/W bit. I'm not sure if I should be shifting this to the left and send only the 7 bit address.
Hence I commented out i2cAdd = i2cAdd >> 1. Anyway, I tried sending both 8 bit(including R/W) and 7 bit but still can't talk to the chip. Am I missing anything here?
By the way, I noticed that the code gets stuck in the function WriteRTCByte when the function "USCI_B_I2C_masterSendMultiByteNext(USCI_B1_BASE, data);" is called
Please see code below
Thanks.
AJ
void InitializeRTC(void)
{
//Assign I2C pins to USCI_B1
GPIO_setAsPeripheralModuleFunctionInputPin(
GPIO_PORT_P4, GPIO_PIN1 + GPIO_PIN2);
//Initialize Master
USCI_B_I2C_initMasterParam param = {0};
param.selectClockSource = USCI_B_I2C_CLOCKSOURCE_SMCLK;
param.i2cClk = UCS_getSMCLK();
param.dataRate = USCI_B_I2C_SET_DATA_RATE_100KBPS;
USCI_B_I2C_initMaster(USCI_B1_BASE, ¶m);
//Enable I2C Module to start operations
USCI_B_I2C_enable(USCI_B1_BASE);
}//end void InitializeRTC(void)
/***********************************************/
void WriteRTCByte(uint8_t i2cAdd, uint8_t rtcAdd, uint8_t data)
{
//i2cAdd = i2cAdd >> 1;
//Specify slave address
USCI_B_I2C_setSlaveAddress(USCI_B1_BASE, i2cAdd);
//Set Transmit mode
USCI_B_I2C_setMode(USCI_B1_BASE, USCI_B_I2C_TRANSMIT_MODE);
USCI_B_I2C_masterSendMultiByteStart(USCI_B1_BASE, rtcAdd);
USCI_B_I2C_masterSendMultiByteNext(USCI_B1_BASE, data);
USCI_B_I2C_masterSendMultiByteStop(USCI_B1_BASE);
while(USCI_B_I2C_isBusBusy(USCI_B1_BASE));
}//end void WriteRTCByte(uint8_t i2cAdd, uint8_t rtcAdd, uint8_t data)
/***********************************************/
uint8_t ReadRTCByte(uint8_t i2cAdd, uint8_t rtcAdd)
{
uint8_t i2cByte;
//i2cAdd = i2cAdd >> 1;
//Specify slave address
USCI_B_I2C_setSlaveAddress(USCI_B1_BASE, i2cAdd);
//Set Transmit mode
USCI_B_I2C_setMode(USCI_B1_BASE, USCI_B_I2C_TRANSMIT_MODE);
USCI_B_I2C_masterSendMultiByteStart(USCI_B1_BASE, rtcAdd);
while(USCI_B_I2C_isBusBusy(USCI_B1_BASE));
//Specify slave address
USCI_B_I2C_setSlaveAddress(USCI_B1_BASE, (i2cAdd | 0x01));
//Set receive mode
USCI_B_I2C_setMode(USCI_B1_BASE, USCI_B_I2C_RECEIVE_MODE);
USCI_B_I2C_masterReceiveSingleStart(USCI_B1_BASE);
i2cByte = USCI_B_I2C_masterReceiveSingle(USCI_B1_BASE);
while(USCI_B_I2C_isBusBusy(USCI_B1_BASE ));
return(i2cByte);
}//end uint8_t ReadRTCByte(uint8_t i2cAdd, uint8_t rtcAdd)
/***********************************************/