0% found this document useful (0 votes)
50 views

Embedded Programming With Python: David Jones

The document discusses embedded programming with Python on an ATtiny25 microcontroller. It provides an overview of the hardware architecture, which includes the ATtiny25 communicating with a larger microcontroller via SPI. Typical serial output from the ATtiny25 is shown, with each character representing a bit transmitted or received. The document also includes an example Intel Hex file containing code (data) for the ATtiny25, and a Python function to analyze the hex file and determine the largest address used, indicating the size of the ROM image.

Uploaded by

Ayesha Banu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

Embedded Programming With Python: David Jones

The document discusses embedded programming with Python on an ATtiny25 microcontroller. It provides an overview of the hardware architecture, which includes the ATtiny25 communicating with a larger microcontroller via SPI. Typical serial output from the ATtiny25 is shown, with each character representing a bit transmitted or received. The document also includes an example Intel Hex file containing code (data) for the ATtiny25, and a Python function to analyze the hex file and determine the largest address used, indicating the size of the ROM image.

Uploaded by

Ayesha Banu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Embedded Programming

with Python
[email protected]

David Jones
Not actually
an ATtiny25
Hardware Architecture Overview

big proper
SPI
µ-controller
Comms
to meter reader
3

ATtiny

RS-232
0V 5V
Typical Serial Output
Processor has
been reset Buffering data
Data from big brother
initialised Beginning transmission
to meter reader

&@R02G0DR02G30..*xxXxXxxxxR02G31XxxxxxXXxxR02G30XxXxxxXH
hxHS01xhhhhXXxhHR02G31XhxhhhHXxxS01xhhhhXXxhHR02G31Xhxhh
hHXxxS01xhhhhXXxhHR02G31XhxhhhHXxxS01xhhhhXXxhHR02G31Xhx
hhhHXxxS01xhhhhXXxhHR02G31XxxxxxXXxxS01xhhhhXXxhHR02G31X
hxhhhHXxx

Each 'x', 'X', 'h', 'H' represents one bit transmitted 'S' and 'R' represent comms
and possibly one bit received with big brother microcontroller

Basically, a nightmare!
:10000000853AE81E7FF05DF27C805DEF2D7D9B2EB2 :10041000F4C50709F61666BC531A033CC49F7765FA
:100010000F8B70DF499252BE3223B25D24A163D5AB :1004200044CE52811F51749337F163D01FEC67C6DD
:10002000C16F6B2AA8C80A102A894983F96C075C3A :1004300030248E6C60E070D3AC86E9956398F161EE
:100030004B9FD2AF4019E89C2805A5AA2BFC1C8435 :10044000553C649BAF34F63135B37AF6236A610DBF
:1000400075B586F58F488C970C811455B869EC8C82 :10045000A2B2712F7D0A24B993B7AD54BF13BB7AF2

