Triggering UART Interrupt on Specific Character

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Triggering UART Interrupt on Specific Character

1,538 Views
derekcook
Senior Contributor I

Hello, 

I have a master device that is constantly transmitting 47 bytes of data. I do not transmit anything to this master device to tell it to start transmitting, this is to keep the master independent of the slave. I am having some trouble with capturing the data I want in the slave device. All of my data is stored in ASCII Hex with the exception of my start character, which is 'L' or 'V'. 

Is there any way to trigger the UART Rx interrupt on a specific start char. I am not seeing much on this online. Currently, I am collecting 2 full buffers of data, and then parsing my full packet (start-end char) out of that data. This seems very inefficient. I was wondering if there was a better way to do this, such as triggering on a specific start char.

0 Kudos
5 Replies

1,353 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Derek Cook,

    Double check your question: Do you mean your received 47 bytes data all begin with 'L' or 'V'?

    'L' and 'V' is the start character, and you also make sure the other content in the 47 Bytes won't have the start bytes?

    If yes, it is easy to realize it, you can use the UART receive interrupt, then in the interrupt check the received data, if it is the specific start char, then write your received counter as the begin point.

    Actually, from my own experience, normally, the master and the slave side can define the uart communication protocol if you don't want to use the standard protocol like modbus.

   You can define the header as 0XA55A(header 2Bytes)+data length(1 byte) + data(nByte)+CRC(1byte). But this method also need the cooperation in the master side.

   This will make sure the communication data is correct and stable.

Wish it helps you!
Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,353 Views
derekcook
Senior Contributor I

Hey Kerry, 

Thanks for the response. This is similar to what I implemented yesterday morning after writing this post. I checked my data in the interrupt, and then when I saw the start char, I read in the full message. This cleaned things up quite a bit. 

I was just wondering if there was a way to trigger the interrupt on a specific character, and that does not seem to be the case. It seem like what you suggested is the best solution.  

0 Kudos

1,353 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Derek Cook,

     Yes, the method which I told is the very popular method in the practical application, even I, also use that method in my own application.

     About the specific character used to trigger the UART receive, unfortunately, the UART module can't support it.

Wish it helps you!

If you still have question about it, please kindly let me know.


Have a great day,
Kerry

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

1,353 Views
Carlos_Mendoza
NXP Employee
NXP Employee

Hi Derek,

Could you tell us which MCU are you using?

Thanks in advance!

Best Regards,
Carlos Mendoza
Technical Support Engineer

0 Kudos

1,353 Views
derekcook
Senior Contributor I

I am using the Kinetis KV31

0 Kudos