Jump to content

    
Sign in to follow this  
jenya7

I2C на K70

Recommended Posts

Проблема подсоедениться к I2C чипу.

void INA226_ReadReg(uint32_t slave_adr, uint8_t reg_addr, uint16_t *value)
{
    uint8_t val[2];
    
    //first - write register address
    
    //for a write operation R/Wn bit should be low
    uint8_t slave_address = slave_adr  & 0xFE;  
    
    //start
    I2C0_C1 |= I2C_C1_TX_MASK;
    I2C0_C1 |= I2C_C1_MST_MASK
    
    /* send slave address with W/R bit */
    I2C0_D = slave_address;
    //wait for ack
    while((I2C0_S & I2C_S_IICIF_MASK)==0) {} 
    I2C0_S |= I2C_S_IICIF_MASK;
    
    /* set register address */
    I2C0_D = reg_addr;
    //wait for ack
    while((I2C0_S & I2C_S_IICIF_MASK)==0) {} 
    I2C0_S |= I2C_S_IICIF_MASK;
    
    //stop
    I2C0_C1 &= ~I2C_C1_MST_MASK;
    I2C0_C1 &= ~I2C_C1_TX_MASK
    

    //second - read from written register address
    
    //slave address for read
    slave_address = slave_adr | 0x01;
    
    //repeated start 
    I2C0_C1 |= I2C_C1_RSTA_MASK;
    
    I2C0_D = slave_address;
    //wait for ack
    while((I2C0_S & I2C_S_IICIF_MASK)==0) {} 
    I2C0_S |= I2C_S_IICIF_MASK;
    
    
    // Put in Rx Mode
    I2C0_C1 &= (~I2C_C1_TX_MASK);

    // Turn off ACK since this is second to last byte being read
    I2C0_C1 |= I2C_C1_TXAK_MASK;
   
    val[0] = I2C0_D;
     //wait for ack
    while((I2C0_S & I2C_S_IICIF_MASK)==0) {} 
    I2C0_S |= I2C_S_IICIF_MASK;
    val[1] = I2C0_D;
     //wait for ack
    while((I2C0_S & I2C_S_IICIF_MASK)==0) {} 
    I2C0_S |= I2C_S_IICIF_MASK;
    
    *value = (val[0] << 8) | val[1];
    
    //stop
    I2C0_C1 &= ~I2C_C1_MST_MASK;
    I2C0_C1 &= ~I2C_C1_TX_MASK
}

 

Застревает на

while((I2C0_S & I2C_S_IICIF_MASK)==0) {}

I2C0_S |= I2C_S_IICIF_MASK;

 

Может я что то упускаю?

 

 

Share this post


Link to post
Share on other sites

я заменил

while((I2C0_S & I2C_S_IICIF_MASK)==0) {}
I2C0_S |= I2C_S_IICIF_MASK;

на

while((I2C0_S & I2C_S_IICIF_MASK)==0)
{
          timeout++;
          if(timeout > I2C_TIMEOUT)
            return I2C_ERROR;
  }

и теперь я вижу первую часть посылки - адрес слейва и адрес регистра. но репитед старт не происходит.

post-71075-1497773935_thumb.jpg

post-71075-1497773948_thumb.jpg

Share this post


Link to post
Share on other sites

Все тот же К70. С INA226 все в порядке. Сейчас обращаюсь к MAX6956 по второму I2C каналу - I2C1. Проблема что на несколько чтений SDA линия остается внизу, флаг BUSY поднимается и все, I2C не реагирует.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this