<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://wiki.mcselec.com/bavr/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.mcselec.com/bavr/index.php?action=history&amp;feed=atom&amp;title=I2C_TWI-MULTI.lib</id>
		<title>I2C TWI-MULTI.lib - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.mcselec.com/bavr/index.php?action=history&amp;feed=atom&amp;title=I2C_TWI-MULTI.lib"/>
		<link rel="alternate" type="text/html" href="http://wiki.mcselec.com/bavr/index.php?title=I2C_TWI-MULTI.lib&amp;action=history"/>
		<updated>2026-04-30T09:45:51Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.18.6</generator>

	<entry>
		<id>http://wiki.mcselec.com/bavr/index.php?title=I2C_TWI-MULTI.lib&amp;diff=5474&amp;oldid=prev</id>
		<title>Admin at 19:49, 17 January 2017</title>
		<link rel="alternate" type="text/html" href="http://wiki.mcselec.com/bavr/index.php?title=I2C_TWI-MULTI.lib&amp;diff=5474&amp;oldid=prev"/>
				<updated>2017-01-17T19:49:54Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
			&lt;col class='diff-marker' /&gt;
			&lt;col class='diff-content' /&gt;
		&lt;tr valign='top'&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 19:49, 17 January 2017&lt;/td&gt;
		&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 129:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 129:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;br/&amp;gt;{{Languages}}&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;&amp;lt;br/&amp;gt;{{Languages}}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background: #eee; color:black; font-size: smaller;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;background: #ffa; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;[[Category:&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;BASCOM Language Reference&lt;/del&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;background: #cfc; color:black; font-size: smaller;&quot;&gt;&lt;div&gt;[[Category:&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;ASM Libraries and Add-Ons&lt;/ins&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	<entry>
		<id>http://wiki.mcselec.com/bavr/index.php?title=I2C_TWI-MULTI.lib&amp;diff=5473&amp;oldid=prev</id>
		<title>Admin: Created page with &quot;The I2C_TWI-MULTI library is intended to be used with normal AVR processors which have 2 or more TWI interfaces.  An example of such a processor is the ATMEGA328&lt;span style=&quot;f...&quot;</title>
		<link rel="alternate" type="text/html" href="http://wiki.mcselec.com/bavr/index.php?title=I2C_TWI-MULTI.lib&amp;diff=5473&amp;oldid=prev"/>
				<updated>2017-01-17T19:47:42Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;The I2C_TWI-MULTI library is intended to be used with normal AVR processors which have 2 or more TWI interfaces.  An example of such a processor is the ATMEGA328&amp;lt;span style=&amp;quot;f...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;The I2C_TWI-MULTI library is intended to be used with normal AVR processors which have 2 or more TWI interfaces.&lt;br /&gt;
&lt;br /&gt;
An example of such a processor is the ATMEGA328&amp;lt;span style=&amp;quot;font-weight: bold;&amp;quot;&amp;gt;PB&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
In order to support multiple busses, this library need to be included using the $LIB directive.&lt;br /&gt;
&lt;br /&gt;
Further you need to create a byte variable named _i2cchannel in your code.&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
This variable will hold the bus or TWI number.&lt;br /&gt;
&lt;br /&gt;
By default it will be 0 and thus the usual TWI hardware will be used&amp;amp;nbsp;: &amp;amp;nbsp;Portc.5 &amp;amp;nbsp;and &amp;amp;nbsp;Portc.4&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
By setting the variable to 1, the second TWI hardware will be used&amp;amp;nbsp;: &amp;amp;nbsp; Porte.0 &amp;amp;nbsp;and Porte.1&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
Further you need to use CONFIG TWI1 instead of CONFIG TWI in order to specify the clock rate for the second TWI&amp;amp;nbsp;: Config Twi1 = 100000&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
All other code will remain compatible.&lt;br /&gt;
&lt;br /&gt;
&amp;amp;nbsp;&lt;br /&gt;
&lt;br /&gt;
= &amp;lt;span class=&amp;quot;f_Header&amp;quot;&amp;gt;Example&amp;lt;/span&amp;gt; =&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bascomavr&amp;quot;&amp;gt;&lt;br /&gt;
'--------------------------------------------------------------------------------&lt;br /&gt;
'name : m328pb.bas&lt;br /&gt;
'copyright : (c) 1995-2016, MCS Electronics&lt;br /&gt;
'purpose : demonstrates M328pb&lt;br /&gt;
'micro : Mega328pb&lt;br /&gt;
'suited for demo : yes&lt;br /&gt;
'commercial addon needed : no&lt;br /&gt;
'--------------------------------------------------------------------------------&lt;br /&gt;
$regfile = &amp;quot;m328pbdef.dat&amp;quot;&lt;br /&gt;
$crystal = 8000000&lt;br /&gt;
$baud = 19200&lt;br /&gt;
$hwstack = 40&lt;br /&gt;
$swstack = 40&lt;br /&gt;
$framesize = 40&lt;br /&gt;
 &lt;br /&gt;
