Zur Übersicht - INFO - Neueste 50 Beiträge - Neuer Beitrag - Suchen - FAQ - Zum CC1-Forum - Zum CC-Pro-Forum

HWCOM bei 19200 fehlt sporadisch das letzte Byte Kategorie: Programmierung (von Detlef Bäthke - 23.09.2004 18:30)
Ich nutze:
C-Control II Unit, CC2-Application-Board, OSOPT V3.0
Hallo,
leider bin ich auch and der seriellen Kommunikation gescheitert.
Bei 9600 Baud funktioniert das Programm einwandfrei.
Bei 19200 Baud fehlt im Empfangsbuffer des CC2 sporadisch das letzte Byte.
Die Datenlänge beträgt maximal 134 Byte. RTS/CTS Handshake ist aktiviert.
Ich habe einen serielle Protokollanalysator in die Leitung gehängt.
Die Daten werden vollständig gesendet. Das CC2 ändert nicht den Pegel an der CTS Leitung.
Da der Empfangspuffer grö�er als 134 Byte ist, besteht dazu wohl auch kein Grund.
Hat jemand eine Idee?

Hier nun der Code:

//  Programmierung 24C16
//--------------------------
byte EEDataWrite[0x800];
byte EEDataRead[0x800];
int  Error;
byte HWcombuf[255];
byte RXDbuf[255];
byte TXDbuf[255];
byte TXDdata[255];
byte command;
byte HeaderCS;
byte DataCS;
byte Datalen;
byte TXDdatalen;
byte CFG_bck12;
byte CFG_bck34;
int  CFG_end_address;
byte CFG_init_value;
long CFG_checksum;
byte CFG_status;


//-----------
  thread main
//-----------
{ int i;
  byte cs;
  byte cmd_reset;
  CFG_bck12 = 0;
  CFG_bck34 = 0;
  CFG_end_address = 0;
  CFG_init_value = 0;
  CFG_checksum = 0;
  CFG_status= 0;
  hwcom.init ();                     // Init
  hwcom.setspeed(hwcom.SPEED_19200); // Baudrate  setzen
  hwcom.set_S0CON (hwcom.set8N1);    // 8Bit, no parity, 1 stop bit
  hwcom.setbuf(HWcombuf,255);            // standard buffer hat nur 64 byte
  lcd.init();
  lcd.clear();
  //lcd.goto(0, 0);
  //lcd.print("WAITING");
  wait lcd.ready();
  do  // endlosschleife
  {
    Error = 0;
    cmd_reset = 0;
    command = 0;
    DataCS = 0;
    Datalen = 0;
    TXDdatalen = 0;
    hwcom.flush(); //Buffer löschen;
    wait hwcom.rxd(); // Wartet auf Daten. Gibt -1 zurück, sobald Daten im Puffer
    i = hwcom.receive (RXDbuf, 4, 25); // die ersten 4 byte einlesen
    if i != 4 Error = 0x90;
    if Error == 0
    {
      HeaderCS = RXDbuf[0] + RXDbuf[2] + RXDbuf[3];
      if HeaderCS != RXDbuf[1] Error = 0x81;
      if Error == 0
      {
        command = RXDbuf[0];
        DataCS = RXDbuf[2];
        Datalen = RXDbuf[3];
        if Datalen > 0
        {
          i = hwcom.receive (RXDbuf, Datalen, Datalen + Datalen + 50);
          if i != Datalen
          {
            Error = 0x85;
            mem.copypos(TXDdata,0,RXDbuf,0,i);
            TXDdatalen = i;
          }
          if Error == 0
          {
            cs = 0;
            for i = 0 ... (Datalen - 1) cs = cs + RXDbuf[i];
            if DataCS != cs Error = 0x82;
          }
        }
      }
      if Error == 0
      {
        if (command > 0) and (command < 0xF)
        {
          if (command == 1)  Software_Version();
          if (command == 2)  Error = 0x83; // change Baudrate
          if (command == 3)  cmd_reset = -1;
          if (command == 4)  Config_Write();
          if (command == 5)  Config_Read(0);
          if (command == 6)  Error = 0x83;
          if (command == 7)  Parameter_Tester2Buf();
          if (command == 8)  Error = 0x83;
          if (command == 9)  Error = 0x83;
          if (command == 0xA)  Error = 0x83;
          if (command == 0xB)  Error = 0x83;
          if (command == 0xC)  Error = 0x83;
          if (command == 0xD)  Error = 0x83;
          if (command == 0xE)  Config_Read(-1);
        }
        else
        {
          Error = 0x83;
        }
      }
    }
    if Error != 0
    {
      TXDQuittung(Error);
    }
    else
    {
      TXDQuittung(command);
    }
  }
  while cmd_reset == 0;
  quit -1;
} //main


Hier noch ein Beispiel für eine fehlerhafte Datenübertragung aus Sicht des PC:
TX:07 D3 4A 82 06 00 00 01 02 03 04 05 06 07 00 68
   00 12 34 56 0E 04 09 17 12 13 14 15 16 17 18 19
   FF 01 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29
   2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39
   3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49
   4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59
   5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69
   6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79
   7A 7B 7C 7D 7E 7F
RX:85 D1 CB 81 06 00 00 01 02 03 04 05 06 07 00 68
   00 12 34 56 0E 04 09 17 12 13 14 15 16 17 18 19
   FF 01 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29
   2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 39
   3A 3B 3C 3D 3E 3F 40 41 42 43 44 45 46 47 48 49
   4A 4B 4C 4D 4E 4F 50 51 52 53 54 55 56 57 58 59
   5A 5B 5C 5D 5E 5F 60 61 62 63 64 65 66 67 68 69
   6A 6B 6C 6D 6E 6F 70 71 72 73 74 75 76 77 78 79
   7A 7B 7C 7D 7E

Gruss Detlef


    Antwort schreiben


Antworten:

Re: HWCOM bei 19200 fehlt sporadisch das letzte Byte (von André H. - 23.09.2004 19:16)
    Re: HWCOM bei 19200 fehlt sporadisch das letzte Byte (von Detlef Bäthke - 24.09.2004 16:24)
        Re: HWCOM bei 19200 fehlt sporadisch das letzte Byte (von André H. - 25.09.2004 16:34)
            Re: HWCOM bei 19200 fehlt sporadisch das letzte Byte (von Detlef Bäthke - 4.10.2004 17:21)
                Re: HWCOM bei 19200 fehlt sporadisch das letzte Byte (von André H. - 18.10.2004 19:26)
                    Re: HWCOM bei 19200 fehlt sporadisch das letzte Byte (von Detlef Bäthke - 1.11.2004 15:31)
                       Re: HWCOM bei 19200 fehlt sporadisch das letzte Byte (von André H. - 5.11.2004 9:00)
                          Re: HWCOM bei 19200 fehlt sporadisch das letzte Byte (von Detlef Bäthke - 5.11.2004 14:06)
        Re: HWCOM bei 19200 fehlt sporadisch das letzte Byte (von Günni - 24.09.2004 20:26)