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

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
 
I should have clarified the issue is not with the size_t but with the parameter bool sendstop.
https://github.com/arduino-libraries/ArduinoECCX08/issues/36#issue-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/ArduinoECCX08/pull/30#issuecomment-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.
 
Back
Top