Report Bugs Here

Moderator: Mmiscool

User avatar
By matherp
#32817 Thanks for the asc and chr functions

These confirm what I suspected: that you are storing the strings in C format i.e. zero terminated.

This means one of the standard uses of strings in Basic, as a byte array, can't be used if a zero is needed in the array.

The result of this is that strings cannot be used in I2C where 0 is often a valid data item.

At the moment i2c.write and i2c.read both use strings so i2c isn't usable for any device where 0 is a valid data item to be transmitted or received. This applies to many devices where registers start from address 0.

As per my previous post in this thread, please could you generate a version of the i2c code which uses integers as the parameters rather than strings.

Please also note the same will apply if/when you implement SPI functionality

The alternative is of course to convert string to use standard Basic format: length byte in position 0. This would be the preferred option but is a much bigger piece of work.
User avatar
By Mmiscool
#32856 Just posted a new build. It implements the code you provided

if (FunctionName == "i2c.write") MyOut = String(Wire.write(Param0.to_Int()));


Lets see how that works.
User avatar
By matherp
#32859 That is looking much better :D

I'm now getting data back from the RTC.

I need one new function and I can let you have an example program.

Please can you implement:

INT(x) returns the integer part of x

The RTC returns data in BCD so I need to go
highnum = BCD / 16
highnum = INT(highnum)
a = highnum * 16
lownum= BCD - a
User avatar
By Mmiscool
#32865 How is this different from the asc() function?

Just need to know what needs to be implemented.

This is the internal code for the the asc() function. Gusing that it would be n easy mod for what you need. Just need to understand what you need.
Code: Select all  if (FunctionName == "asc")
  {
    char bla = Param0.charAt(0);
    int blabla = bla ;
    MyOut = String(blabla);
  }