CONFIG USI
Contents |
Action
Configures the hardware USI.
Syntax
CONFIG USI=mode , Address=adr
Remarks
The USI(universal serial Interface) is found in most atTiny processors. It can be used for various tasks. At the moment only the TWI slave mode is supported. The other modes you need to configure/code yourself.
The CONFIG USI = TWISLAVE mode requires a library that is part of the i2c slave add on which is a commercial add on.
Mode |
The supported mode is : TWISLAVE. This will set the USI in TWI slave mode. The USI works in interrupt mode on the background. |
Address |
This is the I2C/TWI slave address. Notice that bascom uses the 8-bit address notation. |
When USI is used in TWI/I2C mode, it does require that SCL and SDA have pull up resistors. You can not freely choose the SCL and SDA pins : you must use the fixed SCL en SDA pins.
The variables TWI_USI_OVS , TWI_slaveAddress, Twi , Twi_btr , TWI_bflag and Twi_btw are created by the compiler. These are all bytes
The USI interrupts are enabled but you need to enabled the global interrupt using ENABLE INTERRUPTS
The USI Slave code is running as an interrupt process. Each time there is an USI interrupt some slave code is executed. Your BASIC code is called from the low level slave code at a number of events.
You must include all these labels in your Slave application. You do not need to write code in all these sub routines.
Label |
Event |
Twi_stop_rstart_received |
The Master sent a stop(i2CSTOP) or repeated start. Typical you do not need to do anything here. |
Twi_addressed_goread |
The master has addressed the slave and will now continue to send data to the slave. You do not need to take action here. |
Twi_addressed_gowrite |
The master has addressed the slave and will now continue to receive data from the slave. You do not need to take action here. |
Twi_gotdata |
The master has sent data. The variable TWI holds the received value. The byte TWI_BTW is an index that holds the value of the number of received bytes. The first received byte will have an index value of 1. |
Twi_master_needs_byte |
The master reads from the slave and needs a value. The variable TWI_BTR can be inspected to see which index byte was needed. |
See also
Using USI , CONFIG TWISLAVE, CONFIG TWIXSLAVE