Enough code
:100050000D8616D472A9EAFEF6AC53902E90348128 :100460000C1807112775D9620F3147C0833CDB9BFD
:100060002390A8866D003159106847192C8B0B6FAF :10047000737DEB88AACBFA2C0851BD6733286CAE8C
:10007000FE56CFC2BE73791BAB5DFA48DD414E948C :1004800085F025F4AD4BC26EE3E58A2541EC0C09FD
:1000800087365E03985AE74E86BBDBA9F547458065 :100490004A4E06597C810577C0C322938FC7BF207F
:10009000BBF2B00F4B5E9FB6C64FC848ACE2D1036F
:1000A00061C25D7DC83182EB24C022D951F3C77291
:1000B0004C21ADF6394E0FDC8ABD9FD6655C7A02C5
:1004A0006B8B0C50960FE6D3F6D6DD887951D22FA0
:1004B000CC4646BDCA01C18E7C50E774F3DA69832D
:1004C0000E2B634D03C42DCE1AD43CD938EF5513EF
to fill
the ATtiny25
:1000C0009F0C796232AE91E3DE418B0B34AC137935 :1004D00049CD1CDBF0A6C7FC913CF7B1382A2B486C
:1000D0001C0B84EF0BA0710CF7CA2601785D9FA45E :1004E000B25E5361A214FF519D326AC31E9BB624B3
:1000E000E7A8FE649A4832A29D4D894627D6842807 :1004F0005CEAB67FDFA24B6B760D45B00ED38B3F27
:1000F0002B734989D516AA36957A80E81BB6161255 :1005000036E5C5E75E965BABB28168E0BA888800E5
:1001000039A32912B5E79ECA301ADCC495CA070381 :1005100073D4FD4DB4523014F2FFF62C5B30EB92E5
:1001100026CAA2DBF792DC671EF8269D1481B0B6D2 :100520003BC516A6BCDC8761342D6B93326AC700CD
:10012000F24C811A550622F9B4C2AD36CFCE1ED29A :10053000010E9E1C7297B311352B2DD995D5C899F4
:10013000801CD53F936D2F8F5912DD2ED2D130FB0D :1005400062EA2D654EB7C01EC6B54C2E3A26636AC8
:1001400047D8BBC695A474D6E4DA9104C5AFA01411 :100550005FFBF4FCA3A2F8895E7F0DAD45FAE1854F
:10015000A6FA935F821B85C747CDBE1FE5D7B50EB4 :10056000518D19360DC580A23320A907EB8CC384A9
:1001600065EA865391FBEF6393736B8E160D9AC409 :10057000A99E5F44A71CEF9A53B971382899AA0025
:10017000E7D75EA99519257B0F4BFE592B94A883D1 :10058000B00C1E1D9983F1AF3C70EEBE4C486AFF63
:100180002A9FA2B743E0C115FFCF8EAB556A3F153A :10059000E355A36F5CE4C878669ADCE7824FD5C662
:10019000C37A4F5D159F7FB2644EAD3097EDCF6748 :1005A000C8F55C6DAC5552B800B86D4C8009559ECD
:1001A000E15960BAB7B7CEF080C9052C633AA9E12E :1005B0006DB4391BB6B09F679D50DEB28EBF02E5A9
:1001B000FF71F4F61046FBE76D3401112DD0DABC67 :1005C000DE9A274DC6A0BD7E1941F5469C91C245D5
:1001C000D74C41DD729137CD45AACAB855CF172E0D :1005D0006AFCE49B6FC50043A0AAF7E6FEFB9858AF
:1001D0007963C89CBA875800C475DBC55F67D01BBC :1005E000DA8BDFE239ED12A2A9D1A788EB7E6FC4C6
:1001E0000A6051B5A7AC6C0F0C4574A6DE424510F1 :1005F0006E560FA7A7E51ED46EE0C1E47BBE0034A3
:1001F0006FE26F25275E9878F3AECD395131A3A118 :10060000D4DDCBDD09E36375D2131F7088F6BC9C83
:10020000F925DA8B9C7D585714F4FF924E1A165438 :1006100039C95C2EFA4133A5DCE27773B58D6D7F65
:100210002B0F81BB626126DE250BA32F2768BD262D :10062000CAB9670E4E39DDEA45AD1389F754118218
:100220006C01A3124C6CBA983ACC58803F4A55DE08 :10063000B8A64E9F278C13216CC5FD61BD244BC805
:1002300073EFB2C6D269D63D7929B1B084CB12F83A :100640006CE8A6B7D46C427848255686754AAC1437
:100240004FAAD704CEE6AE9C122354F3B15CF5A8B6 :10065000E717CD3286D128A090F5FF531E1409ADBF
:10025000984205F26447D4BC2BB01CCA1FC8631E69 :1006600048EDB0BA3D0E7739C4A107B5D4B646619E
:1002600084E884628E9B9AF02A11CF1513A010CFD8 :1006700022EE2362C47EA177AC3F67404F39EB3E48
:100270001C3494DA3DE46EA1C541D0763569BD7A6F :10068000A099C5A95F9E51CF0A915D19FA5DFC0240
:10028000B8FB30710CE54FB6655CC711AFB9B62F3E :10069000AFCA8A19F8148C8091A133406A6154A5BD
:10029000DD210EB24A786612FA4CA157C28721427C :1006A00079995F73090047E3E6C965DDB6B092C189
:1002A0006CC139912CF497C5A287D2D872E778B780 :1006B0009546DBC1AB9B1071108E0DE51F96301275
:1002B000912C304640D3BD348B4A273464EDF2BFD5 :1006C000800BDAF684FC98A0570BBC92AED1179D34
:1002C00095A6D6CF3B8236E904DABD14F6DF5B840F :1006D000BBA2FAABAB5F99EFD22018E463093126D5
:1002D00010CA65F78C2F846CB255D134F9E08F7158 :1006E000B8687B56D7799112450DDF6E67F9240BF8
:1002E000974507155B020C41D69F249DA91C4B9A8C :1006F000AEC41D1C0C2A77B17D83C89F318429B3F9
:1002F000255DF460679C60533BEB5B9E2671558ED9 :100700005026ED77F6EBC810BEEE841DA1C651CC85
:10030000E7571CAD7B64AAD152990718DDE4A3CA54 :100710000F4CA630E3B63574BE524586F0147426ED
:10031000058C3126D4EF0922CBE2DC55C4305F24B2 :100720004543613CE2AA6AD0BA9AA6192A03CC7959
:10032000F933A221A3050A84D5657BC2D427E0D77F :10073000104EF31240F2B75C2669E34FC5F7F7306D
:10033000724BE2AF00ECC20E8DA9D8623A2F20AD0D :1007400078909012E5A2D3DE76B19CA5EB502E7A7C
:10034000DAEFA0B37133F6F398576D4E9514CB27BF :100750003046B62A8C41334B8807845185EEF77DAD
:10035000939102008BC425DBA56193656BE4C6AF66 :10076000DD9C19E2FCE0BE125DF2F0510DF6900046
:100360002565837616957FF373E06C8BA733F59F35 :10077000C0E0A94BFCEC611257348644F6E5D4B6D0
:10037000ABF58B2BE8D0346FAD38D881A818BFCE41 :10078000C8555C34E0D99429A6AEAF67282B12BCBB
:10038000FF12464956DC7916984F6E451D0B72498F :1007900039D3DBD7388ACC1F09A27221A085B33B9D
:10039000EC9095E08B308620C9C3A292F1DE5C75AB :1007A000725056FBBFF86052143AA2556F2E2D4F6F
:1003A00099F66EB204256505BA3825A1445D3F1F54 :1007B0002E52F2018ACF6B340DA3AD969EA06FB777
:1003B000E323ECDF73E5F5245DBCD296AB09E88955 :1007C0008FB687D21529F5766712E3E7741A9A0374
:1003C00094FE1F48402D5B279FB1A0D4C3F77A8DC0 :1007D000DEF7004FDE24EC6818D5BB9861B42EFA22
:1003D000B2E023586FDF9DC0A1776DDE7122A4C704 :1007E000AC400CDDFA5525CE0785D9F2F62EF84837
:1003E000F6EBCFD584B077322E50B8044FFBC04423 :1007F0008C89C2719B3132B8B7DB3141FF73369BB4
:1003F0001CE5E6C5AD22B088D212E9D0CFA5E175E3 :00000001FF
:10040000E56AC87B5818C2B034A19F79932C29A9FA
Intel Hex File

