Programming DS89C450 - Linux

Discussion in 'Embedded Systems and Microcontrollers' started by PsySc0rpi0n, Oct 5, 2014.

  1. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3
    Hello everyone.

    This year my project will be to program an 8051 compatible micro-controller, the DS89C450.

    I have already built the circuit and I think it's working properly.
    Now I need to communicate with it. I'm using a 5V FTDI to convert an RS232+MAX232 into an USB plug.

    I know I need a set of instructions to configure the connection and I found a python script to do that job. It's here:
    Code (C):
    1.  
    2. ################################
    3. #DS89C430/DS89C450 ROMLOADER  #
    4. #by Vinod.S  #
    5. ################################
    6. import serial,time,sys,os
    7. os.system("clear")
    8. if not sys.argv[1:]:
    9. print "hex file not specified in command line argument\n\n"print "usage:\npython romloader.py filename.ihx\n\n"print "example:\n python romloader.py ledblink.ihx\n\n"sys.exit(0)
    10. ser = serial.Serial("/dev/ttyUSB0",57600)
    11. ser.timeout = 0.3
    12. try:
    13. ser.open()ser.setDTR(1)
    14. except Exception,e:
    15. print "error open serial port: " + str(e)exit()
    16. if ser.isOpen():
    17. try:ser.flushInput()ser.flushOutput()ser.write("\x0D")time.sleep(0.1)recbuffer = ser.read(80)list = recbuffer.split(" ")if 'LOADER' in recbuffer:
    18. print "CONNECTED TO LOADER SUCCESSFULLY"
    19. print recbuffer
    20. else:
    21. print "CONNECTION ERROR"
    22. ser.setDTR(0)
    23. ser.close()
    24. sys.exit(0)
    25. ser.write("K\x0D")
    26. time.sleep(0.1)
    27. ser.write("L\x0D")
    28. f=open(sys.argv[1],"rU")
    29. hexcontent = f.read()
    30. f.close()
    31. ser.write(hexcontent+"\x0D")
    32. k = ser.read(200)
    33. print k
    34. ser.setDTR(0)
    35. ser.close()
    36. except Exception, e1:
    37. print "error communicating...: " + str(e1)
    38. else:
    39. print "cannot open serial port "
    40.  

    When I connect FTDI to PC, my udevamd monitor says:

    KERNEL[77368.473064] add /devices/pci0000:00/0000:00:14.0/usb3/3-1 (usb)
    KERNEL[77368.473166] add /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0 (usb)
    KERNEL[77368.473760] add /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/ttyUSB0 (usb-serial)
    KERNEL[77368.473888] add /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/ttyUSB0/tty/ttyUSB0 (tty)
    UDEV [77368.513321] add /devices/pci0000:00/0000:00:14.0/usb3/3-1 (usb)
    UDEV [77369.520437] add /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0 (usb)
    UDEV [77369.520883] add /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/ttyUSB0 (usb-serial)
    UDEV [77369.522687] add /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/ttyUSB0/tty/ttyUSB0 (tty)

    But when I try to run the script with the file .ihx (Intel hex format for the C code I'm trying to load) to the uC, it says me that it cannot be done because the port is already open, therefore cannot be used!

    Note: I've installed a package named [TT]pyserial[/TT] so that the python script would run!

    Anyone can help me???
     
  2. josip

    Member

    Mar 6, 2014
    63
    12
    BTW, once when you establish connection, configured baud rate on PC side dependence of DS quartz crystal. I made a simple Win32 calculator that can be useful for setting highest possible transfer rate (flashing speed) with minimum error. Also, I was using only PL2303HXD that support any (non-standard) baud rate, don't know if FTDI have same possibility.
     
  3. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3
    Thanks for replying...

    I'm using a 110592Mhz crystal!

    Anyway, I'm now using cutecom but even with this tools I can't make the code I send to the uC to work!
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,394
    1,607
    Virtual COM ports over the USB do not depend on the serial data rate and such as there is no serial link: it's all over the USB connection. You can still set these parameters (since every legacy app will attempt to do so anyway) but this has no effect on the transmission.

    It will just work no matter the settings.

    However, I've seen FTDI chips that require a custom driver (from FTDI). You'll need to look your mystery device up on the manufacturer's page.
     
    PsySc0rpi0n likes this.
  5. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3
    Well, I have changed method.

    I found an application to do the job that I didn't know before.
    I'm trying now with cutecom and using the following settings:

    Device: /dev/ttyUSB0
    Baud rate: 57600 (I'm using a crystal of 110592Mhz)
    Data bits: 8
    Stop bits: 1
    Handshake none selected (don't know if it's important or not)
    Open for: Write
    Apply setting when oppening
    Hex output and Hex input

    Then I do:
    Click "Open device"
    Click " Send file" and select file.ihx (Intel hex format file for 8051)
    Click "Ok"

    It seems to go OK. And I'm also using a switch to turn the circuit or to RUN or PROGRAM mode.

    After the flash I click "Close device" and then I turn the switch into RUN mode and it was supposed to see the LED's blinking but nothing happens!
     
  6. josip

    Member

    Mar 6, 2014
    63
    12
    Setting/calculating baud rate is related to FTDI/DS UART connection.

    How you know that program is downloaded correctly, any logs? Post your schematic here.
     
  7. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,398
    497
    I think there is something I am missing.

    Normally: PC serial port (DB-9?)--RS-232 to TTL chip--uC

    You have: PC USB--USB to RS-232 chip--RS-232 to TTL chip--uC
    Did I get that right?
     
  8. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3
    Well, I'm a bit confused right now a part from that it's the first time I'm doing such thing.

    Well this is what i have:

    [​IMG]
    [​IMG]

    My bridge between laptop and my circuit is this:

    Lc-tech


    My dmesg also says:

    Code (Text):
    1. [32208.125629] usb 3-1: new full-speed USB device number 13 using xhci_hcd
    2. [32208.254088] usb 3-1: New USB device found, idVendor=067b, idProduct=2303
    3. [32208.254096] usb 3-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
    4. [32208.254100] usb 3-1: Product: USB-Serial Controller
    5. [32208.254103] usb 3-1: Manufacturer: Prolific Technology Inc.
    6. [32208.254453] pl2303 3-1:1.0: pl2303 converter detected
    7. [32208.255060] usb 3-1: pl2303 converter now attached to ttyUSB0
    udevadm monitor shows this:

    Code (Text):
    1. KERNEL[32218.440924] add      /devices/pci0000:00/0000:00:14.0/usb3/3-1 (usb)
    2. KERNEL[32218.441075] add      /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0 (usb)
    3. KERNEL[32218.441576] add      /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/ttyUSB0 (usb-serial)
    4. KERNEL[32218.441662] add      /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/ttyUSB0/tty/ttyUSB0 (tty)
    5. UDEV  [32218.467776] add      /devices/pci0000:00/0000:00:14.0/usb3/3-1 (usb)
    6. UDEV  [32219.472157] add      /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0 (usb)
    7. UDEV  [32219.472810] add      /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/ttyUSB0 (usb-serial)
    8. UDEV  [32219.474784] add      /devices/pci0000:00/0000:00:14.0/usb3/3-1/3-1:1.0/ttyUSB0/tty/ttyUSB0 (tty)
     
    Last edited: Oct 5, 2014
  9. josip

    Member

    Mar 6, 2014
    63
    12
    Well, you are using PL2303 based USB/UART bridge. DS have low current on port pins, and it is not able to drive LED's directly. For this you need to put transistor between port pin and LED.

    Here you can see my flasher/target schematic, compatible with Maxim flashing software...

    [​IMG]

    Flasher hardware is build with SOIC chip's and placed inside the body of DB9 connector...

    [​IMG]

    Here is my flasher Win32 software in action...

    [​IMG]

    I didn't use Quartz that will give me requested baud rate for loader. I used PL2303HXD that support any baud rate, and made my own Win32 driver update for this.

    [​IMG]
     
    Last edited: Oct 6, 2014
    PsySc0rpi0n and absf like this.
  10. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3
    Mr. josip...

    I appreciate your reply.

    I'm sorry I'm not an expert on the subject. I'm just starting to learn the basics so I couldn't understand your point.

    You talked about low current in DS port pins. I don't know If you're referring to that transistor (2N222) that I have connected to pins PSEN and !EA/VPP (Collector), GND (Emitter) and to a switch (Base).

    If not, are you trying to say that I have to use a transistor for each lead to increase current? I'm using 2 rows of resistors of 4.7Kohms in a parallel setup! The LEDs light up when I feed the circuit with the regulated 5V.

    Anyway, I think my problem is communication between PC and the circuit. I just can't figure out what's wrong!
     
  11. josip

    Member

    Mar 6, 2014
    63
    12
    Yes, I was using standard 3mm green LED's with DS, and without transistor their light was not noticeable except in total dark room. It was 8 years ago, so maybe some modern bright LED's will work.

    I am not sure what are you doing, but DS89C450 loader use some commands for communication, and it is not enough just to send file by some standard terminal program.

    [​IMG]

    Or you can use Maxim Win32 software tools that are working for sure, or try some linux ds89c450 dedicated software tools like http://linux.softwareweb.com/ds89c450.htm
     
  12. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3
    I'm using (or trying to) minicom and cutecom... And I can't make the communication work. Also there is a cli command, "cu" the allows us to communicate with these kind of devices!

    I'll try to see that dsflash. I have already downloaded that application but didn't tried it out because of some problems in compiling it!

    I'll try again maybe later today!
     
  13. josip

    Member

    Mar 6, 2014
    63
    12
    Also, there is nothing wrong for using push button or something like this for manual selection between programming / running mode, for testing or flashing few times. But for normal use it is much simpler using automatic selection of programing / running mode by UART over SN74HC125 or similar that cost less than nothing.

    You are not using PL2303 USB / UART cable that have UART signal (not 5V logic) on output, but PL2303 board that have UART lines as 5V logic levels, so you can build flasher as on my schematic just by adding SN74HC125, without need for MAX233 or similar.
     
    PsySc0rpi0n likes this.
  14. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3

    I don't know If I fully understood your answer.

    Anyway, I'm answering according my tiny knowledge about the subject.

    I'll try to explain what is missing in that previous schematic I posted a few posts ago.

    I'm using a cell phone transformer to indirectly feed the circuit, meaning that the negative thread of the transformer is connected to the GND bus of the breadboard and the positive thread is connected to a small resistor and this resistor is connected to a 5V voltage regulator that ensures the 5V to the breadboard's positive bus.

    I'm also using this small device to make the bridge between my laptop and the circuit. I'm not using the 5V coming from the laptop USB plug, meaning that only TxD, RxD and GND from that small device are being used.

    You talked about a push button device to switch from RUN to PRG mode and vice-versa. Well, I'm using a switch because it was an offer from a friend of mine. The thread from that switch that connects to the breadboard's positive bus has also a resistor to help avoiding any unwanted situations.

    Hope you understand my explanation.
     
    Last edited: Oct 8, 2014
  15. josip

    Member

    Mar 6, 2014
    63
    12
    As you can see on picture, use DTR output line from your small bridge device for switching between PRG / RUN mode. It is easier to control PRG / RUN mode from laptop automatically. Just add sn74hc125 logic chip to your circuit.

    [​IMG]
     
  16. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3
    I don't have any SN74HC125 with me to add to the circuit. But you're saying that as my circuit is, it will not work???
     
  17. josip

    Member

    Mar 6, 2014
    63
    12
    It should work, at least programing. Detailed description is here... http://www.maximintegrated.com/en/app-notes/index.mvp/id/3262

    And there is Maxim MTK tool (linked at end of the page) for flashing under Win.
     
  18. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3
    Morning...

    I know about MTK but I'm under Linux, not Windows.

    I have already read that link but as my knowledge is very small I'm not sure how can I use that info...

    My problem, I think It's communicating with my serial/USB port under Linux!
     
  19. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3
    Ok, I finally got it working... (After I have destroyed one DS89C450).

    I was doing 2 mistakes.
    The RxD pin from uC connects to TxD pin of FTDI and TxD from uC connects to the RxD pin from FTDI. I was connecting RxD (uC) <--> RxD (FTDI) and TxD (uC) <--> TxD (FTDI)

    The other detail was harder to find. As I don't have any stable power source I have used a cell phone charger (~16V output) and a voltage regulator and a resistor and tried to match the 5V needed by the uC. The problem was that I think in the first attempts I might have let passed way over 5V and probably destroyed the uC. Another reason could have been the ground reference from the regulator that was not welded and sometimes it could not be making a solid contact with the voltage regulator middle pin.

    Anyway I have 2 DS89C450. It was my luck. Now I'm using another cell phone charger but with around 5V of output combined with a 5V regulator. So, now everything is working.
     
  20. PsySc0rpi0n

    Thread Starter Well-Known Member

    Mar 4, 2014
    1,184
    3
    Ok, now I'm using Assembly to perform a few actions in the uC.

    My next challenge is to write a small and simple code to make the uC react to 4 control signals.
    I have 8 LEDs connected to Port 1.

    Te challenge is:

    If P0.0 is "1", then all LEDs must turn ON and turn OFF
    If P0.1 is "1", then one LED must turn ON and rotate left (RL instruction in Assembly)
    If P0.2 is "1", then one LED must turn ON and rotate right (RR instruction in Assembly)
    If P0.3 is "1", then the 2 middle LEDs must turn ON and one rotates left and the other one rotates right, so 2 LEDs will be working.

    I have part of the code done and part of that part is working but the other part is not working.

    But for now I need help to build the code to P0.3.
    Any hits?
     
Loading...