Forum: Mikrocontroller und Digitale Elektronik Stellaris I2C


von Matthias (Gast)


Lesenswert?

Hallo.

Ich verwende im Moment das Stellaris Launchpad mit dem LM4F120H5QR. 
Gehört zur CLASS_IS_BLIZZARD. Weiters verwende ich die dazugehörige 
driverlib. Einige Sachen funktionierten gleich auf Anhieb mit den APIs 
aber dann wollte ich I2C verwenden und 30h später ist noch nicht einmal 
der DrecksSCL-Pin richtige eingestellt...

Deshalb wollte ich fragen ob jemand damit Erfahrung hat oder ähnliche 
Probleme mit I2C hatte.

Was mir zB auffiel war, dass in der Definition vom I2CSCL-pin nicht 
opendrain mit pull-up verwendet wird sondern standard push-pull. Ich 
habe das geändert aber der Pin bleibt dauerend LOW. Beim anderen (SDA) 
passt die Einstellung schon immer. Ich müsste mir jetzt anscheinend 
alles von der SysControl bis GpioConfigs und I2C nochmal durchschauen ob 
da noch wo was nicht passt, weil ich hab echt keinen Plan mehr...

Zum Einstellen des I2C verwende ich folgendes:
1
      GPIOPinConfigure(0x00010803);// GPIO_PB2_I2C0SCL
2
      GPIOPinConfigure(0x00010C03);// GPIO_PB3_I2C0SDA
3
      GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
4
      myGPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
5
      Uart_Send(UART0_BASE,"I2C GPIO DONE\n\r\0",0);
6
      I2CMasterInitExpClk(I2C0_MASTER_BASE,SysCtlClockGet(),false);
7
      I2CMasterEnable(I2C0_MASTER_BASE);

Die Funktion myGPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2); ist im 
Grunde wie GPIOPinTypeI2CSCL, nur dass statt
1
void
2
GPIOPinTypeI2CSCL(unsigned long ulPort, unsigned char ucPins)
3
{
4
    //
5
    // Check the arguments.
6
    //
7
    ASSERT(GPIOBaseValid(ulPort));
8
9
    //
10
    // Make the pin(s) be peripheral controlled.
11
    //
12
    GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
13
14
    //
15
    // Set the pad(s) for open-drain operation with a weak pull-up.
16
    //
17
    if(CLASS_IS_SANDSTORM || CLASS_IS_FURY || CLASS_IS_DUSTDEVIL ||
18
       CLASS_IS_TEMPEST || CLASS_IS_FIRESTORM)
19
    {
20
        GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);  //open drain
21
    }
22
    else  // jo, den hab ich ... BLIZZARD
23
    {
24
        GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD);  // pushpull
25
    }
26
}

das  so geändert wurde wie normalerweise I2C geht :
1
void
2
myGPIOPinTypeI2CSCL(unsigned long ulPort, unsigned char ucPins)
3
{
4
    //
5
    // Check the arguments. GPIO_PIN_TYPE_OD_WPU
6
    //
7
    ASSERT(GPIOBaseValid(ulPort));
8
9
    //
10
    // Make the pin(s) be peripheral controlled.
11
    //
12
    GPIODirModeSet(ulPort, ucPins, GPIO_DIR_MODE_HW);
13
14
    //
15
    // Set the pad(s) for open-drain operation with a weak pull-up.
16
    //
17
    GPIOPadConfigSet(ulPort, ucPins, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD_WPU); // open drain weak internal pull up
18
19
}

Über jede Hilfe/ Aufmunterung glücklich!

Matthias

von StinkyWinky (Gast)


Lesenswert?

Wir initialisieren so:
1
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); /* enable the GPIOA module */
2
  SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C1);  /* enable the I2C module */
3
  /* Set Pins PA6 and PA7 to I2C function */
4
  GPIOPinTypeI2C(GPIO_PORTA_BASE, GPIO_PIN_6 | GPIO_PIN_7);
5
  I2CMasterInitExpClk(I2C1_MASTER_BASE, SYSCTL_CLOCK, true); /* true = fast = ~400kHz (ca. 320kHz) */

von Matthias (Gast)


Lesenswert?

Also die SysCtlEnables verwende ich eh auch weiter oben.

Und ohne GPIOPinConfigure? laut API sagens dort:

"To fully configure a pin, a GPIOPinTypexy() function should also be 
called."

Hab es auch ohne denen getestet, aber das Ergenis is das selbe: SCL ist 
immer LOW. Aber Danke fürn Tip!

Ich hab grad beim Durchstöbern des Controller-Datenblattes folgendes 
gelesen:
"I2C module 0 clock. Note that this signal has an
active pull-up. The corresponding port pin should
not be configured as open drain."

Das ist bei allen I2Cx-modulen so (S.956)
Was ist da bitte los, dass man Pushpull mit active Pullup hat?

von StinkyWinky (Gast)


Lesenswert?

Sorry, hab gerade gesehen, dass du eine andere Prozessorfamilie hast. 
Wir verwenden den LM3S1968.

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.