5 Replies - 479 Views - Last Post: 23 July 2012 - 02:24 AM Rate Topic: -----

#1 Cyteam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-July 12

Serial Bootloader write command problem

Posted 22 July 2012 - 11:54 PM

I'm trying to send some command to a microcontroller which send back an ACK (0xcc) for each writing command like( Ping: 0x23 ,Run: 0x22 , Download: 0x21 etc

I can send each command separately and i receive the ACK back. Now I want to do this with a function like this writing:
    //
    // Send out the sync pattern and wait for an ack from the board.
    //
    byte[]ucSyncPattern[]={0x55, 0x55};
    byte[]COMMAND_ACK ={0xcc};
    byte[] ucAck;
    byte[]COMMAND_PING={0x20};

    if(!serial.Writer(ucSyncPattern,0, 2))
    {
        Log("SyncPattern with the device: error");
    }

    //
    // Wait for the ACK to be received, if something besides an ACK or a zero
    // is received then something went wrong.
    //
    do
    {
       serial.Reader(ucAck,0, 1);
    } while(ucAck == new byte[0]);

    if (ucAck != COMMAND_ACK)
    {
        Log("Synchronize with the device: error");
    }

    //
    // Make sure we can at least communicate with the board.
    //
    ucCommand = COMMAND_PING;
    if(serial.Writer(ucCommand,0, 1) < 0)
    {
        Log("Ping: error");
    }



what i want to have is something like this DumpView:
[19/07/2012 13:50:42] Written data
55 55 UU
[19/07/2012 13:50:42] Read data
00 cc .
[19/07/2012 13:50:42] Written data
03 20 20 .
[19/07/2012 13:50:42] Read data
00 cc .
but my function return this:
[23/07/2012 07:41:54] - Written data

55 55 03 20 20 UU.

[23/07/2012 07:41:54] - Read data

00 cc .

Thanks for your feedback

Cyteam

Is This A Good Question/Topic? 0
  • +

Replies To: Serial Bootloader write command problem

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3575
  • View blog
  • Posts: 11,116
  • Joined: 05-May 12

Re: Serial Bootloader write command problem

Posted 23 July 2012 - 01:09 AM

Does a sync pattern need to be sent before each command, or is it only on initial connection?

Also, I'm confused. You sent a sync command and waited for an ACK, but you sent a PING command and didn't wait for an ACK.
Was This Post Helpful? 0
  • +
  • -

#3 Cyteam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-July 12

Re: Serial Bootloader write command problem

Posted 23 July 2012 - 01:38 AM

Sorry the sync pattern is only on initial connection. Once the program has
detected a successful synchronization it sends out a "ping" command to
ensure that normal communication are functioning before proceeding with
downloading. This last step (ping) is not required but is provided as an example
of using the ``ping'' command.

After the initialization , i have to download a binary file into the microcontroller by sending always 8 bytes command
See my protocol on the attached file.

Thanks

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#4 Cyteam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-July 12

Re: Serial Bootloader write command problem

Posted 23 July 2012 - 02:03 AM

At this moment i can do that without the do while statement and it work:
  if (!serial.Writer(ucSyncPattern, 0, 2))
            {
                Log("SyncPattern with the device: error");
            }
            // wait for the ACK to be received,if somethings besides an ACK or a zero is received the something went                        wrong
            System.Threading.Thread.Sleep(800);  
            if (!serial.Writer(ucCommand, 0, 3))
            {
                Log("Ping with the device: error");
            }

How can i wait for the ack without this Thread.Sleep(800). Ther is a best way to do this like a state machine or somethingselse?

See my protocol on the attached file.

Thanks
[/quote]

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3575
  • View blog
  • Posts: 11,116
  • Joined: 05-May 12

Re: Serial Bootloader write command problem

Posted 23 July 2012 - 02:19 AM

There is a DataReceived event that can probably tell you when an ACK signal was sent back.

Implementing a simple state machine would be my choice.
Was This Post Helpful? 0
  • +
  • -

#6 Cyteam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 22-July 12

Re: Serial Bootloader write command problem

Posted 23 July 2012 - 02:24 AM

Have you an example of this state machine that can do it?
Thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1