JavaScript ist deaktiviert. Für eine bessere Darstellung aktiviere bitte JavaScript in deinem Browser, bevor du fortfährst.
Du verwendest einen veralteten Browser. Es ist möglich, dass diese oder andere Websites nicht korrekt angezeigt werden.
Du solltest ein Upgrade durchführen oder einen
alternativen Browser verwenden.
Siehe
Datenblatt Seite 109:
Code:
Signal
Name PC5/SCL/ADC5/PCINT13 PC4/SDA/ADC4/PCINT12
PUOE TWEN TWEN
PUOV PORTC5 • /PUD PORTC4 • /PUD
TWEN setzt für beide Beine das Pullup Override Enable, als Pullup Override Value gilt dann je (Portbit AND NOT(PUD))
bei einigen Chips sobald das TWI/I2C aktiviert wird die PullUp's immer deaktiviert
Bei den meisten AVR werden die Pullups (sofern nicht global disabled) durch ein Zusammenspiel von PORT-Register und DD-Register beeinflußt. TWEN koppelt quasi den Einfluß des DDR aus.
Zumindest bei einigen Tinies gibt es ja eine andere Pullup-Ansteuerung. Beim Tiny441/841 zB. gibt es für jeden Pullup ein Bit in einem seperaten Pullup Enable Register (PUEN). TWEN beeinflußt hier nicht das entsprechende Pullup Override Enable Signal (PUOE), irgendein Pullup Override Value (PUOV) tritt also nicht in Kraft.
(Das TWI des 441/841 kennt allerdings nur den Slave-Mode (mir ist bisher kein Tiny mit Master-TWI bekannt - Das USI einiger Tinies sollte sich quasi als Master-TWI verwenden lassen, wenn man sich selbst um die Clock kümmert (bzw einen Timer nutzt), und auf Multi-Master-Arbitrierung verzichten kann... aber ich komme vom Thema ab...))
Zuletzt bearbeitet: 29. Nov. 2016
Hallo zusammen,
Das Testprogramm für die I2C Crove Motorplatine habe ich überarbeitet. Es ist das Grundgerüst für den RP6 Raupenantrieb.
CodeBox BascomAVR
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
'
' Project Name : Grove I2c Motor Driver
'
' Files : Grove I2c Motor Driver.cbas
' Writer : TubeFiebig
' Date : 02.12.2016
' Function : Demonstrates The Grove I2c Motor Driver 1.3
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
$regfile = "m328pdef.dat"
$crystal = 16000000
$hwstack = 132 ' default use 32 for the hardware stack
$swstack = 132 'default use 10 for the SW stack
$framesize = 164 'default use 40 for the frame space
'
'
'#################################################################
'############# Grove I2c Motor Driver 1.3 ###########################
'#################################################################
'
'Declare Sub Command_motors(byval Direction As Byte , Motorleft As Byte , Byval Motorright As Byte)
Declare Sub Command_motors(byval Motorleft As Byte , Byval Motorright As Byte)
Declare Sub Motorpwmfrequenceset(byval Frequence As Byte)
Declare Sub Motordirectionset
'
Const Motorspeedset = &H82
Const Directionset = &HAA
Const Pwmfrequenceset = &H84
Const Motorseta = &HA1
Const Motorsetb = &HA5
Const Nothing = &H01
Const I2cmotordriveradd = &H1E ' 7bit I2C address Grove I2c Motor Driver 1.3 (Atmega8)
'
Const Dirvor = &B00001010
Const Dirzurueck = &B00000101
Const Dirstop = &B00001111
Const Dirvor_zurueck = &B00001001
Const Dirzurueck_vor = &B00000110
'
Dim Drive_l As Byte
Dim Drive_r As Byte
Dim Speed As Byte
Dim Direction As Byte
Dim Frequence As Byte
'
' Grundeinstellung Grove Motor Platine
Frequence = &H05
Call Motorpwmfrequenceset(frequence)
Direction = Dirstop
Call Motordirectionset
'
'
'#################################################################
'TWI konfigurieren
'I²C - Bus Pinbelegung (Hardware I²C - Bus)
Config Sda = Portc.4 'SDA und SCL als Hardware-TWI definieren
Config Scl = Portc.5
Config I2cdelay = 5
I2cinit
'
'#################################################################
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
' Haupt Programm
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'Test I2C Grove Motorplatine
Wait 5
Do
'
Direction = Dirvor
Drive_l = 200 : Drive_r = 200
Call Command_motors(drive_l , Drive_r)
Wait 3
'
Direction = Dirstop
Drive_l = 0 : Drive_r = 0
Call Command_motors(drive_l , Drive_r)
Wait 3
'
Direction = Dirzurueck
Drive_l = 45 : Drive_r = 45
Call Command_motors(drive_l , Drive_r)
Wait 3
'
Direction = Dirstop
Call Motordirectionset
Wait 3
'
Direction = Dirvor_zurueck
Drive_l = 100 : Drive_r = 100
Call Command_motors(drive_l , Drive_r)
Wait 3
'
Direction = Dirzurueck_vor
Drive_l = 100 : Drive_r = 100
Call Command_motors(drive_l , Drive_r)
Wait 3
Loop
'
'============================================================
'------------------ Sub-Rotinen I2C Crove Motors Platine ------------------------------
'============================================================
'
' Function To Set The 2 DC Motor Speed
' Dc Motor Links Speed ; Should Be 0~255;
' Dc Motor Rechts Speed ; Should Be 0~255
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
Sub Command_motors(byval Motorleft As Byte , Byval Motorright As Byte)
'
I2cstart
I2cwbyte I2cmotordriveradd
I2cwbyte Motorspeedset
I2cwbyte Motorleft
I2cwbyte Motorright
I2cstop
Waitms 20
' Richtung übergeben
' Adjust the direction of the motors 0b0000 I4 I3 I2 I1
I2cstart
I2cwbyte I2cmotordriveradd
I2cwbyte Directionset
I2cwbyte Direction
I2cwbyte Nothing
I2cstop
Waitms 20
'
End Sub
'
'============================================================
' Motordirectionset
' Set The Direction Of Dc Motor
'============================================================
'Sub Motordirection ' Adjust the direction of the motors 0b0000 I4 I3 I2 I1
'
Sub Motordirectionset
'
I2cstart
I2cwbyte I2cmotordriveradd
I2cwbyte Directionset
I2cwbyte Direction
I2cwbyte Nothing
I2cstop
'
End Sub
'
'===========================================================
'
' Motorpwmfrequenceset
' Set The Prescale Frequency Of Pwm , 0x03 Default
'===========================================================
'
Sub Motorpwmfrequenceset(byval Frequence As Byte)
'
I2cstart
I2cwbyte I2cmotordriveradd
I2cwbyte Pwmfrequenceset
I2cwbyte Frequence
I2cwbyte Nothing
I2cstop
'
End Sub
'#################################################################
End
Grüße,
Wolfgang