How can I get byte_length from Rx port ?

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

cross mob
Anonymous
Not applicable

Guys,

   

How can I get byte_length from Rx port ?

   

Thanks

0 Likes
22 Replies
Anonymous
Not applicable

Is it posibble doing this :

   

byte_length=c;
         for (i=0;i<byte_length;i++)
               {
                 RxdataBuff = c;    // Get a character from UART RX data register
               }   

0 Likes
ArvindK_86
Employee
Employee
10 sign-ins 5 sign-ins 10 solutions authored

It is possible to write a string of characters (multiple bytes) into a TX. But not the same with RX.\

   

The RX has a buffer that can hold only 1 byte of information, and can read only one byte at a time.

   

 

   

If you want to get the byte count, you have to keep reading the data from the buffer, one byte at at time.

   

 

   

You can give this a try:

   

 

   

   

   

while (UART_bReadRxStatus() & UART_RX_REG_FULL)) // keeps looping as long as there is data in the RX buffer

   

{

   

if (UART_cReadChar()) RXcount++;  //_cReadChar reads one character from buffer, returns 0 if there's an error or no data

   

}

0 Likes
Anonymous
Not applicable

How can I detect Rx buffer with content :

   

AB 04 01 04 00

   

??

0 Likes
Anonymous
Not applicable

can I do :

   

byte_length=UART_1_cGetChar();
                       
                        for (i=0;i<byte_length;i++)
                            {
                                                    RxdataBuff = UART_1_cGetChar();    // Get a character from UART RX data register
                            }
                           
                                    LCD_1_Position(0,0);
                                    LCD_1_PrCString("SN: ");
                                    LCD_1_Position(1,0);

                                    for (i=0;i<10;i++)
                                    {           
                                        LCD_1_PrHexByte(RxdataBuff); // Print serial number of the card detected
                                    }       

0 Likes
Anonymous
Not applicable

while (UART_bReadRxStatus() & UART_RX_REG_FULL)) // keeps looping as long as there is data in the RX buffer

   

{

   

if (UART_cReadChar()) RXcount++;  //_cReadChar reads one character from buffer, returns 0 if there's an error or no data

   

}

   

 

   

It's not a valid working code......

0 Likes
Anonymous
Not applicable

You need to enable the command buffer and define the command terminator.

   

Then using the code below it should work

   

if(!UART_bCmdCheck() ){

   
        byte_length = UART_bCmdLength();    
   
    }   
   
        
   
    Regards   
0 Likes
Anonymous
Not applicable

So it'll be like this :

   

                                            if(!UART_bCmdCheck() ){
                                               byte_length = UART_bCmdLength();
                                            }

                    
                        for (i=0;i<byte_length;i++)
                            {
                                                    RxdataBuff = UART_1_cGetChar();    // Get a character from UART RX data register
                            }
                          
                                    LCD_1_Position(0,0);
                                    LCD_1_PrCString("SN: ");
                                    LCD_1_Position(1,0);

                                    for (i=0;i<10;i++)
                                    {          
                                        LCD_1_PrHexByte(RxdataBuff); // Print serial number of the card detected
                                    } 

0 Likes
Anonymous
Not applicable

How can I enable the command buffer and define the command terminator ?

   

Can you give me example ? thank you

0 Likes
Anonymous
Not applicable

I can't see command terminator since it's a reply from device......for 5 to 10 bytes.

   

How can I create it ?

   

Please find my manual attached, and it's on "Basic Command Description"

   

Thanks a lot

0 Likes
Anonymous
Not applicable

The logic :

   

I gave command to device and it replied with AB 04 01 04 00 on Rx port, how can I parse it so I can display them into LCD ?
thank you

0 Likes
Anonymous
Not applicable

 To enable the command buffer, there is a parameter that you define to enable.

   

Could you re-attached the manual?

   

 

   

The reply must formatted in some way, like an address and a data byte plus a checksum or anything else. If the reply sequence always end with a different value then after a pre-difined time has elapsed retrieve the data from the command buffer.

   

 

   

Regards

0 Likes
ArvindK_86
Employee
Employee
10 sign-ins 5 sign-ins 10 solutions authored

You can define the command terminator in the UART user module parameters window, and enable the RX command buffer option. RX interrupts must be enabled.

   

 

   

From the datasheet-

   

 

   

   
    RxCmdBuffer   
   
    

This parameter enables the receive command buffer and firmware used for command processing. The UART RX interrupt must be enabled for the command buffer to operate.

   
   
    RxBufferSize   
   
    

