This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RS 232 or USB communications

Other Parts Discussed in Thread: MAX3232, MSP430F5510, MSP430G2553, TUSB3410

Hello Eveyone:

I am very new to the MSP430 and for my first project I would like to build a USB controlled relays using a MSP430 chip, does anyone know how this can be done?

 

Thank you for all your help.

Brian

  • You can certainly control relays.  Two suggestions though:

    1)  Using RS232 will be easier to do (requires less software, and examples of the communications software you'll need can be downloaded from TI.  You will need to pay attention to the signal levels.   You can always use an inexpensive USB-to-RS232 adapter to get a USB interface.

    2)  You'll probably need a driver circuit to handle the voltage and current you'll need to operate your relays.

    Hope that's helpful.

  • Hello,

    there is a msp430x5xx and msp430x6xx family with integrated USB controller. You don' t need any special components to connect MSP430 to USB. You can download http://www.ti.com/mcu/docs/mcuorphan.tsp?contentId=65684&DCMP=USB&HQS=Other+OT+430usb where you can find examples easy to modify and a great guide describing libraries, variables, examples and much more.

    In this thread: http://e2e.ti.com/support/microcontrollers/msp43016-bit_ultra-low_power_mcus/f/166/p/106658/390317.aspx#390317 you can see the circuit for USB communication.

    Curt Carpenter said:
    Using RS232 will be easier to do (requires less software, and examples of the communications software you'll need can be downloaded from TI.  You will need to pay attention to the signal levels

    Can you show the place for RS232 code? I was looking on TI site for useful code some months ago (for example for design with MAX3232)  but I didn't find anything useful.

    Best regards,

    Mikolaj

  • Thanks curt for the reply I will give it a look.

     

    Brian

  • Thank you Mikolaj for the reply, I hope that I was clear about what I want to do.  I am going to use the MSP430 Launchpad and it only handles DIP to 20 pins, curt suggested I look in the TI area for downloads. I hope this is something I can do.

     

    Again Thanks for the reply.

    Brian

  • A couple weeks ago I also started with Launchpad and value line chips.  Some time later I had found it can be used for programming other MSP430 families (http://hackaday.com/2010/09/28/launchpad-not-limited-to-value-line-chips/ ). Launchpad is the cheapest programmer I have ever seen :)

    I don' t know prices of RS232- USB chips in your country but in mine, for instance, the MSP430F5510 (with USB) is cheaper than this converter.

    Of course using only RS232 with the value line MCU is more inexpensive way.

  • Hi Mikolaj:

    There are two or three places to find example code for serial communications with the MSP430.  Some rely on your device having a built-in UART mdoule; others for  "bit-banging" your own serial I/O using just digital I/O .   Look in the "Code Examples" that you can access here:

      http://www.ti.com/mcu/docs/mcuproductcontentnp.tsp?sectionId=95&familyId=342&tabId=3357#CE

    You'll find a 2400 bps bit-banged example in the  MSP430G2xx1.zip file, in the CCS ASM examples folder.  There are several others too, for C and other variants of the MSP430.

    Hope that helps.

  • I can purchase a USB-to-RS232 adapter from eBay here, Mikolaj, for $2.89 including shipping from Hong Kong.  I've used several of these, and have been satisfied with them.  The main advantage of the adapter approach is that it lets you build an interface that can be used for either USB or RS232, without changing any of your code :-)

    BTW -- it's easy to modify the bit-banged serial comm. interface in the examples to run at 9600 baud using the DCO -- you don't need a crystal oscillator.   You do need to measure SMCLK though, to get an accurate clock-cycle count for one bit time at 9600 baud.   I've found that the DCO, set up to run at around 7.8MHz, is easily stable enough to keep the UART timing right. 

  • Thanks guys for all the help.  Now I have to figure out how to use the S/W to program my chip.  At least I am going in the right direction (I HOPE). I will let you know ho0w things a going so if I get into trouble you can bail me out.

     

    Brian

  • I also thanks, Curt, for reply.

    When I firstly read "USB-to-RS232 adapter" I though you meant USB- RS232 chip converter (like ft232) but you had in mind something like that:


    I am surprised it works fine with standard RS232. It seems I need to place an order in Hong Kong soon :)



  • Curt Carpenter said:
    it's easy to modify the bit-banged serial comm. interface in the examples to run at 9600 baud using the DCO -- you don't need a crystal oscillator.   You do need to measure SMCLK though, to get an accurate clock-cycle count for one bit time at 9600 baud.

    This is why the BSL, which also uses a timer-based software UART, requires a SYNC byte. The software asumes that the other side knows its timing and adjusts itself based on the bit length pobserved on thsi sync byte. And even if the other side is off, it doesn't matter, since both are equally off then :)

    About the USB/serial adapter, soem of them can be stripped down internally, so you can directly fee dthem with the MSPs TTL signals. With an adapter as shown above, you'd need a MAX3232 for the voltage level shifting or you'll fry the MSP. And a proper connector too, because usually the hardware is glued inside the connector case so you cannot easily remove it.

  • You're absolutely right Jens-Michael!  As I mentioned in my first comment, you need to pay attention to signal levels when using a serial port, whether using the USB adapters or a standard PC serial port!   But I've had good success with simple one-transistor  buffers between the adapter and the MCU.   If you're not concerned about noise margin, I've been able to squeeze by using nothing but the 5V and 3V supplies that you can borrow off the Launchpad.  (Using a proper buffer would be better of course).

    The USB-to-Serial adapters I have are molded onto the USB cable, so there's no modifying them without major surgery. 

  • Try this cheap USb to serial TTL.

    http://www.virtualvillage.com/usb-2-0-to-ttl-uart-module-serial-device-converter-6pin-bu2001-020.html?origin=product-search&kwd=&source=pla&gclid=CIqm_NeZwrECFQff4Aodq3QAlQ

  • Well Thank you everyone for your input. 

    But I think that maybe I wasn't very clear on what I want to do, so I will try to explain what I am looking for, I'm sorry for not being clear and if I'm wrong sorry for the long reply.  What I am looking for is relay control using some kind of converter of USB, I want to send a command from a computer to this device and turn on a relay.  It can be USB or RS232, but if I can get away with USB it would require less hardware.  I would like to use one of the MSP430 Value Line chips, because I have a MSP430 Launchpad that programs the 14 to 20 pin chips.  Some of you suggesed bit banging to get the USB conversion and I am checking into that.  I only need to have 4 or 6 relays to control for my project ( I understand about currect requirements for relay so I will be using Transistors to control the relays), but more would be better but that will have to wait for another time. The converters that have been sugesseted I don't understand how that will work,but if someone can explain how I could use it than I am all ears.

     

    Thank you for all your help.

    Brian

  • Everything is clear :)

    If you decide to use MAX3232 you can build circuit like this:

    For MSP430G2553 TX and RX pins are connected to P1.2 and P1.1 (for other chips you need to check in datasheet which pins are used as TX and RX).

    DB9 is connected to PC and you can use any terminal program (like HyperTerminal) for communication MSP<->PC. You can use proposed adapter if you don't have RS232 port in your PC. After connection terminal program will able to detect new COM port.

    if you use relays (or other inductive components) remember about protection. To prevent damage you need to connect diode across every relay coil.

  • this should be simple. use launchpad USB to connect to PC .

    Install Putty program or use hyperterminal and open terminal connect using Virtual COM port created by windows on your PC.

    Write code for MSP430 and under UART interrupt routine check for byte sent by computer.

    By pressing different keys in ternal you can switch on/off relays. You can echo back byte when byte is not recognized by MSP430. :)

    something like this .

    Interrupt routine USCIA0

    {

    //     Read byte from RXbuf

     switch(rxbyte)

    case '1':

      switch on relay 1 (P1OUT|= BIT0);    (whatever PIN relay 1 is connected to ).

     break;

    case '1':

      switch on relay 2 (P1OUT|= BIT1);

     break;

     case '3'

         poweroff relay 1 (P1OUT& = ~BIT0)

    break;

    default:

         echo back received byte;

    break;

    }

  • Brian Johnston said:
    I will be using Transistors to control the relays

    Taek a look at the ULN2003 (available as DIP or SMD), it has 7 transistors complete with free-running diodes. some 100mA max per channel. And you can directly drive it with MSP output pins.

    Brian Johnston said:
    The converters that have been sugesseted I don't understand how that will work

    RS232 uses -3 to -12V for a '1' and +3 to +12V for a '0'. The MSP uses 0V for '0' and VCC for '1'. So you need to invert the logic and adjust the voltage levels.

    The MAX3232 does so. It generates the negative voltage from VCC through cpacitor switching and also does the logical inversion. And its RS232 inputs are tolerant to +-15V and more.

  • Thank you for the reply and I think this is what I am looking for because I was thinking last night" why cann't I just use the launchpad as an USB interface" and I think you must have heard me.  Thank you for the information and I will be giving it a try.

     

    Thank you

    Brian

  • The auxilary serial port on the Launchpad is limited to 9600 baud, since it is implemented in the TUSB3410 as a simple software UART and therefore is hardcoded to that speed. If you want any other speed, you will have to supply an external RS232 (or USB) to UART converter to the serial port of the Launchpad.

**Attention** This is a public forum