Grove- i2C motor driver

TubeFiebig

Mitglied
30. Jan. 2012
34
0
6
Delmenhorst
Sprachen
Hallo zusammen,
ich wollte den Arduino Sketch: DCControl.ino umschreiben für Bascom. Komme nicht weiter.
Der Basiccode wird zwar ohne Fehler übersetzt, aber die Motorplatine reagiert nicht.
Der Arduino Sketch läuft auf einem Uno-Board einwandfrei.

Code:
[/
/*
  Grove- i2C motor driver demo v1.0
  by: http://www.seeedstudio.com
//  Author:LG
//
//
//  This demo code is free software; you can redistribute it and/or
//  modify it under the terms of the GNU Lesser General Public
//  License as published by the Free Software Foundation; either
//  version 2.1 of the License, or (at your option) any later version.
//
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//
*/
#include <Wire.h>

#define MotorSpeedSet             0x82
#define PWMFrequenceSet           0x84
#define DirectionSet              0xaa
#define MotorSetA                 0xa1
#define MotorSetB                 0xa5
#define Nothing                   0x01
#define EnableStepper             0x1a
#define UnenableStepper           0x1b
#define Stepernu                  0x1c
#define I2CMotorDriverAdd         0x0f   // Set the address of the I2CMotorDriver
// set the steps you want, if 255, the stepper will rotate continuely;
void SteperStepset(unsigned char stepnu)
{
  Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
  Wire.write(Stepernu);          // Send the stepernu command
  Wire.write(stepnu);            // send the steps
  Wire.write(Nothing);           // send nothing
  Wire.endTransmission();        // stop transmitting
}
///////////////////////////////////////////////////////////////////////////////
// Enanble the i2c motor driver to drive a 4-wire stepper. the i2c motor driver will
//driver a 4-wire with 8 polarity  .
//Direction: stepper direction ; 1/0
//motor speed: defines the time interval the i2C motor driver change it output to drive the stepper
//the actul interval time is : motorspeed * 4ms. that is , when motor speed is 10, the interval time
//would be 40 ms
//////////////////////////////////////////////////////////////////////////////////
void StepperMotorEnable(unsigned char Direction, unsigned char motorspeed)
{
  Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
  Wire.write(EnableStepper);        // set pwm header
  Wire.write(Direction);              // send pwma
  Wire.write(motorspeed);              // send pwmb
  Wire.endTransmission();    // stop transmitting
}
//function to uneanble i2C motor drive to drive the stepper.
void StepperMotorUnenable()
{
  Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
  Wire.write(UnenableStepper);        // set unenable commmand
  Wire.write(Nothing);     
  Wire.write(Nothing);     
  Wire.endTransmission();    // stop transmitting
}
//////////////////////////////////////////////////////////////////////
//Function to set the 2 DC motor speed
//motorSpeedA : the DC motor A speed; should be 0~100;
//motorSpeedB: the DC motor B speed; should be 0~100;

void MotorSpeedSetAB(unsigned char MotorSpeedA , unsigned char MotorSpeedB)  {
  MotorSpeedA=map(MotorSpeedA,0,50,0,100);
  MotorSpeedB=map(MotorSpeedB,0,50,0,100);
  Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
  Wire.write(MotorSpeedSet);        // set pwm header
  Wire.write(MotorSpeedA);              // send pwma
  Wire.write(MotorSpeedB);              // send pwmb
  Wire.endTransmission();    // stop transmitting
}
//set the prescale frequency of PWM, 0x03 default;
void MotorPWMFrequenceSet(unsigned char Frequence)  {
  Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
  Wire.write(PWMFrequenceSet);        // set frequence header
  Wire.write(Frequence);              //  send frequence
  Wire.write(Nothing);              //  need to send this byte as the third byte(no meaning)
  Wire.endTransmission();    // stop transmitting
}
//set the direction of DC motor.
void MotorDirectionSet(unsigned char Direction)  {     //  Adjust the direction of the motors 0b0000 I4 I3 I2 I1
  Wire.beginTransmission(I2CMotorDriverAdd); // transmit to device I2CMotorDriverAdd
  Wire.write(DirectionSet);        // Direction control header
  Wire.write(Direction);              // send direction control information
  Wire.write(Nothing);              // need to send this byte as the third byte(no meaning)
  Wire.endTransmission();    // stop transmitting
}

void MotorDriectionAndSpeedSet(unsigned char Direction,unsigned char MotorSpeedA,unsigned char MotorSpeedB)  {  //you can adjust the driection and speed together
  MotorDirectionSet(Direction);
  MotorSpeedSetAB(MotorSpeedA,MotorSpeedB);
}
void setup()  {
  Wire.begin(); // join i2c bus (address optional for master)
  delayMicroseconds(10000);
  Serial.begin(9600);
  Serial.println("setup begin");
}

void loop()  {
  // the following code sent commands to motor driver to drive DC motor
  while(1)  {
    Serial.println("sent DC speed 0 , 0 ");
    Serial.println("sent Dir 0b00001010");
    MotorSpeedSetAB(0,0);//defines the speed of motor 1 and motor 2;
    MotorDirectionSet(0b00001010);
    delay(2000);

    Serial.println("sent Dir 0b0101");
    delay(2000);
    MotorDirectionSet(0b0101);
    delay(2000);

    Serial.println("sent Dir 0b0110");
    delay(2000);
    MotorDirectionSet(0b0110);
    delay(2000);

    Serial.println("sent DC speed 80 , 80");
    MotorSpeedSetAB(80,80);//defines the speed of motor 1 and motor 2;
    delay(10); //this delay needed
    MotorDirectionSet(0b00001010);  //"0b1010" defines the output polarity, "10" means the M+ is "positive" while the M- is "negtive"
                                  // make sure M+ and M- is different polatity when driving DC motors.
    delay(2000);
    Serial.println("sent DC speed 40 , 40");
    MotorSpeedSetAB(40,40);//defines the speed of motor 1 and motor 2;
    delay(100); //this delay needed
    MotorDirectionSet(0b0101);  //0b0101  Rotating in the opposite direction
    delay(2000);
    Serial.println("sent DC speed 100 , 40");
    MotorSpeedSetAB(40,40);//defines the speed of motor 1 and motor 2;
    delay(100); //this delay needed
    MotorDirectionSet(0b1001);  //0b0101  Rotating in the opposite direction
    delay(2000);

    Serial.println("sent Dir 0b00000000");
    delay(2000);
    MotorDirectionSet(0b0000);
    delay(2000);

    }
 
}

Ich vermute das hex Adressen der I2C Motorplatine nicht stimmen.
Ein Arduino I2C_Scanner gibt für I2cmotordriveradd x0F aus.
Ein Bascom I2C_Scanner gibt für I2cmotordriveradd H1E aus.




CodeBox BascomAVR
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
'
' Project Name : Grove I2c Motor Driver
'
' Files : Grove I2c Motor Driver.cbas
' Writer :
' Date   :
' 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
'
'$lib „i2c_twi.lbx“
'
'(
'Controller Pins für LCD Ansteuerung Konfigurieren
Config Lcdpin = Pin , Rs = Portb.2 , E = Portb.3 , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7
Config Lcd = 20 * 4                                         'Type des LCD´s 16 Char und 2 Zeilen
Config Portb.1 = Output                                     'LCD Beleuchtung  ein  /  Aus
Lcd_display Alias Pinb.1
Initlcd                                                     'LCD high level Initzialisierung
Cursor Off                                                  'Cursor ausschalten
Cls                                                                             'LCD löschen
')
'
'#################################################################
'#############    Grove I2c Motor Driver 1.3   ###########################
'#################################################################
'
Declare Sub Motorspeedsetab(byval Motorspeeda As Byte , Byval Motorspeedb As Byte)
Declare Sub Motorpwmfrequenceset(byval Frequence As Byte)
Declare Sub Motordirectionset(byval Directionset As Byte , Byval Direction As Integer)
Declare Sub Motordirection
'
Const Motorspeedset = &H82
Const Pwmfrequenceset = &H84
Const Directionset = &HAA
Const Motorseta = &HA1
Const Motorsetb = &HA5
Const Nothing = &H01
Const Enablestepper = &H1A
Const Unenablestepper = &H1B
Const Stepernu = &H1C
Const I2cmotordriveradd = &H1E                                                  ' 8bit I2C address  Grove I2c Motor Driver 1.3 (Atmega8)
'
Const Dirvor = &B00001010
Const Dirruck = &B00000101
Const Dirstop = &B00000000
'
Dim Somedata As String * 10
Dim Frequence As Byte
Dim Direction As Integer
'
Frequence = &H03
'
'------------------------------------------------------------------------------------------------------
'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
'
'
'============================================================
'
'    Motorspeed Setab
'    Function To Set The 2 Dc Motor Speed
'    Motor_A : The Dc Motor Links Speed ; Should Be 0~255;
'    Motor_B : The Dc Motor Rechts Speed ; Should Be 0~255
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
Sub Motorspeedsetab(byval Motorspeeda As Byte , Byval Motorspeedb As Byte)
'
'Motor rechts , Motor links

        I2cstart
        I2cwbyte I2cmotordriveradd
        I2cwbyte Motorspeedset
        I2cwbyte Motorspeeda
        I2cwbyte Motorspeedb
        I2cstop
'
Waitms 15
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
'
'============================================================
'    Motordirectionset
'    Set The Direction Of Dc Motor
'============================================================
'Sub Motordirection  '  Adjust the direction of the motors 0b0000 I4 I3 I2 I1
Sub Motordirection
'
    I2cstart
    I2cwbyte I2cmotordriveradd
    I2cwbyte Directionset
    I2cwbyte &B1010
    I2cwbyte Nothing
    I2cstop
'
End Sub
'
'===========================================================
'
'Sub Motordirectionset(byval Directionset As Byte , Byval Direction As Integer)  '  Adjust the direction of the motors 0b0000 I4 I3 I2 I1
Sub Motordirectionset(byval Directionset As Byte , Byval Direction As Integer)
'
    I2cstart
    I2cwbyte I2cmotordriveradd
    I2cwbyte Directionset
    I2cwbyte &B0001010
    I2cwbyte Direction
    I2cwbyte Nothing
    I2cstop
'
End Sub
'
'============================================================
'    Motordriectionandspeedset
'============================================================
'
'Sub Motordirectionandspeedset(byval Direction As Byte , Byval Motorspeed_l As Byte , Byval Motorspeed_r As Byte)
' you can adjust the driection and speed together
'    Motordirectionset(direction)
'    Motorspeedsetab(motorspeeda , Motorspeedb)
'End Sub
'
'#################################################################
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'    Main Program
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
Do
'
Call Motorspeedsetab(50 , 50)
Waitms 50
Call Motordirection
Wait 2
Loop
'
'#################################################################
End


Könnt Ihr mir da weiter helfen. Viele Grüße und Danke

Wolfgang
 
Zuletzt bearbeitet:
Hallo Lotadac,
Ich vermute das hex Adressen der I2C Motorplatine nicht stimmen.
Ein Arduino I2C_Scanner gibt für I2cmotordriveradd x0F aus.
Mit der X0F Adresse geht auch der Arduino Sketch.
Ein Bascom I2C_Scanner gibt für I2cmotordriveradd H1E aus.

Ich habe es mit verschiedenen I2cmotordriveradd Adressen probiert.
Das Motor-Board wird nicht angesprochen. Kann man gut sehen da auf der Platine LED's befinden.
Grüße,
Wolfgang
 
0x0F ist 0000 1111
0x1E ist 00011110

ich vermute sowas wie ein "Verständnis-Problem"...

so'ne I²C-Adresse besteht ja nur aus sieben Bit, und zwar den oberen sieben des Bytes - das LSB legt die Datenrichtung der folgenden Bytes fest (also ob der Master schreiben oder lesen will(!), entsprechend ob der/die Slave/s lesen oder schreiben sollen(!).

Wenn ich die sieben Bit 000 1111 in den oberen Bits darstelle (einmal linksschieben), erhalte ich 0001 111x.
(x=0)
Dein Arduino-Code scheint auf den 7bit-Adressen zu basieren, und später das "Datenrichtungsbit" dazuzuschieben/-rollen.
Der BASCOM-Code scheint auf den 8bit-Adressen zu basieren (mit 0 als LSB), und dann ggf 'ne (binäre) "1" für den Datenrichtungswwechsel draufzuaddieren (der Aufwand wäre gleich).
 
Ja, die Funktion Wire.beginTransmission (Arduino) erwartet eine 7Bit Adresse, gefolgt von Wire.write und Wire.endTransmission.

Bei Bascom ist es eine Schreib-Leseadresse. Bit0 ist dann die Datenrichtung, bit 7..1 ist die I2C-Adresse.

Insofern stimmt es ja eigentlich mit
0x0F bei Arduino (Adresse stimmt anscheinend da es bei Arduino funktioniert)
und
0x1E bei Bascom (ein bit nach links geschoben, Bit0=0 für Schreiben)

Der Fehler scheint woanders zu liegen.

EDIT:
Ich denke nicht, dass es daran liegt, aber vielleicht mal I2cdelay erhöhen.
 
Zuletzt bearbeitet:
Ähm..

hab mich lange nicht mehr mit BASCOM beschäftigt, aber Deine Programmstruktur:
  1. Direktiven
  2. Subroutinendeklaration
  3. Konstanten/Variablen
  4. Hardware-Init
  5. Subroutinen (Zeile 70..150)
  6. Hauptprogramm (Zeile 155..161)
Kann es sein, daß das wirklich exakt so compiliert wird, also der Controlle nach dem Hardware-Init einmal in die erste Subroutine läuft? Ich sehe keinen Sprung ins Hauptprogramm(*).
Am Ende einer jeden Subroutine steht ja ein RET(urn) (->End Sub), welches Effektiv 'ne Rücksprungadresse vom Stack nimmt und dahin hopst. Dort wurde aber gar keine abgelegt (->call subroutine), Der Sprung führt mMn letztendlich nach 0x0000.

(*)statt die Subroutinen zu Überspringen kann man auch einfach das Hauptprogramm vor jenen platzieren - im Hauptprogramm hast Du ja in Zeile 161 mit dem "loop" eh ein "Goto -> Do" (RJMP)...
 
Hallo zusammen,
danke für die Anworten. Das Basicprogramm ist erst mal nur ein Test wie ich die Motorplatine ansteuern muß.
Darum hat die Do .... Loop Schleife nur Call's zum Steuern des Motor. Ich verstehe in Bascom habe 8bit add.
Beim Arduino sind es 7bit add. Ich muß anderen adressen umrechen.
Also benötige ich ein Programm um von 7bit auf 8bit umzurechnen. dann werde ich mal auf die Suche gehen.
ein schönen Sonntag noch,
Wolfgang
 
Ich muß anderen adressen umrechen.

Nein, warte.
Dies betrifft nur die I2C Adresse, nicht irgendwelche Registeradressen im Controller-IC.

0x1E sollte also eigentlich als WriteAdresse bei Bascom stimmen.
 
Die Adressen sollten so passen - aber wie gesagt, mMn Stimmt Dein Bascom-Code nicht (läuft nicht wie beabsichtigt).
Beim Start läuft alles bis zum Hardware-Init, dann landest Du aber nicht im Hauptprogramm, sondern führst einmal "MotorSpeedSetTab()" aus, und zwar ohne call (es wird also keine Rücksprungadresse auf den Stack gepusht). Am Ende der "Subroutine" steht ein Return (End Sub), der Controller nimmt also das letzte Word vom Stack (läuft dabei über), interpretiert das als Rücksprungadresse, und springt dahin (wo auch immer das ist - vorhin war ich von 0xFFFF ausgegangen, was letztlich nach einem Überlauf des ProgrammCounters auf 0x0000 also den Resetvektor führt, aber der Stack läuft ja bereits beim POPpen der Adresse über - was Dir da jetzt als Adresse geliefert wird...)
 
jo,
Die do... loop schleife muß natürlich vor dem Sub's. Geht aber immer noch nicht. Müssen die adressen für Const Motorspeedset = &H82 und Const Directionset = &HAA nicht auch von 7 bit nach 8 bit umgerechnet werden . ich finde nicht wie ich es geht.

Grüße,
Wolfgang
 
Hmmmm....
1 stelle nach links shiften und dann bit 0 mit 0 oder 1 belegen
Addi
 
Müssen die adressen für Const Motorspeedset = &H82 und Const Directionset = &HAA nicht auch von 7 bit nach 8 bit umgerechnet werden . ich finde nicht wie ich es geht.

Nein, ich hatte ja zuvor schon geschrieben, dass es nur um die I2C Adresse geht.
 
Hallo Wolfgang!

Ich habe deinen Code mal kurz etwas geändert.
Sind allerdings nur kleine Änderungen.
Kannst du ihn mal ausprobieren?


Grüße,
Cassio



CodeBox BascomAVR
' * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
'
' Project Name : Grove I2c Motor Driver
'
' Files : Grove I2c Motor Driver.cbas
' Writer :
' Date   :
' 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
'
'$lib „i2c_twi.lbx“
'
'(
'Controller Pins für LCD Ansteuerung Konfigurieren
Config Lcdpin = Pin , Rs = Portb.2 , E = Portb.3 , Db4 = Portb.4 , Db5 = Portb.5 , Db6 = Portb.6 , Db7 = Portb.7
Config Lcd = 20 * 4                                         'Type des LCD´s 16 Char und 2 Zeilen
Config Portb.1 = Output                                     'LCD Beleuchtung  ein  /  Aus
Lcd_display Alias Pinb.1
Initlcd                                                     'LCD high level Initzialisierung
Cursor Off                                                  'Cursor ausschalten
Cls                                                                             'LCD löschen
')
'
'#################################################################
'#############    Grove I2c Motor Driver 1.3   ###########################
'#################################################################
'
Declare Sub Motorspeedsetab(byval Motorspeeda As Byte , Byval Motorspeedb As Byte)
Declare Sub Motorpwmfrequenceset(byval Frequence As Byte)
Declare Sub Motordirectionset(byval Directionset As Byte , Byval Direction As Integer)
Declare Sub Motordirection
'
Const Motorspeedset = &H82
Const Pwmfrequenceset = &H84
Const Directionset = &HAA
Const Motorseta = &HA1
Const Motorsetb = &HA5
Const Nothing = &H01
Const Enablestepper = &H1A
Const Unenablestepper = &H1B
Const Stepernu = &H1C
Const I2cmotordriveradd = &H1E                                                  ' 8bit I2C address  Grove I2c Motor Driver 1.3 (Atmega8)
'
Const Dirvor = &B00001010
Const Dirruck = &B00000101
Const Dirstop = &B00000000
'
Dim Somedata As String * 10

' CASSIO 28.11.2016**********************************************
'Dim Frequenz As Byte

Dim Direction As Integer

'
' CASSIO 28.11.2016**********************************************
Motorpwmfrequenceset &H03

'
'------------------------------------------------------------------------------------------------------
'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


'#################################################################
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'    Main Program
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
' CASSIO 28.11.2016**********************************************
Do
'
Call Motorspeedsetab(50 , 50)
Waitms 50
Call Motordirection
Wait 2
Loop
'
'#################################################################
End


'
'
'============================================================
'
'    Motorspeed Setab
'    Function To Set The 2 Dc Motor Speed
'    Motor_A : The Dc Motor Links Speed ; Should Be 0~255;
'    Motor_B : The Dc Motor Rechts Speed ; Should Be 0~255
' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
'
Sub Motorspeedsetab(byval Motorspeeda As Byte , Byval Motorspeedb As Byte)
'
'Motor rechts , Motor links

        I2cstart
        I2cwbyte I2cmotordriveradd
        I2cwbyte Motorspeedset
        I2cwbyte Motorspeeda
        I2cwbyte Motorspeedb
        I2cstop
'
Waitms 15
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
'
'============================================================
'    Motordirectionset
'    Set The Direction Of Dc Motor
'============================================================
'Sub Motordirection  '  Adjust the direction of the motors 0b0000 I4 I3 I2 I1
Sub Motordirection
'
    I2cstart
    I2cwbyte I2cmotordriveradd
    I2cwbyte Directionset
    I2cwbyte &B1010
    I2cwbyte Nothing
    I2cstop
'
End Sub
'
'===========================================================
'
'Sub Motordirectionset(byval Directionset As Byte , Byval Direction As Integer)  '  Adjust the direction of the motors 0b0000 I4 I3 I2 I1
Sub Motordirectionset(byval Directionset As Byte , Byval Direction As Integer)
'
    I2cstart
    I2cwbyte I2cmotordriveradd
    I2cwbyte Directionset
    I2cwbyte &B0001010
    I2cwbyte Direction
    I2cwbyte Nothing
    I2cstop
'
End Sub
'
'============================================================
'    Motordriectionandspeedset
'============================================================
'
'Sub Motordirectionandspeedset(byval Direction As Byte , Byval Motorspeed_l As Byte , Byval Motorspeed_r As Byte)
' you can adjust the driection and speed together
'    Motordirectionset(direction)
'    Motorspeedsetab(motorspeeda , Motorspeedb)
'End Sub
'

 
Hallo Cassio,
Danke das du den Demo Code dir angesehen und geändert hast. Ich habe die Ursache gefunden. Ein Hardware Problem. Die SDA und SDL Datenleitungen sind weder am Arduino Board noch an der Motorplatine mit 4,7Kohm Widerständen am +5Volt gelegt.
Beim Arduino Sketch ist es wohl nicht notwendig. Bei Bascom muß es gemacht werden. Also Lötkolben angeworfen und die Widerstände eingelötet.
Jetzt läuft es und ich kann endlich das Programm weiter ausbauen.
Viele Dank allen und schöne Grüße,
Wolfgang
 
Hallo Wolfgang!

Freut mich zu hören, dass du den Fehler doch noch gefunden hast.

Die Pullups für den TWI-Bus müssen selbstverständlich vorhanden sein, sonst wird das natürlich auch nichts. ;)

Da du aber die Schreibadressen (&H0F und &H1E) am Bus ermitteln konntest war ich davon ausgegangen, dass du die Datenübermittlung direkt am TWI-Bus schon geprüft hast. Dies wäre ohne Pullups natürlich nicht möglich gewesen.

Nur ein Hinweis noch......
Du solltest bei den Übergabevariablen in den Subs und den global deklarierten Variablen nicht den selben Namen verwenden.
BASCOM lässt dies zwar zu, aber ich habe damit schon mal ein paar Probleme gehabt.

Aus dem Grunde hatte ich dies entfernt:
Dim Frequence As Byte

weil der selbe Name schon in der Sub stand:
Declare Sub Motorpwmfrequenceset(byval Frequence As Byte)

Die andere Sache, mit der Do-Loop Schleife zu Beginn und die Subs am Ende des Programms wurden ja schon erwähnt. ;)


Dann wünsche ich dir weiterhin viel Spaß.

Grüße,
Cassio
 
Da du aber die Schreibadressen (&H0F und &H1E) am Bus ermitteln konntest war ich davon ausgegangen, dass du die Datenübermittlung direkt am TWI-Bus schon geprüft hast. Dies wäre ohne Pullups natürlich nicht möglich gewesen.
Jain. Habe ich auch schon gehabt. Pull Up's vergessen, I2C Scan durchlaufen lassen und Slave wurde gefunden. Allerdings auf mehreren Adressen gleichzeitig und die Daten wurden auch alles Andere als korrekt empfangen. Ist ja auch klar. Fies ist nur dass unter Umständen trotzdem etwas empfangen wird.
 
Hi Tommy!

Ich war einfach davon ausgegangen, dass er die Kommunikation mit einem Logic Analyzer geprüft hat.
So wäre ich zumindest vorgegangen..... :rolleyes:
Scheinbar sollte man nicht immer von sich auf Andere schließen. ;)

Grüße,
Cassio
 
Hallo Cassio,
Ich habe keinen Logic Analyzer zur Verfügung. Und da ja der Arduino Sketch funktioniert bin ich auch nicht sofort auf die verdammten Widerstände gekommen. Hätte ich meine AVR Test Boards genommen wäre das nicht passiert.
Nana man ist nicht mehr der jüngste.
schönen tag zusammen.
Wolfgang
 
Hmm...

prinzipiell sollten sich auch die internen Pullups nutzen lassen (die sind allerdings mit 20..50kOhm etwas schwach -> also bei hohen Busfrequenzen und langen Strippen weniger geeignet).

Normalerweise toggelt TWI/I²C ja zwischen Gnd und Tristate. Ziel wäre dann toggeln zwischen Gnd und Pullup.
Verwendet man Hardware-TWI, wird durch das TWEN (TWI Enable) das Pullup Override Signal aktiviert, als Pullup Override Value gilt das entsprechende Bit des Port Latch Registers (also ohne Berücksichtigung des Datenrichtungsregisters), sofern die Pullups nicht eh global disabled sind (PUD).
Verwendet man also Hardware-TWI, legt man (nur) mit den beiden PORT-Bits fest, ob die internen Pullups aktiviert sein sollen.

Bei Software-TWI benutzt die verwendete Bibliothek die Beine letztlich als konventionelle I/Os, da müßten dann also entsprechend PORT-Latch- und Datenrichtungsregister manipuliert werden. Inwiefern die verwendeten Bibliotheken das unterstützen, weiß ich nicht - es findet sich in der Online-Hilfe lediglich ein Hinweis, daß man die Pullups beim Hardware-TWI aufschalten kann (eben über die PORT-Bits, klar und nach dem i2cinit).
 
Ich glaube dass zumindest bei einigen Chips sobald das TWI/I2C aktiviert wird die PullUp's immer deaktiviert werden.
Bin mir da aber nicht sicher.

Mein Problem hatte ich auf einem Raspberry Pi.
 

Über uns

  • Makerconnect ist ein Forum, welches wir ausschließlich für einen Gedankenaustausch und als Diskussionsplattform für Interessierte bereitstellen, welche sich privat, durch das Studium oder beruflich mit Mikrocontroller- und Kleinstrechnersystemen beschäftigen wollen oder müssen ;-)
  • Dirk
  • Du bist noch kein Mitglied in unserer freundlichen Community? Werde Teil von uns und registriere dich in unserem Forum.
  •  Registriere dich

User Menu

 Kaffeezeit

  • Wir arbeiten hart daran sicherzustellen, dass unser Forum permanent online und schnell erreichbar ist, unsere Forensoftware auf dem aktuellsten Stand ist und der Server regelmäßig gewartet wird. Auch die Themen Datensicherheit und Datenschutz sind uns wichtig und hier sind wir auch ständig aktiv. Alles in allem, sorgen wir uns darum, dass alles Drumherum stimmt :-)

    Dir gefällt das Forum und unsere Arbeit und du möchtest uns unterstützen? Unterstütze uns durch deine Premium-Mitgliedschaft!
    Wir freuen uns auch über eine Spende für unsere Kaffeekasse :-)
    Vielen Dank! :ciao:


     Spende uns! (Paypal)