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
Michael Gromov schrieb: > Könnten falscher Pullup dafür verantwortlich > sein? Ich nutze 10k Bei mir läuft die Kommunikation mit 10k problemlos.
Schnapp dir mal nen Oszi oder nen LA und schau dir mal die Kommunikation an. Sendest du denn eine Start-Condition?
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
mit oszi muss ich mal überprüfen, aber da der Master nicht bussy ist, sollte es ja heissen das der ACK zurück kommt - also senden sollte ja klappen glaub ich
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 | }
|
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
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.