Tiva C cannot change value of MDR register

0

i have a tiva c micro controller the tm4c123gxl and i have been trying for a while now to use the I2C module on the board with a digital accelrometer with no result , i have been trying to set the MDR register with a certain value to send but it stays as 0

here is the code i am using for intialization till reaching part where i set the MDR register im using step by step debugging i run the code initially to the assignment step of I2C3_MDR_R = 0x2D;

void PortDInit(void)
{
volatile unsigned long delay=0;
    SYSCTL_RCGCI2C_R|=0x8;             //1-set clock of I2C of module 3 
    delay = SYSCTL_RCGC2_R;            //2-delay to allow clock to stabilize
    SYSCTL_RCGC2_R |= 0x00000008;      //3-port D clock
    delay = SYSCTL_RCGC2_R;            //4-delay to allow clock to stabilize     
    GPIO_PORTD_AFSEL_R |= 0x03;        //5-alternate function set for I2C mode
    GPIO_PORTD_DEN_R |=0x03;          //6-enable digital functionality for PA6 and PA7
    GPIO_PORTD_ODR_R|=0x02;                  //7-enable open drain mode for I2CSDA register of port A
    GPIO_PORTD_PCTL_R = 0x00000033;   //8-set PCTL to I2C mode
    I2C3_MCR_R= 0x00000010;                     // 9-intialize the i2c master
    I2C3_MTPR_R = 0x00000007;                   // 10-number of system clock cycles in 1 scl period
I2C3_MSA_R = 0x3A // set slave address and read write bit
I2C3_MDR_R = 0x2D;                                  // data to be sent BREAK POINT HERE using single step here yields MDR with same value = 0
I2C3_MCS_R = 0x00000003;                                  // follow transmit condition
    while(I2C3_MCS_R &= 0x40 == 1);                 // wait bus is busy sending data
    if(I2C3_MCS_R&=0x04 ==1)
    {
        //handle error in communication
    }
    else
    {
        //success in transmission 
    }

what i have done to reach this code

  • carefully understood the I2C protocol how it works etc.
  • check the data sheet and follow the initalization steps mentioned there step by step which got me to this code
  • i know i should use tivaware library which will be easier but using the registers helps me understand more of how everything is working , im still a student
  • at first i didnt have the digital enable line as it wasnt mentioned to be activated for the I2C but its only logical it should be there as we are using digital values i tried with both yielded the same output mdr=0
  • i am using keil 4 as my IDE and im viewing the values of registers of I2C module 3 to know whether data is placed in MDR or not

hope any one helps thanks.

c
arm
microcontroller
keil
asked on Stack Overflow Nov 22, 2016 by Essam Eid • edited Nov 22, 2016 by Essam Eid

1 Answer

0

This is a long shot, but here goes:

in your comments, step 6 says

//6-enable digital functionality for PA6 and PA7

but it appears you are working on GPIO_PORTD...

maybe its a comment typo (you meant PD6 and PD7) but just double check you are looking at the right pins...

Good luck!

answered on Stack Overflow Dec 18, 2016 by Etienne Stehelin

User contributions licensed under CC BY-SA 3.0