0

I am using the default example which can be found here.

The part of the code I am interested is this:

#define TEST_BUFFER_SIZE        16


u8 SendBuffer[TEST_BUFFER_SIZE];
u8 ReceiveBuffer[TEST_BUFFER_SIZE];



for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
    SendBuffer[Index] = Index;
    ReceiveBuffer[Index] = 0;
}


XUartLite_Recv(&UartLite, ReceiveBuffer, TEST_BUFFER_SIZE); 
XUartLite_Send(&UartLite, SendBuffer, TEST_BUFFER_SIZE);


while ((TotalReceivedCount != TEST_BUFFER_SIZE) ||
    (TotalSentCount != TEST_BUFFER_SIZE)) {
}


for (Index = 0; Index < TEST_BUFFER_SIZE; Index++) {
    if (ReceiveBuffer[Index] != SendBuffer[Index]) {
        return XST_FAILURE;
    }
}

The buffer can hold values of 1 byte long. Using realterm I send a text file which hold values such as:

0 12 3 4 56 7 8 91

but what I read at the ReceiveBuffer is '0', ' ', '1', '2', ' '... etc I know that it sends ASCII characters because during debuging I see that the SendBuffer sends characters such as '\r', '\f' which my terminal translates as numbers but how do I send a two digit number????

  • A two-digit number is sent as two ASCII characters. You will have to convert a C int to ASCII characters before sending, and convert the received characters back to an int on reception. – Peter Bennett Oct 22 '16 at 19:19

1 Answers1

2

A byte can be between 0 and 255. If you send, for example, decimal 65 then the system will translate it to 'A'. Once you've received the byte, 'A', just convert it to an integer with (unsigned int)ReceiveBuffer[i]. You'll get 65.

Another approach would be breaking the 2-digit-number into the digits and sending each digit respectively.

Rohat Kılıç
  • 26,954
  • 3
  • 25
  • 67