<div dir="ltr"><div dir="ltr"></div><div>See comments below.<br></div><div><br></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 4, 2023 at 6:52 PM Bo Berglund via fpc-pascal <<a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I use the method:<br>
<br>
i2cMaster.WriteBytesToReg(i2caddress: byte; regAddress: uint16; data: PByte;<br>
size: byte): boolean;)<br>
<br>
With data specified as follows in the call:<br>
<br>
if not i2cMaster.WriteBytesToReg(FEEPROMAddr, startaddress, @source[0],<br>
NumBytes) then<br>
<br>
Here the source argument is a TBytes array of bytes so I supply the address of<br>
element 0 as the data argument (expected to be a PByte).<br></blockquote><div><br></div><div>This is the correct way of passing the starting address of your data buffer. Is your startaddress variable an unsigned 16 bit integer (word/uint16)? If not, type cast this to a uint16 to ensure the compiler calls the correct overloaded method.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
When I step through this in the debugger and get into the method itself I can<br>
see that the source argument contains the data I have loaded into it, so the<br>
data is there.<br>
<br>
When I run that method to the end and it finishes without error, I still cannot<br>
see the data in the EEPROM at the given address.<br>
<br>
So for testing I changed the call to be:<br>
if not i2cMaster.WriteByteToReg(FEEPROMAddr, startaddress, source[0]) then<br>
<br>
This uses the method to write a single byte to the i2c device and it works just<br>
fine!<br>
<br>
So either there is a problem with the WriteBytesToReg() method or else my use of<br>
it...<br></blockquote><div><br></div><div>Note that I haven't tested WriteByteToReg with a device supporting 10 bit register addresses, or in your case 16 bit...</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
What comes to mind is the data type PByte, which I have never used before and do<br>
not know if it is valid.<br></blockquote><div><br></div><div>PByte is a pointer to a byte.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
I am keeping the data in a dynamic array of bytes (the pascal type TBytes) and<br>
send the address of element 0 of that array as the argument to the method.<br>
Is this wrong?<br></blockquote><div><br></div><div> Passing the address of the first element of a TBytes array as you did above is correct.<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
If so what should I use instead?<br>
Can I typecast it like this:<br>
<br>
if not i2cMaster.WriteBytesToReg(FEEPROMAddr, startaddress, PByte(source),<br>
NumBytes) then<br>
(Tried it and it does not work)<br></blockquote><div><br></div><div>No, this does not take the address of source, which is waht is required.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
????<br>
<br>
Seems like I am getting close but missing something important...<br></blockquote><div><br></div><div>I will look at the EEPROM datasheet, in case the details do not agree with the WriteBytesToReg implementation.<br></div></div></div>