EFM32 I2C startet nicht

Gast #4272957
Lesenswert?

Abend. Ich habe vor kurzem mit dem EFM32 Happy gecko angefangen.

Das ist mein erster Versuch den I2C zu benutzen. Mein Code habe ich 
selbst geschrieben, aber irgendwie startet I2C überhaupt nicht.
Vllt. habe ich irgendwas vergessen:
1
include <stdio.h>
2
#include <stdlib.h>
3

4
#include "em_device.h"
5
#include "em_chip.h"
6
#include "em_cmu.h"
7
#include "em_emu.h"
8
#include "em_gpio.h"
9
#include "em_cmu.c"
10

11

12
#include "em_gpio.c"
13
#include "em_i2c.h"
14

15
static uint8_t BufA[2];
16
static uint8_t BufB[7];
17
volatile I2C_TransferReturn_TypeDef status;
18
static I2C_TransferSeq_TypeDef seq ={
19
    .addr = 0x80,
20
    .buf[0].data = BufA,
21
    .buf[1].data = BufB
22
};
23
static I2C_Init_TypeDef I2INIT={
24
    .clhr = i2cClockHLRStandard,
25
    .enable= true,
26
    .freq= I2C_FREQ_STANDARD_MAX,
27
    .master=true,
28
    .refFreq=false
29

30
};
31
void testwrite(){
32
    seq.buf[0].len=2; //send 2 bytes
33
    seq.buf[1].len=1; //receive 1 byte
34

35
    seq.buf[0].data[0]=0x84;
36
    seq.buf[0].data[1]=0xB8;
37
    seq.flags=I2C_FLAG_WRITE_READ;
38
    I2C_TransferInit(I2C0, &seq);
39

40

41

42
};
43
int main(void)
44
{
45

46
  /* Chip errata */
47
  CHIP_Init();
48
  CMU_OscillatorEnable(cmuOsc_HFRCO,1,0);
49
  CMU_ClockEnable(cmuClock_HFPER, true);
50
  CMU_ClockEnable(cmuClock_GPIO,1);
51
  CMU_ClockEnable(cmuClock_I2C0,1);
52
  //I2C Augänge  konfigurieren
53
  GPIO_PinModeSet(gpioPortD, 7, gpioModeWiredAndPullUpFilter, 1);
54
  GPIO_PinModeSet(gpioPortD, 6, gpioModeWiredAndPullUpFilter, 1);  
55
  I2C0->ROUTE = I2C_ROUTE_SDAPEN | I2C_ROUTE_SCLPEN | (1 << _I2C_ROUTE_LOCATION_SHIFT);
56
  //Sensor einschalten=
57
    GPIO_PinModeSet(gpioPortC, 8, gpioModePushPull , 1);
58
    GPIO_PinOutSet(gpioPortC,8);
59
  I2C_Init(I2C0,&I2INIT);
60

61
  while (1)
62
  {
63
    testwrite();
64

65

66
  GPIO_PinModeSet(5,5,gpioModePushPull,1);//test led
67
  GPIO_PinOutSet(5,5);
68

69
}
70
}
#4272985
Lesenswert?

Direkt in em_i2c.c steht, wie man die I²C funktionen benutzen muss:
1
I2C_TransferReturn_TypeDef ret;
2
 
3
  // Do a polled transfer
4
  ret = I2C_TransferInit(I2C0, &seq);
5
  while (ret == i2cTransferInProgress)
6
  {
7
    ret = I2C_Transfer(I2C0);
8
  }

Man müsste nur lesen können...
Gast #4273096
Lesenswert?

Also, mein Code sieht jetzt so aus:
1
void testwrite(){
2
    seq.buf[0].len=2; //send 2 bytes
3
    seq.buf[1].len=1; //receive 1 byte
4

5
    seq.buf[0].data[0]=0x84;
6
    seq.buf[0].data[1]=0xB8;
7
    seq.flags=I2C_FLAG_WRITE;
8
    I2C_TransferInit(I2C0, &seq);
9
    status= I2C_TransferInit(I2C0, &seq);
10

11
        while (status==i2cTransferInProgress){
12

13
          status=I2C_Transfer(I2C0);
14
        }
15

16

17
};

Im debugger hängt der MCU in der while (status==i2cTransferInProgress) 
Schleife
Gast #4273302
Lesenswert?

Tja, ich bin doof

  while (status==i2cTransferInProgress){

          status=I2C_Transfer(I2C0);
        }

hat sofort geholfen.
Nur hing immer noch  mein LA an den I2C BUs, und störte den ganzen 
System...

Danke an allen

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