Jump to content
Taggsladder

Listen/spy/sniff UART comunication using MSP430

Recommended Posts

Hello

 

My name is Andreas and I am from Sweden, this is my first post here :)

 

First of all I want to say that I am very new to microcontrollers, please bear with me. I started off by reading "MSP430 Microcontroller Basics" and then bought TI's Launchpad and read "Getting Started with the MSP430 LaunchPad". Since then I have fiddled with the Launchpad a couple of weeks doing some basic projects. Since my C coding knowledge is not very good I have been working in Energia and the "simpler" coding, not sure what it is called.

 

I am working on a new project where I need the MSP430 to listen to UART traffic between two devices. Basically I just need to listen for a specific string sent from device 1 to device 2.

 

So far I have just connected the RXD and TXD of the 2 devices I want to listen to and connected them to the Launchpads P1.1 and P1.2. I have the two pins on the launchpad set to "SW UART". The MSP430 2553 is installed on the Launchpad but with no code on it. I then open Energia and open the serial monitor. In the serial monitor I can see the string I want to fetch and the commands sent by BOTH devices. So far so good. But as soon as I put the code "Serial.begin();" (tried all baud rates) in the MSP430 not changing anything else I still can monitor the communication but just the commands sent from device 1 and not the commands sent from device 2. Also the 2 devices don't work as they should because I suppose the commands from device 2 is not reaching device 1. I know for sure that the commands from device 1 reaches device 2 though, that part works.

 

I can say also that I don't have any specifics on the baud rate used between the two devices but I am almost sure it is 9600. Strangely I get the same results if I set the serial monitor at 9600, 14400, 19200, 28800, 38400, 57600, or 115200. Only if I set it at 4800 the formatting becomes incorrect!

 

Oh my god, this got complicated for me to describe, sorry. I am new to all this.

 

Thanks

 

Best regards

Andreas

Share this post


Link to post
Share on other sites

If you want to sniff all traffic sent from device 1 to device 2, all you need to do is connect that line to the RX pin on the launchpad.  When device 1 transmits a bit, both devices (device 2 and your sniffer) will read it.

 

I'm not an energia user, so I can't give specific code advice there, but the easiest way to pull this off would be to use the hardware UART peripheral and an interrupt.  When the launchpad receives (sniffs) a new byte on the line, the interrupt fires and does something with it.  Maybe pop it onto an array, or display it on a screen, or flash the LED....  There are lots of tutorials about interrupts on the MSP430 and lots of code examples on this site.  There should be a good write up in the two documents you referenced.

 

If you want to monitor both sides of the conversation (1--->2 and 2--->1) at the same time, things get more interesting.  Since a single UART module just has an RX/TX pair, to get two RX channels, you need two UARTs.  There are chips with dual UART, but the 2553 on the launchpad is not one of them.  You can, however, implement a timer based serial (which does exist already in Energia) to listen to the other line.  The same workflow would apply...use an interrupt to read the the incoming byte and then do something with it.

 

One word of caution.... UART lines are totem driven.  That means the transmitter asserts high and low by actively driving the line to Vcc or GND.  If you put two transmitters on the same line (sort of sounds like you did that in your description), if one tries to send a 1 while the other is still idle (0), the first transmitter will be pulling the UART line to ground while the idle transmitter tries to hold the line up.  This is called bus contention and creates a short-circuit condition that can potentially burn out the transmitter on the MCU or the entire MCU itself if it pulls enough current.  

 

The RX side is high impedance, and safe to do this as long as you aren't attempting to connect a ton of receivers in parallel. 

Share this post


Link to post
Share on other sites

If you want to sniff all traffic sent from device 1 to device 2, all you need to do is connect that line to the RX pin on the launchpad.  When device 1 transmits a bit, both devices (device 2 and your sniffer) will read it.

Thanks!!! Got it working now, sweet! That is exactly what i wanted!

 

I am gonna play with a little more, sure some more questions will pop up :)

 

Thanks again for your well written reply, truly appriciate it.

 

Best regards

Andreas

Share this post


Link to post
Share on other sites

Also remember if you are using the onboard serial USB->Serial convertor on the board that it limits the board rate to 9600. You will have to use jumpers to get speeds higher than 9600.

 

You may also run into difficulties with missed packets if you are using a polling method to transmit data. Remember that at 9600 baud you a character takes ~1ms to transmit. 

I found that if you are using 9600 baud you will need the DCO to be ~12Mhz to avoid losing packets. If you were to implement the receive and transmit (even just the transmit) through the DMA I am sure it would go alot smoother/less lossy.

In the end I just used a protocol analyzer, which I would highly recommend! Makes communications work much much easier. 

Share this post


Link to post
Share on other sites

As stated, the old MSP430G2 LaunchPad's UART limits you to 9600bps (boo).  The newer F5529 LaunchPad does not, and it has a backchannel UART that would be perfect for relaying this data back to a PC, fwiw.  Can run that one at higher speed (e.g. 230400) while using the boosterpack-onboard serial port for your sniffing.

 

I think the USCI peripheral that supplies this hardware UART is supposed to have some form of auto-baudrate detection, but I'm not sure on this platform and I'm fairly certain Energia doesn't support it natively.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...