i2c0 not receiving any data

Discussion in 'General Programming Discussion' started by asusrog, Feb 19, 2015.

  1. asusrog

    asusrog New Member

    Joined:
    Apr 28, 2014
    Messages:
    13
    Likes Received:
    0
    Hello,

    Iam trying to get the I2C0(SDA,SCL) working on my udoo(arduino side). I have used the wire slave receiver code but to no avail. I2c master is tiva-tm4c1294xl, i have no problems on the master side as i have checked by echoing back the I2C data back to the serial terminal in tiva. Tiva is sending data to my udoo. I have done bit shifting and m sending bytes which are then re-assembled at the udoo end. I wish to use this data to be able to publish it over rosserial.
    Code:
    #include <Wire.h>
    
    int i=0,j=0;
    void setup()
    {
      Wire.begin(4);                // join i2c bus with address #4
      Wire.onReceive(receiveEvent); // register event
      Serial.begin(9600);           // start serial for output
    }
    
    int data=0x00000000;
    int datad1=0x00000000;
    int datad2=0x00000000;
    float value;
    
    void loop()
    {
      Serial.println(data);
      delay(100);
      if (i==4)
      {
        i=0;
        datad1=data;
        if(j==2)
        {
          datad2=data;
          value = datad1 + (datad2/1000.0f);
        }
        
      }
    }
    
    
    // function that executes whenever data is received from master
    // this function is registered as an event, see setup()
    void receiveEvent(int howMany)
    {
      
       
         data |= Wire.read()>>8*i;
         ++i;
         if(i==4)
         ++j;
       // receive byte as an integer
               // print the integer
    }
    This is the code m using for my arduino. i have even tried i2c scanner but it returned nothing, i guess it wont work if the other i2c device is a master. Anyways i have tried using 1.7K and 4.7K pullups and also without any pull-ups since due has built in pull-ups. i have tried i2c1 as well. Please advice me on how to go about troubleshooting this. Also i have set the slave address on my tiva as 0x04. Below is my relevant tiva code just in case.
    Code:
    void I2C8_init(void)
    {
      SYSCTL_RCGCI2C_R |= 0x0100; //activate I2C8
      SYSCTL_RCGCGPIO_R |= 0x0001; //activate port A
      while((SYSCTL_PRGPIO_R&0x0001)==0) {}; //wait till PORT A is ready for access
      GPIO_PORTA_AHB_AFSEL_R |= 0x0C;
      GPIO_PORTA_AHB_ODR_R |= 0x08;
      GPIO_PORTA_AHB_PCTL_R = (GPIO_PORTA_AHB_PCTL_R&0xFFFF00FF) + 0x00002200;
      GPIO_PORTA_AHB_DEN_R |= 0x0C;
      I2C8_MCR_R = 0x00000010;
      I2C8_MTPR_R = TPR;
    
    }
    
    uint32_t I2C_send(uint8_t slave, int8_t data)
    {
      while(I2C8_MCS_R&0x00000001){};
      I2C8_MSA_R = (slave<<1)&0xFE;
      I2C8_MSA_R &= ~0x01;
      I2C8_MDR_R = data&0xFF;
      I2C8_MCS_R = (I2C_MCS_START | I2C_MCS_RUN);
      while(I2C8_MCS_R&0x00000001){};
    
    //if((I2C8_MCS_R& (I2C_MCS_DATACK | I2C_MCS_ADRACK | I2C_MCS_ERROR)) != 0)
    //{
     //return (I2C8_MCS_R& (I2C_MCS_DATACK | I2C_MCS_ADRACK | I2C_MCS_ERROR));
    //}
    
    return (I2C8_MCS_R& (I2C_MCS_DATACK | I2C_MCS_ADRACK | I2C_MCS_ERROR));
    
    } 
    
    void I2C_send32(int_fast32_t A)
    {
     int8_t data[4],i;
     for(i=0;i<4;i++)
      {
        data[i] = (A<<i*8);
        I2C_send(0x04,data[i]);
        UARTprintf("  Sending: '%3d'  . . .  ", data[i]);
       }
    
    }
     
  2. asusrog

    asusrog New Member

    Joined:
    Apr 28, 2014
    Messages:
    13
    Likes Received:
    0
    Please could anyone help me with this. It is really important for me to get this working
     

Share This Page