Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Python script for loading hex to DS89C430/440/450 (LINUX)

Few days ago I was just trying to familiarize an 89C430 microcontroller. I am using SDCC in linux. Then I feel the process of hex loading (ISP) a bit difficult since I need to type the commands and send the hex file using a terminal emulator. Then I wrote a small python script (pyserial based) for the purpose. It requires the file name of the hex as command line argument and the remaining the script will do...
PHP:
import serial,time,sys,os
os.system("clear")
if not sys.argv[1:]:
    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)
ser = serial.Serial("/dev/ttyUSB0",57600)
ser.timeout = 0.3
try:
    ser.open()
    ser.setDTR(1)
except Exception,e:
    print "error open serial port: " + str(e)
    exit()
if ser.isOpen():
    try:
        ser.flushInput()
        ser.flushOutput()
        ser.write("\x0D")
        time.sleep(0.1)
        recbuffer = ser.read(80)
        list = recbuffer.split(" ")
        if 'LOADER' in recbuffer:
            print "CONNECTED TO LOADER SUCCESSFULLY"
            print recbuffer
        else:
            print "CONNECTION ERROR"
            ser.setDTR(0)
            ser.close()
            sys.exit(0)
        ser.write("K\x0D")
        time.sleep(0.1)
        ser.write("L\x0D")
        f=open(sys.argv[1],"rU")      
        hexcontent = f.read()
        f.close()
        ser.write(hexcontent+"\x0D")
        k = ser.read(200)
        print k
        ser.setDTR(0)
        ser.close()
    except Exception, e1:
        print "error communicating...: " + str(e1)
else:
    print "cannot open serial port "

3262Fig01.gif

Comments

There are no comments to display.

Part and Inventory Search

Blog entry information

Author
vinodstanur
Read time
1 min read
Views
518
Last update

More entries in Uncategorized

More entries from vinodstanur

Share this entry

Back
Top