<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Write registers and BITs i2C within a library</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7223fbf476/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7223fbf476/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/7223fbf476/</id><updated>2021-07-16T21:56:42.122000Z</updated><subtitle>Recent posts to Write registers and BITs i2C within a library</subtitle><entry><title>Write registers and BITs i2C within a library</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7223fbf476/?limit=25#f0b5" rel="alternate"/><published>2021-07-16T21:56:42.122000Z</published><updated>2021-07-16T21:56:42.122000Z</updated><author><name>Ingo</name><uri>https://forge.codesys.com/u/ingo/</uri></author><id>https://forge.codesys.comc8a5dd617eb870e52e469c3f39153be26109fb7a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi!&lt;br/&gt;
This actually can be very easy, when I got your question right 😉. I would intuitively use Write8, as you did.&lt;br/&gt;
The interface is roughly:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="err"&gt;Write8(usiRegister, usiValue)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;So, to write your bit 4 to register 1, you need to call s.th. like this:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="k"&gt;start&lt;/span&gt; &lt;span class="n"&gt;counting&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0000&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;
&lt;span class="n"&gt;Write8&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="k"&gt;start&lt;/span&gt; &lt;span class="n"&gt;counting&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0001&lt;/span&gt; &lt;span class="mi"&gt;0000&lt;/span&gt;
&lt;span class="n"&gt;Write8&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Alternatively, you can write it in binary form, instead of hex:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="k"&gt;start&lt;/span&gt; &lt;span class="n"&gt;counting&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;Write8&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;00001000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="o"&gt;//&lt;/span&gt; &lt;span class="k"&gt;when&lt;/span&gt; &lt;span class="n"&gt;you&lt;/span&gt; &lt;span class="k"&gt;start&lt;/span&gt; &lt;span class="n"&gt;counting&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="n"&gt;Write8&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;#&lt;/span&gt;&lt;span class="mi"&gt;00010000&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Write registers and BITs i2C within a library</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7223fbf476/?limit=25#e626" rel="alternate"/><published>2021-07-16T13:16:50.680000Z</published><updated>2021-07-16T13:16:50.680000Z</updated><author><name>mrpioneer</name><uri>https://forge.codesys.com/u/mrpioneer/</uri></author><id>https://forge.codesys.comc834b8ba20020a1ea034c81fd13056d42cf63716</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;write8&lt;/p&gt;
&lt;p&gt;write8(1, 16#40); If i understand it correct should this write BIT 4 in register 01?&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;write&lt;/p&gt;
&lt;p&gt;HoldCmd :BYTE :=16#F4;&lt;br/&gt;
write(ADR(HoldCmd),1); &lt;br/&gt;
This will write a byte into register 16 # F4.&lt;br/&gt;
But what bits?&lt;br/&gt;
All to 1 or all to 0 or something completely different?&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;writeBits&lt;/p&gt;
&lt;p&gt;But unfortunately I have no idea how to use this command.&lt;/p&gt;
&lt;p&gt;I would be very grateful for a short description&lt;/p&gt;
&lt;p&gt;Input   usiRegister USINT   register&lt;br/&gt;
usiFirstBit USINT   highest value bit to write (0..7)&lt;br/&gt;
usiLength   USINT   number of bits to write (1..usiFirstBit+1)&lt;br/&gt;
usiValue    USINT   value of the bits to set (0..2^usiLength-1)&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;Thanks in advance.&lt;/p&gt;
&lt;p&gt;BR&lt;br/&gt;
MR. Pioneer&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Write registers and BITs i2C within a library</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/7223fbf476/?limit=25#1e6e" rel="alternate"/><published>2021-07-12T16:11:17.408000Z</published><updated>2021-07-12T16:11:17.408000Z</updated><author><name>mrpioneer</name><uri>https://forge.codesys.com/u/mrpioneer/</uri></author><id>https://forge.codesys.com6990695472450b76e81cd9f938a11641a4555456</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hello everybody,&lt;/p&gt;
&lt;p&gt;I need a brief explanation.&lt;br/&gt;
I would like to create an i2C library in which I have to write individual bits in different registers.&lt;/p&gt;
&lt;p&gt;Specifically, this means&lt;/p&gt;
&lt;p&gt;Register (0x01)&lt;br/&gt;
Bit 4&lt;/p&gt;
&lt;p&gt;Possibly can someone write me a short code how this works.&lt;/p&gt;
&lt;p&gt;I have the following methods available within the library.&lt;br/&gt;
write&lt;br/&gt;
write8&lt;br/&gt;
writebits&lt;/p&gt;
&lt;p&gt;Thanks in advance.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>