Bascom ---> Pascal

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • Page 1 of 6
Mathias
Benutzer
Avatar
Gender: n/a
Location: Weingarten - Baden
Posts: 307
Registered: 07 / 2003
Subject:

Bascom ---> Pascal

 · 
Posted: 24.06.2022 - 03:37  ·  #1
Hallo,

habe einen Codeschnipsel den ich gerne in Pascal übersetzen würde.
Es klappt leider nicht.

Code

Sub I2c_read(device_adres As Byte , Reg_adres As Byte , Wert_count As Byte )
  Local X As Byte
  Local Y As Byte
  Y = Wert_count - 1

  I2cstart                                          'Start I2C
  I2cwbyte Device_adres                             'Sende Slave Adresse
  I2cwbyte Reg_adres                                'Register Adresse
  I2cstart
  Incr Device_adres
  I2cwbyte Device_adres                             'sende Slave Adresse +1 für Lesen
  If Wert_count > 1 Then
    For X = 1 To Y
      I2crbyte Wert_array(x) , Ack                  'lese Wert
    Next
  End If
  I2crbyte Wert_array(wert_count) , Nack            'lese Wert
  I2cstop
  Waitms 10
End Sub


Code

Procedure I2c_read(device_adres:Byte;Reg_adres:Byte;Wert_count:Byte);
  Var X : Byte;
      Y : Byte;
  begin
  Y:= Wert_count - 1;
  bool:= I2Cout(device_adres,Reg_adres);
  inc(Device_adres);
  bool:= I2Cout(device_adres);                      // geht so nicht! Data fehlt.
  If Wert_count > 1 Then
    For X:= 1 To Y do
      bool:= I2Cinp(Wert_array[x]); //, Ack);       // geht so nicht! Adr fehlt.
    EndFor;
  EndIf;
  bool:= I2Cinp(Wert_array[Wert_count]); //, Nack); // geht so nicht! Adr fehlt.
//  mDelay(10);
End I2c_read;


An den drei Zeilen wo am Ende "geht so nicht!" scheitert es.
Vielleicht ist auch schon der der Ansatz falsch.
Wie kann man das zum Laufen bringen?

Danke
Gruß
Mathias
You must be logged in or your permissions are to low to see this Attachment(s).
golf
Benutzer
Avatar
Gender:
Location: Donauwörth
Age: 70
Posts: 250
Registered: 11 / 2009
Subject:

Re: Bascom ---> Pascal

 · 
Posted: 24.06.2022 - 04:58  ·  #2
Hallo Mathias,
auf die Schnelle, probier mal sowas aus.

Procedure I2c_read(device_adres:Byte;Reg_adres:Byte;Wert_count:Byte);
Var X : Byte;
begin

bool:= I2Cout(device_adres,Reg_adres);

For X:= 1 To Wert_count do
bool:= I2Cinp(device_adres,Wert_array[x]);
EndFor;

End I2c_read;

golf
golf
Benutzer
Avatar
Gender:
Location: Donauwörth
Age: 70
Posts: 250
Registered: 11 / 2009
Subject:

Re: Bascom ---> Pascal

 · 
Posted: 24.06.2022 - 06:06  ·  #3
Hallo Mathias,
welches I2C-Device ist das ?
Evtl die I2C-Adresse für Avrco prüfen.
golf
Merlin
Administrator
Avatar
Gender:
Age: 24
Posts: 1362
Registered: 03 / 2005
Subject:

Re: Bascom ---> Pascal

 · 
Posted: 24.06.2022 - 09:08  ·  #4
I2C addresses are strange things. They are usually 7 bits - but the high 7 bits. The last bit is used for reading and writing. I prefer to think of it that every device has two adjacent addresses - one for reading and one for writing.
rage
Benutzer
Avatar
Gender: n/a
Age: 64
Homepage: processanalytik.de
Posts: 235
Registered: 02 / 2007
Subject:

Re: Bascom ---> Pascal

 · 
Posted: 29.06.2022 - 08:32  ·  #5
Guten Tag,

ich kenne das Problem, zumeist bei SMA-Bausteinen. Ich habe ein Charger-Chip von einem Hochleistungs-Akku auslesen müssen. Leider kann der AVRCO kein Repeat-Start nicht. Daher musste ich was basteln. Wenn Du nicht weiterkommst, schreib mal was das für ein CHip ist.

cu Ralf
golf
Benutzer
Avatar
Gender:
Location: Donauwörth
Age: 70
Posts: 250
Registered: 11 / 2009
Subject:

