@AlexanderH Hi Alexander,
Great to see you experimenting with REXYGEN and getting good results so far! It’s nice that you started from the example library — that’s definitely the right approach. The I2C function in REXYGEN works a bit differently compared to Arduino or other low-level implementations. Since REXYGEN tasks usually don’t run with very short cycle times, a single I2C call performs both write and read operations within one cycle. This command takes care of sending the message, waiting briefly, and then reading the response. That means you don’t need to manually handle the NAK or stop condition — the function itself takes care of it.
I looked through your code and have a few notes that might help:
- I noticed that right after calculating
channel1, you have areturn 0;. Because of that, the code for channel2 never runs — I guess that’s just for debugging, but it’s worth pointing out. - In each REXYGEN cycle, you currently configure the converter for continuous read mode. This might not behave as you expect, and it’s probably unnecessary. Try switching to one-shot mode first and see what kind of values you get. Later, you can set continuous mode once, and then in your
main()you can just read the data by settingi2c_write_count = 0. That way, theI2Cfunction won’t send any configuration bytes, it will only read — according to the documentation, that should work. - You can use the
Trace()function to print out the value ofi2c_ret_funfor debugging. Keep in mind that you need to enable these messages in the system log:
Go to Target → Diagnostic messages, tick Information in Function block messages, and make sure Enable logging is checked in the Options tab of the block properties dialog. Only then you’ll see the messages in the System log. - And finally, double-check the I2C address of the MCP3424 — it’s configurable, so make sure it matches your hardware setup.
Hope this helps you move forward! Please let us know how it goes — it’s always interesting to see REXLANG + I2C projects in action.
Cheers,
Jan

