I2C test

For general Flowcode discussion that does not belong in the other sections.
samtin
Posts: 47
http://meble-kuchenne.info.pl
Joined: Sat Jul 10, 2021 2:43 pm
Has thanked: 12 times
Been thanked: 6 times

Re: I2C test

Post by samtin »

Hi Martin,

Yes, you have really been a great help and I thank you. When you have time and if you want, tell me how I should proceed when I change the source code to "FC_Comp_Source_Serial_EEPROM_(24LC512)" for example, how to get the fcpx file.

All the best!

samtin
Posts: 47
Joined: Sat Jul 10, 2021 2:43 pm
Has thanked: 12 times
Been thanked: 6 times

Re: I2C test

Post by samtin »

Hi Martin,

Now I noticed that I actually used another component in the test, instead of using the 24LC256 component.
The 24LC256 does not work, the eeprom component is not visible on the 2D panel, and in the properties I do not have the option to write at least one byte, in the data field it does not allow me to add parentheses, when editing the data variable in the initial value field I passed 4 bytes, but did not store them in the eeprom locations starting from address 0.

All the best!

mnfisher
Valued Contributor
Posts: 1462
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 135 times
Been thanked: 713 times

Re: I2C test

Post by mnfisher »

The component I did doesn't simulate - it will only run on hardware (in the bad old days you had to pay for components)

Can you post your code so far?

Martin

samtin
Posts: 47
Joined: Sat Jul 10, 2021 2:43 pm
Has thanked: 12 times
Been thanked: 6 times

Re: I2C test

Post by samtin »

Hi Martin,

Of course I have attached the fc file.
Attachments
test eeprom.fcfx
(18.95 KiB) Downloaded 107 times

mnfisher
Valued Contributor
Posts: 1462
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 135 times
Been thanked: 713 times

Re: I2C test

Post by mnfisher »

Looks like this should work on hardware (you might need to change the capacity if you have 512Kb chip)

Note that it will do nothing in simulation (sorry) - and that Read and Write only work on an array of data - so if you have
ReadData(data, 4) - it will read 4 bytes into data (which needs to have room for this) so this doesn't need to be in a loop.

StartRead(0)
ReadData(data, 4) // Read bytes 0,1,2,3 to data
ReadData(d1, 4) // Read bytes 4,5,6,7 to d1

Similarly - WriteData(data, 4) will write 4 bytes to the eeprom (and increment the address by 4) so:

StartWrite(0)
WriteData(data, 4) // Write to addresses 0,1,2,3
WriteData(d1, 4) // Write to address 4,5,6,7

Note that the size can be more or less than 4 (depending the size of data / d1) - and data needs to be an array (this makes reading a single byte slightly more convoluted - ReadByte(data, 1) then need x = data[0]

I've tweaked and commented a few lines of your code.

Martin
Attachments
test eeprom.fcfx
(18.4 KiB) Downloaded 106 times

samtin
Posts: 47
Joined: Sat Jul 10, 2021 2:43 pm
Has thanked: 12 times
Been thanked: 6 times

Re: I2C test

Post by samtin »

Good morning,

The data to be written are taken from the initial value {0, 1, 2, 3}.
Is there another option where other data can be written apart from those in the initial value?

mnfisher
Valued Contributor
Posts: 1462
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 135 times
Been thanked: 713 times

Re: I2C test

Post by mnfisher »

Yes, just set data to the values you exam to write.

StartWrite(address) sets the address to start writing the data to.
So
StartWrite(23)
data[0]=56
data[1] =99
WriteData(data, 2)

Will write 56, 99 to addresses 23 and 24 in the Eeprom

samtin
Posts: 47
Joined: Sat Jul 10, 2021 2:43 pm
Has thanked: 12 times
Been thanked: 6 times

Re: I2C test

Post by samtin »

Perfect, I will try to test on the board. Now I make some notifications for some previous studies.
Thanks Martin

mnfisher
Valued Contributor
Posts: 1462
Joined: Wed Dec 09, 2020 9:37 pm
Has thanked: 135 times
Been thanked: 713 times

Re: I2C test

Post by mnfisher »

Please let us know how it goes 😊

samtin
Posts: 47
Joined: Sat Jul 10, 2021 2:43 pm
Has thanked: 12 times
Been thanked: 6 times

Re: I2C test

Post by samtin »

Hi Martin,
It works perfectly, I'll come back later with a more concise flowchart, I have to delete the components that I no longer need.

Post Reply