:1000000096E2386064BE25C9C526E264329D4593F8
:10001000BEBF14CACDD2ED8D1C47C74B2F7177B12F
:100020002B7388389FCAAEEC0B3AFEA3E367955C4E
:10003000329337FB51CB9252CD9B644D054EC8FC99
:00000001FF

data (code)
Length of data

address offset checksum

record type
0: code
1: end-of-file
How big is the ROM image?
def hexan(f) :
highest = 0
for l in f :
length = l[1:3]
addr = l[3:7]
type = l[7:9]
if type == '00' :
addr = int(addr, 16)
length = int(length, 16)
addr += length - 1
highest = max(highest, addr)
print "Highest address used: %04x\n" % highest
Writing Hex Files in Python

# First we produce the record as a sequence of numbers so that


# we can checksum it, then we convert to hex strings.
length = len(l)
offset = [(a >> 8) & 0xff, a & 0xff] # big-endian
rectype = 0
data = map(ord, l)
r = [length] + offset + [rectype] + data
# CHECKSUM
checksum = sum(r)
checksum = (-checksum) & 0xff
r += [checksum]
# Convert to hex string.
r = map(lambda x: '%02X' % x, r)
r = ''.join(r)
Not Actually a Tektronix TDS4013B
Oscilloscope Output File
0000000 3a 57 46 4d 50 52 45 3a-42 59 54 5f 4e 52 20 32 :WFMPRE:BYT_NR 2
0000010 3b 42 49 54 5f 4e 52 20-31 36 3b 45 4e 43 44 47 ;BIT_NR 16;ENCDG
0000020 20 42 49 4e 3b 42 4e 5f-46 4d 54 20 52 49 3b 42 BIN;BN_FMT RI;B
0000030 59 54 5f 4f 52 20 4d 53-42 3b 4e 52 5f 50 54 20 YT_OR MSB;NR_PT
0000040 31 30 30 30 30 3b 57 46-49 44 20 22 43 68 33 2c 10000;WFID "Ch3,
0000050 20 44 43 20 63 6f 75 70-6c 69 6e 67 2c 20 35 2e DC coupling, 5.
0000060 30 45 30 20 56 2f 64 69-76 2c 20 34 2e 30 45 2d 0E0 V/div, 4.0E-
0000070 34 20 73 2f 64 69 76 2c-20 31 30 30 30 30 20 70 4 s/div, 10000 p
0000080 6f 69 6e 74 73 2c 20 50-6b 20 44 65 74 65 63 74 oints, Pk Detect
0000090 20 6d 6f 64 65 22 3b 50-54 5f 46 4d 54 20 45 4e mode";PT_FMT EN
00000a0 56 45 4c 4f 50 45 3b 58-49 4e 43 52 20 34 2e 30 VELOPE;XINCR 4.0
00000b0 45 2d 37 3b 50 54 5f 4f-46 46 20 30 3b 58 5a 45 E-7;PT_OFF 0;XZE
00000c0 52 4f 20 2d 31 2e 37 32-38 45 2d 33 3b 58 55 4e RO -1.728E-3;XUN
00000d0 49 54 20 22 73 22 3b 59-4d 55 4c 54 20 37 2e 38 IT "s";YMULT 7.8
00000e0 31 32 35 45 2d 34 3b 59-5a 45 52 4f 20 30 2e 30 125E-4;YZERO 0.0
00000f0 45 30 3b 59 4f 46 46 20-2d 31 2e 38 39 34 34 45 E0;YOFF -1.8944E
0000100 34 3b 59 55 4e 49 54 20-22 56 22 3b 3a 43 55 52 4;YUNIT "V";:CUR
0000110 56 45 20 23 35 32 30 30-30 30 cb 80 cf 80 cc 00 VE #520000......
0000120 cf 80 cc 80 cf 00 cc 80-cf 80 cc 80 d0 00 cb 80 ................
0000130 d0 00 cc 00 cf 80 cc 00-cf 00 cc 00 cf 80 cc 00 ................
0000140 cf 80 cc 80 cf 80 cc 80-d0 80 cc 80 ce 00 cc 00 ................
0000150 cf 00 cc 80 cf 80 cc 00-cf 00 cc 80 d0 00 cd 00 ................
0000160 d0 00 cd 00 cf 80 cd 00-d0 00 cb 80 d0 00 cc 00 ................
0000170 cf 80 cc 00 cf 00 cc 00-cf 00 cc 00 d0 00 cc 00 ................
0000180 ce 80 cc 80 cf 00 cc 00-cf 80 cc 00 cf 80 cc 00 ................
Slurping Oscilloscope Data in Python

s = f.read()
match = re.search(r':CURVE? ?#(\d)', s)
...
data = s[len(preamble):]
n = datalength // 2
wave = struct.unpack('>%dh' % n, data)

re rocks!
struct rocks!
Produced using Python

... and SVG


Not Actually What We Did

Nat Semi
IO card

USB

pySerial serial analysis, wxPython


ATtiny
RS-232 logging,
pySerial test generation

JTAG

Disk

You might also like