This parameter determines the number of RAM locations that are reserved for the receive buffer. The largest command that can be received is one less than the buffer size selected, because the string must be null terminated. This parameter is only valid when the RxCmdBuffer is enabled and the UART RX interrupt is enabled.

   
   
    CommandTerminator   
   
    

This parameter selects the character that signals the end of a command. When received, a flag is set signaling that a complete command has been received. After this flag is set, additional characters are not accepted until the cmdReset() function is called.

    

 

    

 

    

Make sure the input stream always contains the cmd terminator to get the count. If the command terminator is not received, in this code, byte_length will not be set-

    

if(!UART_bCmdCheck() )

    

{
           byte_length = UART_bCmdLength(); 
}

    

 

    

The other issue is that the RX cmd buffer has a size limitation (32 or 64 bytes, pls check)

    

 

    

 

    

If all you want to do is display the RX string on an LCD, the best solution is to use interrupts (you can get an interrupt every time one byte is received) and display the current byte in the RX buffer on LCD. Additionally use the RX status flags to determine if all data has been displayed.

   
0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

To enable the command buffer, there is a parameter that you define to enable.

   

Could you re-attached the manual?

   

 

   

The reply must formatted in some way, like an address and a data byte plus a checksum or anything else. If the reply sequence always end with a different value then after a pre-difined time has elapsed retrieve the data from the command buffer.

   

 

   

Regards

==============   

   

Yes sure, I'll attach the manual again.

   

if you're talking about checksum, make more sense for me since I read about it on the manual but don't know how to use it yet.

   

I need to check the end of the reply (Rx), but from I can see it's always changing.....

   

I can print out Rx, but still random. What I want, is if I give command AB 02 01,

   

device will reply AB 04 01 04 00, please see page 5 on the manual.

0 Likes
Anonymous
Not applicable

Can I do like this :

   

while(1)
    {
       do {

                                UART_1_CmdReset();                // Reset Command Buffer
            for (i=0;i<2;i++) //repeat command 15 times
              {
                for (i=0;i<3;i++)   
                {
                    UART_1_PutChar(sel_card); // Send a character to UART TX port
                }
                  Delay50uTimes(1);

             }
               
                c = UART_1_cGetChar();
           
         }while (c == 0);
            byte_length = UART_1_cGetChar();
         for (i=0;i<byte_length;i++)
            {
                RxdataBuff = UART_1_cGetChar();    // Get a character from UART RX data register
            }   
        if (RxdataBuff[0] == 0xAB)//check the first character
        {
         
         switch(RxdataBuff[1])            // Check status byte
            {
                case 0x04:            // If 0x04 : Operation success
                    LCD_clr_line(0); //clear LCD screen
                      LCD_clr_line(1);

                    LCD_1_PrCString("Card Selected");    // Print "Card selected" on the LCD  ;
                    LCD_1_Position(1,0);
                    LCD_1_PrCString("SN: ");
                    for (i=2;i<6;i++)
                    {           
                        LCD_1_PrHexByte(RxdataBuff); // Print serial number of the card detected
                    }                   
                    break;
               
                case 0x02:            // If 0x02 : Operation fail
                    LCD_clr_line(0); //clear LCD screen
                      LCD_clr_line(1);

                    LCD_1_PrCString("Operation failed");    // Print "Card selected" on the LCD  ;
                           
                    break;
   
             }//end switch
        }//end if
    }
 } 

0 Likes
Anonymous
Not applicable

from this code,

   

it's responding to AB 02 01 perfecty,

   

when I can not display in orderly manner on hex byte ( still raw ), because I can't determine how many bytes to be read

   

=============
    while(1)
    {
       do {

                                UART_1_CmdReset();                // Reset Command Buffer
           
             
                for (i=0;i<15;i++)   
                {
                    UART_1_PutChar(0x01); // Send a character to UART TX port
                }
                  Delay50uTimes(1);

             
               
                c = UART_1_cGetChar();
           
         }while (c == 0);
           
                        
        if (c == 0x01)//check the card available
        {
         LCD_clr_line(0);
         LCD_clr_line(1);
         LCD_1_Position(0,0);
         LCD_1_PrCString("Card in ");
         UART_1_CmdReset();                // Reset Command Buffer
           for (i=0;i<3;i++)   
                {
                    UART_1_PutChar(sel_card); // Send a character to UART TX port
                }
            byte_length = UART_1_cGetChar();
            /*
            for (i=0;i<byte_length;i++)
            {
                RxdataBuff = UART_1_cGetChar();    // Get a character from UART RX data register
            }

   

// Please help on how to read the byte length and parse it ?
            */

                    LCD_1_Position(1,0);
                    LCD_1_PrCString("SN: ");
                    for (i=2;i<6;i++)
                    {           
                        LCD_1_PrHexByte(byte_length); // Print serial number of the card detected
                    }                   
         
        }//end if 0x01
    }//end while

