Tuesday, 19 March 2024
     
 
Latest News
Main Menu
Home Home
Shop Shop
News News
BASCOM-AVR BASCOM-AVR
BASCOM-8051 BASCOM-8051
Products Products
Application Notes Application Notes
Publications Publications
Links Links
Support Center Support Center
Downloads Downloads
Forum Forum
Resellers Resellers
Contact Us Contact Us
Updates Updates
MCS Wiki MCS Wiki
Online Help
BASCOM-AVR Help BASCOM-AVR Help
BASCOM-8051 Help BASCOM-8051 Help
Contents in Cart
Show Cart
Your Cart is currently empty.
Search the Shop

Products Search

User Login
Username

Password

If you have problem after log in with disappeared login data, please press F5 in your browser

Polls
RSS News
Check the Shop
  Random 
Random
 

SE-ESB-P
SE-ESB-P
EUR 24.14


BASCOM-AVR (Download version)
BASCOM-AVR (Download version)
EUR 107.69


 
     
 

 
 
Popular
 
     
 
Shopping zone
Categories

List All Products


Advanced Search
Shop Download Area
Show Cart
Your Cart is currently empty.






I2CSLAVE Library (Download version)


Price: EUR 24.14

This product is provided as down-loadable without any storage media and is billed without shipping.

I2CSLAVE is an add-on product for BASCOM-AVR.

It allows you to turn an AVR micro into an I2C slave chip.

You could start your own factory for I2C chips: create your own PCF8574 , I2C LCD display etc.
The I2C Slave add on comes with different libraries for different AVR processors.

There is the plain soft mode library which uses the TIMER and INT interrupts and it is intended for the older AVR chips which do not have TWI or USI like  2313,2323, 2333,2343,4433 and tiny22.

Then there is a Library for AVR processors that have built in TWI hardware (TWI-I2C).
This should be used for processors like M8,M32, M64,M128, M644, etc.

And  most TINY processors come with an USI. There is a library that can be used with the USI as well. This is for processors like : tiny2313,  tiny4313,  tiny24,  tiny44,  tiny 84, tiny25,  tiny45 , tiny85,  tiny26,  tiny261,  tiny461, m169, m165 , m325,  m3250,  m645,  m6450,  m329,  m649, tiny87,  tiny167 and tiny43U

For the XMEGA there is a separate library. 

The library works similar for all libraries but there are subtle differences. Use the examples and the help to get started.

While a big range of the AVR processors is supported with a library, not all AVR’s can be turned into an I2C slave. 

The first choice should always be a processor with TWI hardware. This because the TWI implements I2C fully in hardware. This is similar to the TWIC/TWID/TWIE/TWIF in the Xmega.

The next choice should be USI, but this is less ideal. The USI can only do counting in hardware. All the I2C handling is performed with software. And the USI interrupts fires a lot, which will make the main application slower. 

And the last choice is the software implementation. This uses a timer and an interrupt and code. So this also means that the application should be simple.


Here is a small sample for the atTiny2313 with USI.
 


'-------------------------------------------------------------------------------
'                            (c) 2004-2014 MCS Electronics
'          This demo demonstrates the USI I2C slave
'          This is part of the I2C Slave library which is a commercial addon library
'          Not all AVR chips have an USI !!!!
'-------------------------------------------------------------------------------

$regfile = "attiny2313.dat"

$crystal = 8000000
$hwstack = 40
$swstack = 16
$framesize = 24

const cPrint = 0                                            'make 0 for chips that have NO UART, make 1 when the micro has a UART and you want to show data on the terminal

#if cPrint
 $baud = 19200                                            'only when the processor has a UART
#endif

config usi = twislave , address = &H40                      'bascom uses 8 bit i2c address (7 bit shifted to the left with one bit)

#if cPrint
 print "USI DEMO"
#endif

'do not forget to enable global interrupts since USI is used in interrupt mode
enable interrupts 'it is important you enable interrupts

do
 ! nop ; nothing to do here
loop



'The following labels are called from the library. You need to insert code in these subroutines
'Notice that the PRINT commands are remarked.
'You can unmark them and see what happens, but it will increase code size
'The idea is that you write your code in the called labels. And this code must execute in as little time
'as possible. So when you slave must read the A/D converter, you can best do it in the main program
'then the data is available when the master requires it, and you do not need to do the conversion which cost time.


'A master can send or receive bytes.
'A master protocol can also send some bytes, then receive some bytes
'The master and slave address must match.

'the following labels are called from the library  when master send stop or start
Twi_stop_rstart_received:
 '  Print "Master sent stop or repeated start"
Return

'master sent our slave address and will not send data
Twi_addressed_goread:
 ' Print "We were addressed and master will send data"
Return


Twi_addressed_gowrite:
 '  Print "We were addressed and master will read data"
Return

'this label is called when the master sends data and the slave has received the byte
'the variable TWI holds the received value
Twi_gotdata:
 '   Print "received : " ; Twi ; " byte no : " ; Twi_btw
 Select Case Twi_btw
 Case 1 : 'Portd = Twi                                   ' first byte
 Case 2: 'you can set another port here for example
 End Select
Return

'this label is called when the master receives data and needs a byte
'the variable twi_btr is a byte variable that holds the index of the needed byte
'so when sending multiple bytes from an array, twi_btr can be used for the index
Twi_master_needs_byte:
 '  Print "Master needs byte : " ; Twi_btr
 Select Case Twi_btr
 Case 1 : twi = 68                                       ' first byte
 Case 2 : twi = 69                                       ' send second byte
 End Select 'you could also return the state of a port pin or A/D converter
Return




For enable cart please login or register first

Customer Reviews:

jmpe  (Sunday, 05 August 2007)
Rating: 4
Now I can make real powerful I2C featured mic's, by splitting tasks with mathematical routines as slaves.
One of these slave mic will be a HIGH precision thermocouple (8 different types) linearisation with a resolution better than +/- .05 degree celcius.
Additional some RTD's (Pt100 ect), completely mic controlled. Target is the ATtiny85

You cannot write a review because you not have ordered this product yet.

You may also be interested in this/these product(s):

BASCOM-AVR - USB Add On
BASCOM-AVR - USB Add On
EUR 47.19
For enable cart please login or register first