RP6 ROBOT SYSTEM - 4. Programming the RP6
void writeIntegerLength(uint16_t number, uint8_t base, uint8_t length);
This function is a variant for writeInteger, enabling you to specify the number of digits
(length) to be displayed. If the number's length is below the specified limit, the func-
tion will add leading zeros. If the number's length exceeds the specified limit, the
function will only display the trailing digits.
As usual we will demonstrate the function's behaviour by a few examples:
writeIntegerLength(2340, DEC, 5);
Output: “02340”
writeIntegerLength(2340, DEC, 8);
Output: “00002340”
writeIntegerLength(2340, DEC, 2);
Output: “40”
writeIntegerLength(254, BIN, 12);
Output: “000011111110”
4.6.2.2. Receiving data
The reception of Data through the serial interface is completely interrupt based. The
received data is written to a so called circular buffer automatically in the background.
Single received bytes/chars can be read out of the buffer with the function:
char readChar(void)
It returns the next available character in the Buffer and deletes it from the Buffer.
If the circular buffer is empty, 0 is returned. You should check for the buffer size with
this function:
uint8_t getBufferLength(void)
before calling readChar, otherwise you can't tell if a 0 is real data or not!
Several characters may be read with
uint8_t readChars(char *buf, uint8_t numberOfChars)
at once from the Buffer. You need to pass a pointer to an Array and the number of
chars to receive as parameters to this function. It returns the actual number of chars
that were written to the Array. This is useful if the buffer contains less chars than spe-
cified with numberOfChars paramter.
If the Buffer is completely full, any new received data will NOT overwrite data in the
buffer. Instead, a status Variable (uart_status) will be set to signal a buffer overflow
(UART_BUFFER_OVERFLOW). You should write your programs such that this can not
happen. Usually a buffer overflow occurs if the datarate gets to high or the program is
busy with something else for too long and does not read the data from the buffer. You
should avoid using long mSleep delays. If required, you can increase the size of the
circular buffer. Predefined size of the Buffer is 32 chars. In the file RP6uart.h, you can
change the definition UART_RECEIVE_BUFFER_SIZE.
A bigger example program can be found on the CD-ROM (Example_02_UART_02).
- 82 -