0 Likes
Anonymous
Not applicable

I try this one and returning some bytes, but not sure if it's right or not

   

while(1)
    {
       do {

                                UART_1_CmdReset();                // Reset Command Buffer
           
             
                for (i=0;i<15;i++)   
                {
                    UART_1_PutChar(0x01); // Send a character to UART TX port
                }
                  Delay50uTimes(1);

             
               
                c = UART_1_cGetChar();
           
         }while (c == 0);
           
                        
        if (c == 0x01)//check the card available
        {
         LCD_clr_line(0);
         LCD_clr_line(1);
         LCD_1_Position(0,0);
         LCD_1_PrCString("Card in ");
         UART_1_CmdReset();                // Reset Command Buffer
           for (i=0;i<3;i++)   
                {
                    UART_1_PutChar(sel_card); // Send a character to UART TX port
                }
               
                  if(!UART_1_bCmdCheck() )
                  {
                      byte_length = UART_1_bCmdLength();
                  }

           
           
            for (i=0;i<byte_length;i++)
            {
                RxdataBuff = UART_1_cGetChar();    // Get a character from UART RX data register
            }
           
                    LCD_1_Position(1,0);
                    LCD_1_PrCString("SN: ");
                    for (i=2;i<6;i++)
                    {           
                        LCD_1_PrHexByte(RxdataBuff); // Print serial number of the card detected
                    }                   
         
        }//end if 0x01
    }//end while
 }//end main

0 Likes
Anonymous
Not applicable

what shoud I put for command terminator ? I can't see what's the end of the Rx...??

                                    
       
        CommandTerminator       
       
        

This parameter selects the character that signals the end of a command. When received, a flag is set signaling that a complete command has been received. After this flag is set, additional characters are not accepted until the cmdReset() function is called.

       
0 Likes
Anonymous
Not applicable

if the return is : AB 04 01 04 00  ......what's the command terminator ?

   

00 ??

0 Likes
Anonymous
Not applicable

Please have a look on the video :

   

http://s129.photobucket.com/user/picture_77/media/RFID_zps0aef3a5d.mp4.html

   

I used :

   

      byte_length = UART_1_cReadChar();
            

   

The code :

   

while(1)
    {
       do {

                                UART_1_CmdReset();                // Reset Command Buffer
           
             
                for (i=0;i<15;i++)   
                {
                    UART_1_PutChar(0x01); // Send a character to UART TX port
                }
                  Delay50uTimes(1);

             
               
                c = UART_1_cGetChar();
           
         }while (c == 0);
           
                        
        if (c == 0x01)//check the card available
        {
         LCD_clr_line(0);
         LCD_clr_line(1);
         LCD_1_Position(0,0);
         LCD_1_PrCString("Card in ");
         UART_1_CmdReset();                // Reset Command Buffer
           for (i=0;i<3;i++)   
                {
                    UART_1_PutChar(sel_card); // Send a character to UART TX port
                }
                /*
                  if(!UART_1_bCmdCheck() )
                  {
                      byte_length = UART_1_bCmdLength();
                  }
                  */
                   byte_length = UART_1_cReadChar();
                 
           
           
            for (i=0;i<byte_length;i++)
            {
                RxdataBuff = UART_1_cGetChar();    // Get a character from UART RX data register
            }
           
                    LCD_1_Position(1,0);
                    LCD_1_PrCString("SN: ");
                    for (i=0;i<4;i++)
                    {           
                        LCD_1_PrHexByte(RxdataBuff); // Print serial number of the card detected
                    }                   
         
        }//end if 0x01
          else
         if (c == 0xFE)
         {
           LCD_clr_line(0);
           LCD_clr_line(1);
           LCD_1_Position(1,0);
           LCD_1_PrCString("No Card! ");

         }//end 0xFE
    }//end while
 }//end main

0 Likes
Anonymous
Not applicable

The respond description :

   

   

0 Likes
Anonymous
Not applicable

In the protocol you use there is no command terminator, so you can't use the command buffer.

0 Likes
Anonymous
Not applicable

I tested with serial port and RS232 in computer

   

I send AB 02 01 and the response is AB 04 01 04 00

   

but in cypress I get a different response it's not AB 04 01 04 00.....why is that ????????????????????????

   

0 Likes