Requesting Guidance on Proper Way to Call rd_block(p_block, count, ackbit) in jm_i2c.spin2

@JonnyMac What's the proper way to use this call with an array of bytes? Currently, I'm trying the following:

i2c : "jm_i2c"
byte data[30]

pub go()

I just want to verify I'm call the method correctly.


  • Your syntax is correct. Are you having problems? I do my best to test code very carefully, but I am in fact human. :)
  • I doubt it's your code. I'm sure I'm doing something wrong. I'm trying to read multiple registers at a time from a RV-3028-C7 RTC. I can write to it fine and read each register independently but I've yet to have a successful multiple register read. I may need to set a mode or something. I'm getting all $FF's instead of the expected values 00,01,02,03,etc. As soon as I finish helping my brother from Lake Charles unload his truck, I'll get back to the fun stuff. If I can't get it by tonight I'll post some code. Thanks.
  • JonnyMacJonnyMac Posts: 7,008
    edited 2020-10-09 - 15:27:23
    I just finished coding the Click RTC 10 object a few days ago. This method lets you do that -- should be similar for your RTC.
    pub generic_read(r, p_buf, len)
    '' Read block of registers from RTC to p_buf
    '' -- r is first register
    '' -- p_buf is pointer to destination bytes
    '' -- len is number of registers to read
      i2c.rd_block(p_buf, len, i2c.NAK)
    Remember... to do an I2C read you have to restart and send the slave address with bit 0 set to 1. I have these constants in my object.
      DS3231M_WR = %1101_000_0                                      ' i2c slave id
      DS3231M_RD = %1101_000_1
  • JonnyMacJonnyMac Posts: 7,008
    edited 2020-10-09 - 19:00:29
    A few minutes later...
    You should be able to write a routine like this for your RTC (Warning: not tested, not polished -- change magic #s to constants)
    pub get_unix_time() : unixtime
      i2c.rd_block(@unixtime, 4, i2c.NAK)
  • Your generic_read method made me realize, when I started using your rd_block call I hadn't added the i2c.start() and i2c.write(slaveReadAddress) calls before it. Stupid mistake on my part. This damn hurricane has me distracted. Everything is working as expected now. Thanks for the help.
  • Glad to help. I hope you and your family are safe from the storm.
Sign In or Register to comment.