Re: Bascom ---> Pascal

 · 
Posted: 29.06.2022 - 17:37  ·  #6
Mathias
Benutzer
Avatar
Gender: n/a
Location: Weingarten - Baden
Posts: 307
Registered: 07 / 2003
Subject:

Re: Bascom ---> Pascal

 · 
Posted: 03.08.2022 - 21:58  ·  #7
Hatte wegen Dringlichkeit eines anderen Projekts keine Zeit.
Bin wider aktiv.
Danke für die Posts.

Es handelt sich um den Klimasensor BME280 von Bosch.
Datenblatt im Anhang.

@golf
I2C per Bitbang kenne ich noch von 8051er Zeiten.
Wenn's geht ohne Bitbang.

Gruß
Mathias
You must be logged in or your permissions are to low to see this Attachment(s).
miparo
Administrator
Avatar
Gender:
Location: Germany
Age: 59
Posts: 953
Registered: 09 / 2007
Subject:

Re: Bascom ---> Pascal

 · 
Posted: 04.08.2022 - 00:38  ·  #8
This is a mini job for Merlin :)

The AVRco makes it so unfortunately:
I2Cout(Addr,reg,data);
> Addr
< ACK slave
> Reg
< ACK Slave
> data
< ACK Slave
> STOP master , >>> this is not always desired here.


Better would be an optional bool, if a stop should be send too.
[code]
I2Cout(Addr,Reg, data, bool[ SendStop ]);
I2Cinp(Addr, data, bool[ SendStop ]);
[/quote]
Due to the optionl bool the code remains also downward compatible

Then also I2C devices with Auto-Increment would be easier to control.
This is how most other compilers do it.

Quote

I2Cout( Addr, Reg,Value, false);
I2Cinp(Reg+1,Data,false);
I2Cinp(Reg+2,Data,false);
......
I2Cinp(Reg+x,Data,true); <<< last with STOP


THE BEST :)

The whole thing is already in the compiler !
But this is only used in the LANport driver.
For this there is an AVRco internal bool _AUTOACK.
With the normal I2C driver it is set to True in $_Main, so that always a STOP is sent.

x.$_Main:
LDI _ACCA, true
MOV _AUTOACK, _ACCA

[code]

SYSTEM.I2CSTOPB:
BST FLAGS2, _AUTOACK <<< unfortunately not public
BRTS SYSTEM._L0032
// send bad stop
SBI DDRC, 007h
NOP
SBI DDRC, 006h
LDI _ACCA, 001h
RCALL SYSTEM.uDelay
CBI DDRC, 007h
LDI _ACCA, 001h
RCALL SYSTEM.uDelay
CBI DDRC, 006h
LDI _ACCA, 001h
RCALL SYSTEM.uDelay
SYSTEM._L0032:
SER _ACCA
STS I2C_DevLock, _ACCA
RET



SYSTEM.I2COUT:
RCALL SYSTEM.I2CSTARTB
CLC
ROL _ACCDLO
RCALL SYSTEM.I2CSENDBYTE
TST _ACCA
BRNE SYSTEM._L0045
RCALL SYSTEM.I2CSTOPB <<<<<<<<<< problem
LDI _ACCA, false
RET
SYSTEM._L0045:
MOV _ACCDLO, _ACCAHI
RCALL SYSTEM.I2CSENDBYTE
TST _ACCA
BRNE SYSTEM._L0050
RCALL SYSTEM.I2CSTOPB <<<<<<<<< problem
LDI _ACCA, false
RET
------------------
SYSTEM.I2CINP:
RCALL SYSTEM.I2CSTARTB
SEC
ROL _ACCDLO
RCALL SYSTEM.I2CSENDBYTE
TST _ACCA
BRNE SYSTEM._L0044
RCALL SYSTEM.I2CSTOPB <<<<<<<<<<<<< problem
LDI _ACCA, false
RET
SYSTEM._L0044:
RCALL SYSTEM.I2CRECVBYTE
RCALL SYSTEM.I2CSTOPB <<<<<<<<<<<<<<<< problem
LDI _ACCA, true
RET

[/code]


miparo
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • Page 1 of 6
Selected quotes for multi-quoting:   0

Registered users in this topic

Currently no registered users in this section

The statistic shows who was online during the last 5 minutes. Updated every 90 seconds.
MySQL Queries: 15 · Cache Hits: 14   139   153 · Page-Gen-Time: 0.027241s · Memory Usage: 2 MB · GZIP: on · Viewport: SMXL-HiDPI