Send and receive HEX in uart

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I am using 'cy8c4247lqi'. I am i am trying to interface fingerprint sensor over the uart.

   

My sensor can understand only HEX. Problem is i can sent Only String and char. by usinguartputstring() and uartputchar() but is is acsii value.

   

 

   

Please anyone guide me how to send and receive HEX in Uart.

   

 

   

Thanx

   

Dharmesh

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Hex data contains 0x00 which is used as string terminator. This prohibits the use of putstring().

   

PutChar() will send a 0x00 over the UART line, so using this API you will perform what you need to.

   

 

   

Bob

View solution in original post

0 Likes
3 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Hex data contains 0x00 which is used as string terminator. This prohibits the use of putstring().

   

PutChar() will send a 0x00 over the UART line, so using this API you will perform what you need to.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Thanx Bob for your reply.

   

 

   

I am using, 

   

        UART_UartPutChar(0x02);  //STX
        ch = UART_UartGetChar(); 
        UART_UartPutChar(ch);
        
        UART_UartPutChar(0x00u);  //LSB        
        ch = UART_UartGetChar(); 
        UART_UartPutChar(ch);
        
        UART_UartPutChar(0x00u);  //MSB
        ch = UART_UartGetChar(); 
        UART_UartPutChar(ch);
        
        UART_UartPutChar(0xD2u);  //DATA
        ch = UART_UartGetChar(); 
        UART_UartPutChar(ch);
        
        UART_UartPutChar(0x00u);  //PLB
        UART_UartPutChar(0x00u);  //PLB

   

 

   

This code to send 02 00 00 D2 00 00 to my sensor. For cross checking i am trying to recive the same char. i have sent. But every time i am reciveing only first element E.X putcahr(0x02) send 0x02 and ch = getchar(); should recive 0x02 but ch is = 0 .

   

I am doing any mistake here??

   

please help me. I can able to recive data which is sent bt key board i have problem with only hex values.

0 Likes
Anonymous
Not applicable

Try reading back multiple values from the UART after sending the HEX data to verify it isn't an issue with response data being stuck in a buffer (FIFO hardware or software Circular buffer).

   

Double check your UART transmission speeds match between the devices as well, mismatched speeds will have interesting data exchanges 🙂

   

Try checking the RX size to see how many received data bytes are stored, as there could be more than one stored, with 0 being a byte from some previous spurious response data.

0 Likes