This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Serial i/o programming using keil c

Hi. I'm working on a project involving a java program and the micro controller NXP P89v664.

The java program which utilises the RXTX package, outputs to the serial port a string of characters to be deciphered by the micro controller.

My java program is completed and outputs correctly as checked by virtual com ports and a c program.

I have written a keil c program to receive the input but I somehow receive random inputs instead.

I used the _getkey() fuction to receive the input and putchar() function to check the output.

I'm new to keil c can anyone shed some light on this pls?

Thanks.

Parents
  • Most circular buffer software is written incorrectly. There are several things you need to know with circ buffers.

    1. When the buffer is empty.
    2. When the buffer is full.
    3. How much data is in the buffer.
    4. Where the next data goes in.
    5. Where the next data comes out.

    To accomplish all of these, you obviously need a buffer, a next-in pointer (or index), and a next-out pointer (or index). Generally, you can figure out the amount of data in the buffer by subtracting the next-out from next-in (with a modulo). However, if the result is 0, does that mean that the buffer is full or empty? This is where most circ buffer implementations fall apart.

    Choosing a buffer size that is a power of 2, and using indexes for next-in and next-out, and NOT mod'ing the indexes after an increment, it is easy to answer the questions of the list above.

    This is how the serial I/O routines work that I wrote when I was at Keil. This is found at http://www.keil.com/download/docs/200.asp.

    The examples listed in this thread look mysteriously like the code I wrote way back when.

    Jon

Reply
  • Most circular buffer software is written incorrectly. There are several things you need to know with circ buffers.

    1. When the buffer is empty.
    2. When the buffer is full.
    3. How much data is in the buffer.
    4. Where the next data goes in.
    5. Where the next data comes out.

    To accomplish all of these, you obviously need a buffer, a next-in pointer (or index), and a next-out pointer (or index). Generally, you can figure out the amount of data in the buffer by subtracting the next-out from next-in (with a modulo). However, if the result is 0, does that mean that the buffer is full or empty? This is where most circ buffer implementations fall apart.

    Choosing a buffer size that is a power of 2, and using indexes for next-in and next-out, and NOT mod'ing the indexes after an increment, it is easy to answer the questions of the list above.

    This is how the serial I/O routines work that I wrote when I was at Keil. This is found at http://www.keil.com/download/docs/200.asp.

    The examples listed in this thread look mysteriously like the code I wrote way back when.

    Jon

Children
No data