I2C antwort=0, dabei master nicht besetzt.

OP #2435155
Lesenswert?

Hallo leute,

vielleicht könnt Ihr mir einen Tip geben.
Ich versuch die Kommunikation zwischen einem LM3S1968 und einem SHT21 
herzustellen.
Mein Vorgehen:
1. Slave mit der Adresse 1000000+0(für schreiben) ansprechen, abwarten, 
bis master nicht besetzt ist.
2. Slave Register 11100011 ansprechen und wieder abwarten, bis master 
nicht besetzt ist.
3. Slave mit der Adresse 1000000+0(für lesen) ansprechen, abwarten, bis 
master frei ist.
4. daten auslesen.

Es kommt immer eine 0 raus. Könnten falscher Pullup dafür verantwortlich 
sein? Ich nutze 10k

Danke,
Grüsse - Michael
OP #2435212
Lesenswert?

ja, also wie in dem Datenblatt, hier mein Code:
1
unsigned long result;
2
#define SLAVE_ADDR 0x40
3
//...Sysclock usw. einstellen
4

5
    I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), false);   
6
    I2CMasterEnable(I2C0_MASTER_BASE );
7
    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDR,false);
8
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
9
    while(I2CMasterBusy(I2C0_MASTER_BASE) != 0);
10

11
    I2CMasterDataPut(I2C0_MASTER_BASE,0xE5); 
12
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
13
    while(I2CMasterBusy(I2C0_MASTER_BASE) != 0);
14

15
    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDR,true);
16
    I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND);
17
    while(I2CMasterBusy(I2C0_MASTER_BASE) != 0);
18
  
19
    I2CMasterControl( I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE );
20
    while(I2CMasterBusy(I2C0_MASTER_BASE) != 0);
21
    result = I2CMasterDataGet(I2C0_MASTER_BASE);
22

23
    UARTprintf("Done %x\n",result);
24
    while(1){
25

26
    I2CMasterControl( I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE );
27
    while(I2CMasterBusy(I2C0_MASTER_BASE) != 0);
28
    result = I2CMasterDataGet(I2C0_MASTER_BASE);
29
}
30
    return(0);

und bei mir bleibt result immer auf 0
Gast #2436841
Lesenswert?

koennte bitte jemand einen blick auf den code werfen und sagen obs 
falsch ist? - und wenns ist, wo.

danke im Voraus
1
unsigned long ulDataRx[3], res; 
2
    unsigned long ulindex;  
3

4
       SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
5
                   SYSCTL_XTAL_16MHZ); 
6
  SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
7
  SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0);
8
  SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
9

10
     
11
    RIT128x96x4Init(1000000); 
12
    
13
  GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);
14
  GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD);
15
  GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_DIR_MODE_HW);
16
  GPIODirModeSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_DIR_MODE_HW);  
17
  
18
  I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), 0);
19
  I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS, false); 
20
  I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND); 
21
  while(I2CMasterBusy(I2C0_MASTER_BASE)){}
22
  
23
  
24
     I2CMasterDataPut(I2C0_MASTER_BASE, 0xE3);
25
  I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_SEND); 
26
  while(I2CMasterBusy(I2C0_MASTER_BASE)){}   
27
          
28
    for(ulindex = 0; ulindex < 3; ulindex++)    {
29
        ulDataRx[ulindex] = 0;
30
    }
31
    I2CMasterSlaveAddrSet(I2C0_MASTER_BASE, SLAVE_ADDRESS , true);
32
    for(ulindex = 0; ulindex < NUM_I2C_DATA; ulindex++)    {
33
    res=0;
34
        I2CMasterControl(I2C0_MASTER_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
35
        while(I2CMasterBusy(I2C0_MASTER_BASE))        {
36
        }
37
 
38
        res = I2CMasterDataGet(I2C0_MASTER_BASE);
39
        ulDataRx[ulindex] = res; 
40
    }

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren