Hi everyone,
I am trying to interface 1307 rtc to tiva using I2C communication. I have configured my launchpad for I2C as given in the datasheet. http://www.ti.com/lit/gpn/tm4c123gh6pm
After configuration I am not able to write to I2C_MDR register.
Here is my code so far
// ***** 1. Pre-processor Directives Section *****
#include <stdint.h>
#include "tm4c123gh6pm.h"
void port_e_i2c_init(){
unsigned long volatile delay;
SYSCTL_RCGCI2C_R |= 0x00000004; // Enable and provide clock to I2C module 2 in Run mode.
delay = SYSCTL_RCGCI2C_R; // wait 3-5 bus cycles
SYSCTL_RCGC2_R |= 0x10; // Port E clock
delay = SYSCTL_RCGC2_R; // wait 3-5 bus cycles
GPIO_PORTE_AFSEL_R |= 0x00000030; // pin 4 & 5 functions as peripheral signal & is controlled by alternate H/W function
GPIO_PORTE_AMSEL_R &= ~0xFF; // no analog
GPIO_PORTE_ODR_R |= 0x00000020; // pin 5 (SDA) is configured as open drain.
GPIO_PORTE_PCTL_R |= 0x00330000; // set I2C function on pin 4 & 5
GPIO_PORTE_DEN_R |= 0x30; // Digital enable on pin 4 & 5
I2C2_MCR_R = 0x00000010; // initialize the I2C master
I2C2_MTPR_R = 0x00000009; // set SCL clock speed to 100 Kbps
I2C2_MSA_R = 0x00000076; // slave address -> 3B, next operation -> transmit (as last bit is 0)
I2C2_MDR_R = 0x00000068; // place the data byte to be transmitted in the Master Data Register
I2C2_MCS_R = 0x00000007; // single byte transmit of data from master to slave
while((I2C2_MCS_R & 0x00000040)); // wait till transmission is done
}
void i2c_tx(){
// I2C2_MDR_R = 0x00000068; // place the data byte to be transmitted in the Master Data Register
// I2C2_MCS_R = 0x00000007; // single byte transmit of data from master to slave
// while((I2C2_MCS_R & 0x00000040));
}
/*
* main.c
*/
int main(void) {
port_e_i2c_init();
i2c_tx();
return 0;
}
please help.