' USART TX RX&lt;br /&gt;
' 0 D.1 D.0&lt;br /&gt;
' 1 B.3 B.4&lt;br /&gt;
 &lt;br /&gt;
' ISP programming&lt;br /&gt;
' MOSI-PB3 MISO-PB4 SCK-PB5&lt;br /&gt;
 &lt;br /&gt;
' TWI SDA SCL&lt;br /&gt;
' 0 C.4 C.5&lt;br /&gt;
' 1 E.0 E.1&lt;br /&gt;
 &lt;br /&gt;
'Configuration&lt;br /&gt;
 &lt;br /&gt;
Config Clockdiv = 1 'make sure we get 8 Mhz from internal osc&lt;br /&gt;
 &lt;br /&gt;
Config Com1 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0&lt;br /&gt;
Config Com2 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0&lt;br /&gt;
 &lt;br /&gt;
'we have 2 TWI interfaces&lt;br /&gt;
Config Scl = Portc.5 ' we need to provide the SCL pin name&lt;br /&gt;
Config Sda = Portc.4 ' we need to provide the SDA pin name&lt;br /&gt;
 &lt;br /&gt;
Config Sda1 = Porte.0 'use this for the second TWI&lt;br /&gt;
Config Scl1 = Porte.1&lt;br /&gt;
 &lt;br /&gt;
Config Twi = 100000 'speed 100 KHz&lt;br /&gt;
Config Twi1 = 100000 'speed 100 KHz&lt;br /&gt;
 &lt;br /&gt;
'some constants for the signature row&lt;br /&gt;
Const Device_signature_byte1 = 0&lt;br /&gt;
Const Device_signature_byte2 = 2&lt;br /&gt;
Const Device_signature_byte3 = 4&lt;br /&gt;
 &lt;br /&gt;
Const Rc_oscillator_calibration = 1&lt;br /&gt;
 &lt;br /&gt;
Const Serial_number_byte0 = &amp;amp;H0E&lt;br /&gt;
Const Serial_number_byte1 = &amp;amp;H0F&lt;br /&gt;
Const Serial_number_byte2 = &amp;amp;H10&lt;br /&gt;
Const Serial_number_byte3 = &amp;amp;H11&lt;br /&gt;
Const Serial_number_byte4 = &amp;amp;H12&lt;br /&gt;
Const Serial_number_byte5 = &amp;amp;H13&lt;br /&gt;
Const Serial_number_byte6 = &amp;amp;H14&lt;br /&gt;
Const Serial_number_byte7 = &amp;amp;H15&lt;br /&gt;
Const Serial_number_byte8 = &amp;amp;H16&lt;br /&gt;
Const Serial_number_byte9 = &amp;amp;H17&lt;br /&gt;
 &lt;br /&gt;
$lib &amp;quot;I2C_TWI-MULTI.lib&amp;quot; 'important for using 2 TWI interfaces&lt;br /&gt;
 &lt;br /&gt;
Dim _i2cchannel As Byte ' you MUST dim this variable yourself when using the above lib&lt;br /&gt;
Dim B As Byte 'just a used byte&lt;br /&gt;
 &lt;br /&gt;
I2cinit 'default TWI init&lt;br /&gt;
I2cinit Twi1 'optional specify TWI1 to init that interface&lt;br /&gt;
 &lt;br /&gt;
Open &amp;quot;com2:&amp;quot; For Binary As #2 'create a channel to reference the UART&lt;br /&gt;
 &lt;br /&gt;
'print the chip ID&lt;br /&gt;
Print &amp;quot;ID : &amp;quot; ; Hex(readsig(device_signature_byte1)) ; Hex(readsig(device_signature_byte2)) ; Hex(readsig(device_signature_byte3))&lt;br /&gt;
 &lt;br /&gt;
'all I2C statements will work the same. All you need to do is to set the _i2cchannel variable to 0 or 1&lt;br /&gt;
_i2cchannel = 1 'try the second bus&lt;br /&gt;
 &lt;br /&gt;
Print &amp;quot;Scan start&amp;quot;&lt;br /&gt;
For B = 0 To 254 Step 2 'for all odd addresses&lt;br /&gt;
I2cstart&lt;br /&gt;
I2cwbyte B 'send address&lt;br /&gt;
If Err = 0 Then 'we got an ack&lt;br /&gt;
 Print &amp;quot;Slave at : &amp;quot; ; B ; &amp;quot; hex : &amp;quot; ; Hex(b) ; &amp;quot; bin : &amp;quot; ; Bin(b)&lt;br /&gt;
End If&lt;br /&gt;
I2cstop 'free bus&lt;br /&gt;
Next&lt;br /&gt;
 &lt;br /&gt;
 &lt;br /&gt;
Do&lt;br /&gt;
 Print &amp;quot;COM1&amp;quot;&lt;br /&gt;
 Print #2 , &amp;quot;COM2&amp;quot;&lt;br /&gt;
 Waitms 1000&lt;br /&gt;
Loop&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br/&amp;gt;{{Languages}}&lt;br /&gt;
&lt;br /&gt;
[[Category:BASCOM Language Reference]]&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>