Skip to content

I2C write a buffer bug ? #661

Closed
Closed

Description

@amirc2013

Im trying to send a buffer over a I2C communication.
this is the code i used :

 Wire.beginTransmission(SCREEN_WRITE_addr);
  Wire.write(addr);
  unsigned char* ptr = data;
  for (int i = 0 ; i < len ; i++) {
    Wire.write(*ptr);
     if (DEBUG) {
      Serial.print("WE WROTE :");
      Serial.println(*ptr,HEX);
    }
    ptr++;
  }
  Wire.endTransmission(true);

some how only the last byte has been sent ... why ?

Activity

  1. amirc2013 commented on Sep 19, 2019

    @amirc2013
    Author

    it seems like it is depended on the size of what im sending ... so ... can anyone explain why ?

  2. fpistm commented on Sep 20, 2019

    @fpistm
    Member

    Hi @amirc2013
    could you be more precise about your issue as described in the GitHub issue template:
    Describe the bug
    A clear and concise description of what the bug is.

    To Reproduce
    Complete source code which can be used to reproduce the issue. Please try to be as generic as possible (no extra code, extra hardware,...)

    Desktop (please complete the following information):

    • OS: [e.g. Windows]
    • Arduino IDE version: [e.g. 1.8.8]
    • STM32 core version: [e.g. 1.4.0]
    • Tools menu settings if not the default: [e.g. Newlib Standard, No Serial]
    • Upload method: [e.g. STLink]

    Board (please complete the following information):

    • Name: [e.g. Nucleo F429ZI]
    • Hardware Revision: [e.g. Rev B]
    • Extra hardware used if any: [e.g. X-Nucleo IKS01A1]

    Additional context
    Add any other context about the problem here.

    Full sketch. Which I2C device you used. how it is wired. Do you use PULLUP resistors on the line...

  3. fpistm commented on Sep 24, 2019

    @fpistm
    Member

    @amirc2013
    without any feedback I will close this issue.

  4. amirc2013 commented on Sep 24, 2019

    @amirc2013
    Author

    Bug :
    Can't write a big buffer to the i2c line. Seems like there is a limitation which I can't find where or why.

  5. fpistm commented on Sep 24, 2019

    @fpistm
    Member

    @amirc2013
    OK but you do not provide enough information.
    Which board you used, which I2C hardware, how it is wired.
    As said I could not help without more info.
    I do not ask to close the issue, only to have more info to be able to help...

  6. amirc2013 commented on Sep 24, 2019

    @amirc2013
    Author
  7. reopened this on Sep 24, 2019
  8. fpistm commented on Sep 24, 2019

    @fpistm
    Member

    No worries ;)

  9. fpistm commented on Sep 25, 2019

    @fpistm
    Member

    Right by default I2C_BUFFER is 32 bytes but it is a dynamic allocated buffer which can growth if needed.
    I ask about more info because if @amirc2013 used the GitHub repository then he could met an issue I've seen after repeated start feature introduction. For the 1.7.0, I've revert it.
    So, while I do not get all info I could not help.

  10. amirc2013 commented on Sep 25, 2019

    @amirc2013
    Author
  11. amirc2013 commented on Sep 25, 2019

    @amirc2013
    Author

    This is the simple formation of the code Im using for writing to the I2C.

    My Real Program is really big and it is not understandalbe
    so for this issue I will just use this instead.

    static inline void i2c_write(
    unsigned short addr,
    unsigned char *data,
    unsigned short len)
    {
    Wire.beginTransmission(SLAVE_addr);
    Wire.write(addr);
    Wire.write((const uint8_t *)data,(size_t)len);
    Wire.endTransmission(true);
    }

    The bug :
    When I'm writing a big data to this function - I just cant see then on my logic analyzer.
    Only when I cut them down to 0x1000/10 bytes I will be able to see them.
    This is super weird. Cause I need to write in 0x1000 chunk size...

    My board : Nucleo L4R5ZI
    OS: Windows
    Arduino IDE version: 1.8.10
    STM32 core version: How can I check that ?
    Tools menu settings if not the default. Newlib Nano (default)
    Upload method: Mass storage

    Hardware Revision:How can I check that ?

    I don't use any extra pull-up resistors.. Only connect a micro-controller to my STM with level shifter in the middle.

  12. fpistm commented on Sep 25, 2019

    @fpistm
    Member

    STM32 core version: How can I check that ?

    How did you install it? Boards manager? Using git repo? Anyway you can check here:

    /**
    * @brief STM32 core version number
    */
    #define STM32_CORE_VERSION_MAJOR (0x01U) /*!< [31:24] major version */
    #define STM32_CORE_VERSION_MINOR (0x07U) /*!< [23:16] minor version */
    #define STM32_CORE_VERSION_PATCH (0x00U) /*!< [15:8] patch version */
    /*
    * Extra label for development:
    * 0: official release
    * [1-9]: release candidate
    * F[0-9]: development
    */
    #define STM32_CORE_VERSION_EXTRA (0x00U) /*!< [7:0] extra version */
    #define STM32_CORE_VERSION ((STM32_CORE_VERSION_MAJOR << 24U)\
    |(STM32_CORE_VERSION_MINOR << 16U)\
    |(STM32_CORE_VERSION_PATCH << 8U )\
    |(STM32_CORE_VERSION_EXTRA))

    Hardware Revision:How can I check that ?
    on the sticker you should have something like MB1312 X where X is is the revision, anyway this is not very important in our case.

    I don't use any extra pull-up resistors.. Only connect a micro-controller to my STM with level shifter in the middle.

    Could you be more precise about this? which microconttoller and level shifter? how are they wired.
    I2C lines require PULL up so ensure to have them on your wiring.

  13. 11 remaining items

  14. fpistm commented on Sep 26, 2019

    @fpistm
    Member

    I will try to see if I'm able to remove uint8_t date size limitations as HAL can handle uint16_t but I could not promise. In that case you would be able to send your 0x1000 in 16 times.

  15. amirc2013 commented on Sep 26, 2019

    @amirc2013
    Author

    I wish you luck, it is really important to me.
    Thank you for the help :)

  16. urosh-dev commented on Nov 8, 2019

    @urosh-dev

    Any updates on that. I have the same issue. I cant send string with Wire. for example Wire.write("hello");
    Using blue pill and raspberry pi with command from raspberry pi :
    bus.read_i2c_block_data(address,4)
    or
    bus.read_byte(address)
    Blue pill just hangs up.

  17. fpistm commented on Nov 8, 2019

    @fpistm
    Member

    Any updates on that. I have the same issue. I cant send string with Wire. for example Wire.write("hello");
    Using blue pill and raspberry pi with command from raspberry pi :
    bus.read_i2c_block_data(address,4)
    or
    bus.read_byte(address)
    Blue pill just hangs up.

    This is not related. Here the issue is for buffer higher than 32 in receive

  18. fpistm commented on Dec 16, 2019

    @fpistm
    Member

    Current status:

    • Master:

      • can write up to 255 (limited by Arduino API uint8_t)
      • can read up to 32
    • Slave:

      • can read/write up to 32

    32 is the Arduino standard. The Master Tx has been extend to support the X-Shield NFC nevertheless
    the Rx should be able to receive also 255 bytes. And Slave should be able to write also up to 255.

  19. removed this from the 1.8.0🎄 🎅 milestone on Dec 16, 2019
  20. added this to the 1.9.0 milestone on Dec 20, 2019
  21. ABOSTM commented on Jan 3, 2020

    @ABOSTM
    Contributor

    Hi @amirc2013,
    with implementation of PR #853, the status is 255 bytes transfer in any direction
    (254 with the bug identified see warning).
    But still limited by Arduino API uint8_t

  22. modified the milestones: 1.9.0, on Jan 6, 2020
  23. modified the milestones: , 1.9.0 on Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug 🐛Something isn't working

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions