View previous topic :: View next topic |
Author |
Message |
Andrei
Joined: 30 Apr 2004 Posts: 24 Location: Ekaterinsburg,Russia
|
Posted: Mon Feb 10, 2020 4:30 pm Post subject: ATtiny85 doesn't work in USI-TWI slave mode |
|
|
Hallo to all!
Sometimes I need to connect sensors and MC. I use 2082 BascomAVR version and I decided to use newest I2C\TWI library as well(of course, I have got them by legal way). I2C slave, TWI slave works very good, if I use a right library in a head of program with a lot of chips. I used one I2C soft master in all experiments - all resuts were good.But I can't get the same result, using USI slave library with ATtiny 85.I begun to work with tiny 85 like I2C slave - reply was 255 only! I repeated the example from I2CSLAVE DATASHEET. I saw ID0 = 255, ID1 = 255, ID2 =255 on master's LCD only (oscilloscope's screen shows 8 ones on SDA, of course).Can I use I2C slave soft master & USI-TWI slave?Why doesn't work tiny85 like USI-TWI slave, who knows? I changed ATtiny85, of course, but the result was the same.I tried to use SELECT CASE and without SELECT CASE - both resuts were negative.
$regfile = "attiny85.dat"
$crystal = 8000000
$hwstack = 32
$swstack = 32
$framesize = 40
$lib "I2C_USI_SLAVE.lib"
Config USI = TWIslave, address = &H40
Config Timer0 = Timer, Prescale = 256
Start Timer0
Enable Interrupts
Enable Timer0
On Timer0 Label_1
Dim D As Byte
Dim V As Byte
Dim V1 As Byte
Dim X As Byte
Dim ID As Byte 'BYTE'S IDENTIFICATOR
Dim Tay0 As Byte
'------------------------------------------------------
Begin:
If ID = 0 Then 'ID BYTE: SLAVE GETS IT FROM MASTER
X = D
End if
If ID = 1 Then
X = V
End if
If ID = 2 Then
X = V1
End if
Goto Begin
'-------------------------------
Label_1:
Incr Tay0
If Tay0 => 122 Then 'TIME 1 SEC
Incr D
V = D + 1
V1= D + 2
Tay0 = 0
End if
Return
'----------------------------------------------------------------------
TWI_GOTDATA:
Select Case Twi_btw:
Case 1: ID = Twi 'MASTER SENDS ID - 0,1,2 TO SLAVE
End select
Return
TWI_STOP_RSTART_RECEIVED:
Return
TWI_ADDRESSED_GOWRITE:
Return
TWI_ADDRESSED_GOREAD:
Return
TWI_MASTER_NEEDS_BYTE:
Select Case Twi_btr:
Case 1: Twi = X 'must be 0...255 MASTER GETS D,V,V1 AND PUT THEM ON DISPLAY
End select
Return
(BASCOM-AVR version : 2.0.8.2 )
Last edited by Andrei on Wed Feb 12, 2020 1:19 pm; edited 8 times in total |
|
Back to top |
|
|
Andrei
Joined: 30 Apr 2004 Posts: 24 Location: Ekaterinsburg,Russia
|
Posted: Tue Feb 11, 2020 9:23 pm Post subject: |
|
|
Hello!I see there reply 255 only!Who has good results, using attiny avr 25,45,85 with I2C_ USI_TWI-slave library(bascom 2082 & the last I2C slave library)? Is it library alive or dead?ATmega8,48,168,328 chips work very good like slaves in I2Csoftslave&twi-slave modes, but they have big sizez and a lot of pins, tiny has small sizez and 8 pins only, that is more better.
This is soft master's I2C program, if it's need:
$regfile = "m32def.dat" ' specify the used micro
$crystal = 16000000 ' used crystal frequency
$baud = 19200 ' use baud rate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
$lib "I2c.lib"
Config Sda = Porta.3
Config Scl = Porta.2
Config I2cdelay = 10
I2cinit
Const Addressw = &H40
Const Addressr = &H41
Dim C As Byte
Dim V As Byte
Dim V1 As Byte
Dim D As Byte
Dim X As Byte
Config Watchdog = 2048
Start Watchdog
Config Timer0 = Timer , Prescale = 256
Start Timer0
Enable Interrupts
Enable Timer0
On Timer0 Label_1
Dim Tay0 As Byte
Dim Tay1 As Byte
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7 , E = Portb.2 , Rs = Portb.3
Config LCD = 20 * 4
Cursor Off Noblink
Reset Watchdog
'----------------------------------------------------------------------------------------
Begin:
Reset Watchdog
I2cstart
I2cwbyte Addressw
I2cwbyte C 'BYTE'S ID
I2cstop
Reset Watchdog
waitms 1 'SLAVE WORKS WITH VARIABLES
I2cstart
I2cwbyte Addressr
I2crbyte X,Nack
I2cstop
Reset Watchdog
If C = 0 Then
D = X
End if
If C = 1 Then
V = X
End if
If C = 2 Then
V1 = X
End if
Locate 1,1
Lcd "VAR =";D;" ";V;" ";V1;" " 'I SEE 255, 255, 255 ONLY - IT ISN'T REPLY FROM TINY85
Locate 2 , 1
Lcd "C =";C;" " ' CIRCLE - 0,1,2
Goto Begin
'-------------------------------------------------------------------------------
Label_1:
Incr Tay0 '4,096 MSEC
If Tay0 => 244 Then
Incr C
If C = > 3 Then
C =0
End if
Tay0 = 0
End if
Return |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|