stm32f103 i2c_read

Gast #4877188
Lesenswert?

habe - mal wieder - ein problem mit stm. Ein si47303-fm-modul läuft am 
avr.

Beim ARM klappt irgendwie das Lesenn nicht:
1
// Read all registers from Si4703
2
void Si4703_Read(void) {
3
  uint8_t i;
4
  uint8_t buffer[32]; // 16 of 16-bit registers
5

6
  I2C_AcknowledgeConfig(I2C_PORT,ENABLE); // Enable I2C acknowledge
7
  I2C_GenerateSTART(I2C_PORT,ENABLE); // Send START condition
8
  while (!I2C_CheckEvent(I2C_PORT,I2C_EVENT_MASTER_MODE_SELECT)); // Wait for EV5
9
  I2C_Send7bitAddress(I2C_PORT,Si4703_ADDR,I2C_Direction_Receiver); // Send slave address for READ
10

11
  while (!I2C_CheckEvent(I2C_PORT,I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)); // Wait for EV6
12

13
  // Si4703 read start from r0Ah register
14
  for (i = 0x14; ; i++) {
15
    if (i == 0x20) i = 0x00;
16
    while (!I2C_CheckEvent(I2C_PORT,I2C_EVENT_MASTER_BYTE_RECEIVED)); // Wait for EV7 (Byte received from slave)
17
    buffer[i] = I2C_ReceiveData(I2C_PORT); // Receive byte
18
    if (i == 0x12) break;
19
  }
20
  I2C_AcknowledgeConfig(I2C_PORT,DISABLE); // Disable I2C acknowledgment
21
  I2C_GenerateSTOP(I2C_PORT,ENABLE); // Send STOP condition
22
  while (!I2C_CheckEvent(I2C_PORT,I2C_EVENT_MASTER_BYTE_RECEIVED)); // Wait for EV7 (Byte received from slave)
23
  buffer[i++] = I2C_ReceiveData(I2C_PORT); // Receive last byte
24

25
  for (i = 0; i < 16; i++) {
26
    Si4703_REGs[i] = (buffer[i<<1] << 8) | buffer[(i<<1)+1];
27
  }
28
}

bei I2C_CheckEvent hängt es sich auf. Entweder vom Modul kommt nichts 
zurück oder der code stimmt nicht.

Da ein i2c-Lcd an der gleichen Schnittstelle funktioniert und da das 
modul am avr geht, könnte es am code liegen.


Jemand eine Idee?
Gast #4877424
Lesenswert?

Niemand eine Idee.

Will das ganze jetzt mit Bitbang i2c versuchen. Erstes Ziel, es soll auf 
dem avr ein pcf8574 angesprochen werden. Klappt leider auch nicht.

Weiß jemand weiter?
1
#include "i2csoft.h"
2
#include "i2csoft.c"
3

4

5
#define i2c_init SoftI2CInit
6
#define i2c_stop SoftI2CStop
7
#define i2c_write SoftI2CWriteByte
8
#define i2c_start(x) SoftI2CStart();SoftI2CWriteByte(x) 
9
#define i2c_start_wait(x) SoftI2CStart();SoftI2CWriteByte(x);SoftI2CStop() 
10

11
#include "twilcd.h"
12

13
....
14

15

16
i2c_init();
17
lcd_init();
18
lcd_write("test");
Angehängte Dateien:
Gast #4878384
Lesenswert?

Pete K. schrieb:
> Warum benutzt Du AVR Bibliotheken für einen ARM?

Es ist ja im Prinzip alles das Gleiche. Wenn ich den auf dem AVR 
funktionierenden Bitbang-code auf den ARM potiere, weiß ich ob der 
Fehler am code oder an der Schnittstelle liegt. Leider funktionierte der 
aus dem inet gedowloadete code nicht. Jetzt weiß ich, wie i2c 
funktioniert. Der auf meinem AVR funktionierende bitbang code im Anhang. 
Für Lcd und Radio reicht der.
Angehängte Dateien:

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