Author Topic: Is there a way to write from a user memory location to I2C?  (Read 2204 times)

matt_vs

  • Full Member
  • ***
  • Posts: 15
    • View Profile
Is there a way to write from a user memory location to I2C?
« on: January 20, 2014, 10:04:43 AM »
Hello-

I know how to read from the I2C bus and place that value into user memory at a given address:
            i2c1BeginTransmission(0x9C);                                  //Begin transmission to DIPswitch2
            i2c1Write(0x00);                                                     //Write register address for Configuration = 0x00
            i2c1ReadToArray(&userRam[0x52], 1);                     //Read 1 byte from DIPswitch2, and save to given pointer
            i2c1EndTransmission();

This will read one byte from slave 0x9C register 00 and place it at user memory location 0x52.
Now I will manipulate this memory location value and I want to write it back to the I2C bus - how can I do that?
Is there a command to write from a memory location to the I2C bus?

Thanks!


modtro2

  • Administrator
  • Hero Member
  • *****
  • Posts: 564
    • View Profile
Re: Is there a way to write from a user memory location to I2C?
« Reply #1 on: January 22, 2014, 02:55:29 PM »
Hi Matt

The i2cWriteMessage() function does this. For example, to write 1 byte of user memory at location 0x52, to slave at 0x9C, use:
Code: [Select]
i2c1WriteMessage(0x9C, &nzGlobals.userRam[0x52], 1);    //Write Byte 1 (user ram 0x52) to slave at 0x9C

Please note that "userRam" is now a member of nzGlobals. So, when you download the new V2.03 Beta, you will have to update all "userRam" references in your code to "nzGlobals.userRam".
« Last Edit: January 22, 2014, 02:57:26 PM by modtro2 »

matt_vs

  • Full Member
  • ***
  • Posts: 15
    • View Profile
Re: Is there a way to write from a user memory location to I2C?
« Reply #2 on: January 24, 2014, 07:47:28 AM »
Hello-

I'm a little confused about this one - When I tried to add this code to my main.c the compiler complained that the variable nzGlobals.userRam wasn't defined.

I am running www.netcruzer.com/nz/netcruzer_v203beta140107.zip
Which I think is the latest - correct?

My code also still has the original user ram references like below:
i2c1ReadToArray(&userRam[0x20+(channel*2)], 2); //Read 2 bytes from I2C slave, and save to given pointer

And it is working just fine. I never changed the variable callouts when I updated to the version listed above

Do you know what include file has the variable declaration for the new nzGlobals or what library I need to include?

Thanks again!

modtro2

  • Administrator
  • Hero Member
  • *****
  • Posts: 564
    • View Profile
Re: Is there a way to write from a user memory location to I2C?
« Reply #3 on: January 27, 2014, 04:03:41 PM »
This has been added in current code, which has not been released yet. I uploaded the current code for you to test. You can download it here:
www.netcruzer.com/nz/netcruzer_v203_current1401281047.zip

It is not the final V2.03 yet, still have some issues with Cookies. But, you don't use them. Please update your code with this version.

Best will be if you replace all your existing code with this code. Then, just overwrite the main.c in the "projects/webserver" folder with your main.c. I however also made some changes to my main.c for this project. For example, to check if User Memory 0x42 and 0x43 have been modified via the web pages. See the "main_I2C_Power_Demo.c" file for my current version. You will probably have to merge your main.c with this file. The following line in processIO() does this check:
Code: [Select]
if (vaEnable != USER_RAM_WORD(0x42))