Skip to main content
ast8346
Associate II
December 20, 2016
Question

I2C master-slave communication problem

  • December 20, 2016
  • 1 reply
  • 2378 views
Posted on December 20, 2016 at 13:35

The original post was too long to process during our migration. Please click on the attachment to read the original post.
    This topic has been closed for replies.

    1 reply

    waclawek.jan
    Super User
    December 20, 2016
    Posted on December 20, 2016 at 14:22

    Receiver does not work.

    Make sure your connections are OK. Read back the GPIO registers in a debugger and verify their content is what you intended.

    [EDIT]  

    I2C_CR2:

    SADD[7:1]: Slave address bit 7:1 (master mode)

    In 7-bit addressing mode (ADD10 = 0):

    These bits should be written with the 7-bit slave address to be sent

    I2C_OAR1:

    Bits 7:1 OA1[7:1]: Interface address

    Bits 7:1 of address

    Well, the latter is just another incarnation of the 'I don't understand the 7-bit address from I2C specification'. OA1 should contain the 7-bit address, ergo, drop the shift in

     I2C1->OAR1 |= (0x10<<1); // set own address

    JW

    PS.

     
    ast8346
    ast8346Author
    Associate II
    December 20, 2016
    Posted on December 20, 2016 at 15:48

    Right, so the address value has to be in the range between 0x08 and 0x77

    Also, the I2C_write function should have address shifted to the left once as well as the bit 0 has to do with 10-bit interface

    I2C1->CR2 = I2C_CR2_RELOAD | (uint32_t) (1 << 16) | (uint32_t) (address << 1);

    I have changed that, but my code still does not work

    :(

    waclawek.jan
    Super User
    December 20, 2016
    Posted on December 20, 2016 at 16:53

    The address both in OAR and CR2 has the same structure, so either shift both (treating them as 7-bit address as per I2C spec) or none (treating them as the 'customary' 8-bit address).

    If you have both shifted, then again, double-check the connections and the macros you've used in the slave code.

    JW