CRC Check Verständnisproblem Implementierung DS18S20

Gast #2772560
Lesenswert?

Hallo zusammnen,

ich habe eine kleines Problem mit der Implementierung eines CRC Checks 
eines DS18S20 Temperatursensors.

Als Controller kommt ein Attiny26 zum Einsatz.

Hier nachfolgend ein Ausschnitt meiner main Funktion die aus mir 
unbekannten Gründen nicht funktioniert. Der Controller bleibt bei der 
Ausführung einfach stehen.

1
int main(void)
2
{
3
  
4
  uint8_t DS18S20_Full_Scratchpad[9];
5
  DS18S20_init();
6
  DS18S20_write_byte(DS18S20_ROM_CMD_SKIP_ROM);
7
  DS18S20_write_byte(DS18S20_FUNCT_CMD_CONVERT_T);
8
  
9
  DS18S20_wait_ready();
10
  
11
  DS18S20_init();
12
  DS18S20_write_byte(DS18S20_ROM_CMD_SKIP_ROM);
13
  DS18S20_write_byte(DS18S20_FUNCT_CMD_READ_SCRATCHPAD);
14
  
15
  DS18S20_read_bytes(DS18S20_Full_Scratchpad,9);
16

17
  
18
  uint8_t crc = 0;
19

20
  for (uint8_t IntI = 0; IntI< 9; IntI++) {
21
    
22
    crc = _crc_ibutton_update(crc, DS18S20_Full_Scratchpad[IntI]);
23
  
24
  }
25

26
  STATUSLED(crc);
27
 
28
}

Wenn ich mir hingegegen außerhalb der main Funktion eine eigene Check 
CRC Funktion anlege mit folgendem Code und Aufruf funktioniert das 
ganze.

1
int DS18S20_checkcrc(uint8_t crc_array[],uint8_t count) {
2
  
3
  uint8_t crc = 0;
4
    for (uint8_t IntI = 0; IntI< count; IntI++) {
5
      crc = _crc_ibutton_update(crc, crc_array[IntI]);
6
  }
7
  return crc; //Ist 0, wenn CRC okay
8
}

Wenn ich oben genannte Funktion in der main Funktion selbst anlege und 
aufrufe bleibt ebenfalls der COntroller stehen.

Kann mir diese Verhaltensweise vielleicht jemand erklären?

Gruß
Gast #2773379
Lesenswert?

Hallo,

der Controller bleibt innerhalb der for-Schleife stehen.

Nach vielem rumprobieren ist mir noch aufgefallen, dass das ganze im 
AVR5 Simulator einwandfrei durchläuft egal wo die Schleife im Quellcode 
steht.


Gruß

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