Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Wire Library missing size_t requestFrom(uint8_t address, size_t len, bool stopBit)

  1. #1
    Junior Member
    Join Date
    Oct 2020
    Posts
    5

    Wire Library missing size_t requestFrom(uint8_t address, size_t len, bool stopBit)

    According to the Arduino API
    https://github.com/arduino/ArduinoCo...dwareI2C.h#L39

    Teensy Wire library is missing this function prototype


    Code:
    size_t requestFrom(uint8_t address, size_t len, bool stopBit)
    this is causing ArduinoECCX08 to not work with teensy. I have create a PR https://github.com/PaulStoffregen/Wire/pull/36 would appreciate if some one from the team can review and merge it

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,768
    In my view, the problem lies within the library itself. The only reason that the example code doesn't compile is because the private receiveResponse function requires a "size_t length" argument which is not necessary. Since it is a private function, the only calls to it are from within ECCX08.cpp and none of them actually NEED the length argument to be size_t. They can be "int", in fact in most cases uint8_t would suffice.

    Can you try replacing the receiveResponse function in ECCX08.cpp with this:
    Code:
    int ECCX08Class::receiveResponse(void* response, size_t length)
    {
      int retries = 20;
      
    //>>>PAH
    //#define ORIGINAL
    #ifdef ORIGINAL
      size_t responseSize = length + 3; // 1 for length header, 2 for CRC
      byte responseBuffer[responseSize];
    
      while (_wire->requestFrom((uint8_t)_address, (size_t)responseSize, (bool)true) != responseSize && retries--);
    
    #else
    
      int responseSize = (int)(length + 3); // 1 for length header, 2 for CRC
      byte responseBuffer[responseSize];
    
      while (_wire->requestFrom((int)_address, responseSize, 1) != responseSize && retries--);
    
    #endif
      responseBuffer[0] = _wire->read();
    
      // make sure length matches
      if (responseBuffer[0] != responseSize) {
        return 0;
      }
    
      for (size_t i = 1; _wire->available(); i++) {
        responseBuffer[i] = _wire->read();
      }
    
      // verify CRC
      uint16_t responseCrc = responseBuffer[length + 1] | (responseBuffer[length + 2] << 8);
      if (responseCrc != crc16(responseBuffer, responseSize - 2)) {
        return 0;
      }
      
      memcpy(response, &responseBuffer[1], length);
    
      return 1;
    }
    I'm pretty sure it covers all contingencies but I have no way of testing it - other than it compiles

    Pete

  3. #3
    Junior Member
    Join Date
    Oct 2020
    Posts
    5
    I should have clarified the issue is not with the size_t but with the parameter bool sendstop.
    https://github.com/arduino-libraries...sue-1027169928

    the wire library is missing that. Also there have been other platforms which had the issue but people from arduino recommended have this change in the core of the platform. https://github.com/arduino-libraries...ment-886475456

    The second issue is with the BufferLength the default value is 32 but the ATECC608B chip has cases where it needs to send messages greater than that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •