Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ambiguity when trying to use the requestFrom #6

Closed
mackelec opened this issue Oct 25, 2023 · 2 comments
Closed

ambiguity when trying to use the requestFrom #6

mackelec opened this issue Oct 25, 2023 · 2 comments

Comments

@mackelec
Copy link

I got a compilation warning regarding ambiguity when trying to use the requestFrom method.

I was using Arduino IDE 1.8.19, Target DUE.

In function uint8_t JC_EEPROM::read

I changed to this to sort the warning out.

                int intAddress = static_cast<int>(ctrlByte);
		int intCount = static_cast<int>(nRead);
		Wire.requestFrom(intAddress, intCount);
@JChristensen
Copy link
Owner

JChristensen commented Oct 26, 2023

I believe the proper fix would be

Wire.requestFrom(ctrlByte, static_cast<uint8_t>(nRead));

There are several other similar calls, looks like I may have missed the cast in one or two.
Oddly, when compiling for AVR, I do not see the warning, but I do when compiling for the DUE. Seems like I should see it in both cases. Might be compiler options or other differences in the tool chain.

I'm going to have to look at it for a bit. Stand by.

@JChristensen
Copy link
Owner

JChristensen commented Oct 26, 2023

Would you test this please and let me know if it fixes the issue.
Replace the JC_EEPROM.cpp file with the attached.
If it works OK, then I'll push a new version.
Just two lines changed:

diff --git a/src/JC_EEPROM.cpp b/src/JC_EEPROM.cpp
index 204d4f3..3f0a7dd 100644
--- a/src/JC_EEPROM.cpp
+++ b/src/JC_EEPROM.cpp
@@ -76,7 +76,7 @@ uint8_t JC_EEPROM::write(uint32_t addr, uint8_t* values, uint16_t nBytes)
         Wire.beginTransmission(ctrlByte);
         if (m_nAddrBytes == 2) Wire.write(static_cast<uint8_t>(addr >> 8)); // high addr byte
         Wire.write(static_cast<uint8_t>(addr));                             // low addr byte
-        Wire.write(values, nWrite);
+        Wire.write(values, static_cast<uint8_t>(nWrite));
         txStatus = Wire.endTransmission();
         if (txStatus != 0) return txStatus;
 
@@ -119,7 +119,7 @@ uint8_t JC_EEPROM::read(uint32_t addr, uint8_t* values, uint16_t nBytes)
         uint8_t rxStatus = Wire.endTransmission();
         if (rxStatus != 0) return rxStatus;     // read error
 
-        Wire.requestFrom(ctrlByte, nRead);
+        Wire.requestFrom(ctrlByte, static_cast<uint8_t>(nRead));
         for (byte i=0; i<nRead; i++) values[i] = Wire.read();
 
         addr += nRead;          // increment the EEPROM address

jc_eeprom.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants