Forum: Mikrocontroller und Digitale Elektronik Atmel -> ATmega32 -> Software I2C


von Jan H. (janiiix3)


Lesenswert?

Nabend,

ich habe gerade das Problem, dass sich mein "SCL" Pin nicht bewegt ( 
toggelt ).

Was mache ich falsch?

Meine main()
1
tI2c SoftI2c;
2
3
int main(void):
4
{
5
  SoftI2c.Port = &PORTC;
6
  SoftI2c.Scl = 1<<PC0;
7
  SoftI2c.Sda = 1<<PC1;
8
  I2cSoftInit( &SoftI2c );
9
  
10
  uint8_t Commando[] = { 13 , 0x83 }; // Frequenz Modus + 1Hz
11
  
12
    while (1) 
13
    {
14
     *SoftI2c.Port |=  (1<<SoftI2c.Scl);
15
    *SoftI2c.Port |=  (1<<SoftI2c.Sda);
16
     
17
     *SoftI2c.Port &= ~(1<<SoftI2c.Scl);
18
    *SoftI2c.Port &= ~(1<<SoftI2c.Sda);
19
    }
20
}

Makros:
1
#ifdef __AVR__
2
#define  __PORT_DDR__( _p )    (*( (_p-1) ))  
3
#define __PORT_PIN__( _p )    (*( (_p-2) ))
4
#else
5
#error Library not Supported for our Device
6
#endif 
7
8
#define Q_DEL _delay_loop_2(3)
9
#define H_DEL _delay_loop_2(5)
10
11
typedef uint8_t PortBit_t;
12
typedef uint8_t Port_t;
13
14
typedef struct
15
{
16
  /*
17
  *  Port für das I²C Modul.
18
  *  Es wird die Adresse von dem Daten Richtungs Register
19
  *  später rechnerisch ermittelt.
20
  */
21
  volatile Port_t *Port;
22
  
23
  /*
24
  *  SCL Pin 
25
  */
26
  PortBit_t Scl;
27
  
28
  /*
29
  *  SDA Pin
30
  */
31
  PortBit_t Sda;
32
  
33
}tI2c;

Und die Init (I2cSoftInit()):
1
void I2cSoftInit( tI2c *Object ) 
2
{
3
  __PORT_DDR__( Object->Port ) |= ( 1 << Object->Scl ); // Scl als Ausgang konfigurieren
4
  __PORT_DDR__( Object->Port ) |= ( 1 << Object->Sda ); // Sda als Ausgang konfigurieren
5
  
6
  *Object->Port |= ( 1 << Object->Scl ); // Default Pegel einstellen
7
  *Object->Port |= ( 1 << Object->Sda ); // ..  
8
}

Irgendwo mache ich etwas gravierendes falsch..

von Stefan F. (Gast)


Lesenswert?

Du shiftest doppelt gemoppelt:
1
SoftI2c.Sda = 1<<PC1;                   // = 2
2
*SoftI2c.Port &= ~(1<<SoftI2c.Sda);     // = 4
3
*Object->Port |= ( 1 << Object->Sda );  // = 4

von Jan H. (janiiix3)


Lesenswert?

Stefanus F. schrieb:
> Du shiftest doppelt gemoppelt:
>
1
> SoftI2c.Sda = 1<<PC1;                   // = 2
2
> *SoftI2c.Port &= ~(1<<SoftI2c.Sda);     // = 4
3
> *Object->Port |= ( 1 << Object->Sda );  // = 4
4
>

Oh man.. Man sollte früher Feierabend machen.
Ich danke Dir vielmals!

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.