Skip to content

Commit f970f9e

Browse files
author
nofeletru
committed
Добавлено чтение id по опкоду 15h
1 parent 8e65a1d commit f970f9e

File tree

2 files changed

+50
-21
lines changed

2 files changed

+50
-21
lines changed

software/main.pas

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,32 +2565,31 @@ procedure TMainForm.ButtonBlockClick(Sender: TObject);
25652565
procedure TMainForm.ButtonReadIDClick(Sender: TObject);
25662566
var
25672567
XMLfile: TXMLDocument;
2568-
ID: array[0..2] of byte;
2569-
ID90H: array[0..1] of byte;
2570-
IDABH: byte;
2571-
IDstr: string[6];
2568+
ID: MEMORY_ID;
2569+
IDstr9FH: string[6];
25722570
IDstr90H: string[4];
25732571
IDstrABH: string[6];
2572+
IDstr15H: string[4];
25742573
begin
25752574
try
25762575
if not OpenDevice() then exit;
25772576
LockControl();
2578-
FillByte(ID, 3, $FF);
2579-
FillByte(ID90H, 2, $FF);
2580-
FillByte(IDABH, 1, $FF);
2577+
FillByte(ID.ID9FH, 3, $FF);
2578+
FillByte(ID.ID90H, 2, $FF);
2579+
FillByte(ID.IDABH, 1, $FF);
2580+
FillByte(ID.ID15H, 2, $FF);
25812581
if not SetSPISpeed(0) then exit;
25822582

25832583
EnterProgMode25(hUSBdev);
25842584
UsbAsp25_ReadID(hUSBDev, ID);
2585-
UsbAsp25_Read(hUSBDev, $90, 0, ID90H, 2);
2586-
UsbAsp25_Read(hUSBDev, $AB, 0, IDABH, 1);
25872585
ExitProgMode25(hUSBdev);
25882586

25892587
USB_Dev_Close(hUSBdev);
25902588

2591-
IDstr := Upcase(IntToHex(ID[0], 2)+IntToHex(ID[1], 2)+IntToHex(ID[2], 2));
2592-
IDstr90H := Upcase(IntToHex(ID90H[0], 2)+IntToHex(ID90H[1], 2));
2593-
IDstrABH := Upcase(IntToHex(IDABH, 2));
2589+
IDstr9FH := Upcase(IntToHex(ID.ID9FH[0], 2)+IntToHex(ID.ID9FH[1], 2)+IntToHex(ID.ID9FH[2], 2));
2590+
IDstr90H := Upcase(IntToHex(ID.ID90H[0], 2)+IntToHex(ID.ID90H[1], 2));
2591+
IDstrABH := Upcase(IntToHex(ID.IDABH, 2));
2592+
IDstr15H := Upcase(IntToHex(ID.ID15H[0], 2)+IntToHex(ID.ID15H[1], 2));
25942593

25952594
if FileExists('chiplist.xml') then
25962595
begin
@@ -2607,22 +2606,25 @@ procedure TMainForm.ButtonReadIDClick(Sender: TObject);
26072606
ChipSearchForm.ListBoxChips.Clear;
26082607
ChipSearchForm.EditSearch.Text:= '';
26092608

2610-
FindChip.FindChip(XMLfile, '', IDstr);
2609+
FindChip.FindChip(XMLfile, '', IDstr9FH);
26112610
if ChipSearchForm.ListBoxChips.Items.Capacity = 0 then FindChip.FindChip(XMLfile, '', IDstr90H);
26122611
if ChipSearchForm.ListBoxChips.Items.Capacity = 0 then FindChip.FindChip(XMLfile, '', IDstrABH);
2612+
if ChipSearchForm.ListBoxChips.Items.Capacity = 0 then FindChip.FindChip(XMLfile, '', IDstr15H);
26132613

26142614
if ChipSearchForm.ListBoxChips.Items.Capacity > 0 then
26152615
begin
26162616
ChipSearchForm.Show;
2617-
LogPrint('ID(9F): '+ IDstr);
2617+
LogPrint('ID(9F): '+ IDstr9FH);
26182618
LogPrint('ID(90): '+ IDstr90H);
26192619
LogPrint('ID(AB): '+ IDstrABH);
2620+
LogPrint('ID(15): '+ IDstr15H);
26202621
end
26212622
else
26222623
begin
2623-
LogPrint('ID(9F): '+ IDstr +STR_ID_UNKNOWN);
2624+
LogPrint('ID(9F): '+ IDstr9FH +STR_ID_UNKNOWN);
26242625
LogPrint('ID(90): '+ IDstr90H +STR_ID_UNKNOWN);
26252626
LogPrint('ID(AB): '+ IDstrABH +STR_ID_UNKNOWN);
2627+
LogPrint('ID(15): '+ IDstr15H +STR_ID_UNKNOWN);
26262628
end;
26272629

26282630
XMLfile.Free;

software/usbasp25.pas

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@ interface
3838
WT_PAGE = 0;
3939
WT_SSTB = 1;
4040
WT_SSTW = 2;
41+
type
4142

43+
MEMORY_ID = record
44+
ID9FH: array[0..2] of byte;
45+
ID90H: array[0..1] of byte;
46+
IDABH: byte;
47+
ID15H: array[0..1] of byte;
48+
end;
4249

4350
function UsbAsp25_Busy(devHandle: Pusb_dev_handle): boolean;
4451

@@ -50,7 +57,7 @@ function UsbAsp25_Read32bitAddr(devHandle: Pusb_dev_handle; Opcode: byte; Addr:
5057
function UsbAsp25_Write(devHandle: Pusb_dev_handle; Opcode: byte; Addr: longword; buffer: array of byte; bufflen: integer): integer;
5158
function UsbAsp25_Write32bitAddr(devHandle: Pusb_dev_handle; Opcode: byte; Addr: longword; buffer: array of byte; bufflen: integer): integer;
5259

53-
function UsbAsp25_ReadID(devHandle: Pusb_dev_handle; var ID: array of byte): integer;
60+
function UsbAsp25_ReadID(devHandle: Pusb_dev_handle; var ID: MEMORY_ID): integer;
5461

5562
function UsbAsp25_Wren(devHandle: Pusb_dev_handle): integer;
5663
function UsbAsp25_Wrdi(devHandle: Pusb_dev_handle): integer;
@@ -124,16 +131,36 @@ procedure ExitProgMode25(devHandle: Pusb_dev_handle);
124131
USBSendControlMessage(devHandle, USB2PC, USBASP_FUNC_DISCONNECT, 0, 0, 0, dummy);
125132
end;
126133

127-
//Читает 3 байта id
128-
function UsbAsp25_ReadID(devHandle: Pusb_dev_handle; var ID: array of byte): integer;
134+
//Читает id и заполняет структуру
135+
function UsbAsp25_ReadID(devHandle: Pusb_dev_handle; var ID: MEMORY_ID): integer;
129136
var
130-
buffer: array[0..2] of byte;
137+
buffer: array[0..3] of byte;
131138
begin
132-
FillByte(buffer, 3, $FF);
139+
//9F
133140
buffer[0] := $9F;
134141
USBSendControlMessage(devHandle, PC2USB, USBASP_FUNC_25_WRITE, 0, 0, 1, buffer);
142+
FillByte(buffer, 4, $FF);
135143
result := USBSendControlMessage(devHandle, USB2PC, USBASP_FUNC_25_READ, 1, 0, 3, buffer);
136-
move(buffer, ID, 3);
144+
move(buffer, ID.ID9FH, 3);
145+
//90
146+
FillByte(buffer, 4, 0);
147+
buffer[0] := $90;
148+
USBSendControlMessage(devHandle, PC2USB, USBASP_FUNC_25_WRITE, 0, 0, 4, buffer);
149+
result := USBSendControlMessage(devHandle, USB2PC, USBASP_FUNC_25_READ, 1, 0, 2, buffer);
150+
move(buffer, ID.ID90H, 2);
151+
//AB
152+
FillByte(buffer, 4, 0);
153+
buffer[0] := $AB;
154+
USBSendControlMessage(devHandle, PC2USB, USBASP_FUNC_25_WRITE, 0, 0, 4, buffer);
155+
result := USBSendControlMessage(devHandle, USB2PC, USBASP_FUNC_25_READ, 1, 0, 1, buffer);
156+
move(buffer, ID.IDABH, 1);
157+
//15
158+
buffer[0] := $AB;
159+
USBSendControlMessage(devHandle, PC2USB, USBASP_FUNC_25_WRITE, 0, 0, 1, buffer);
160+
FillByte(buffer, 4, $FF);
161+
result := USBSendControlMessage(devHandle, USB2PC, USBASP_FUNC_25_READ, 1, 0, 2, buffer);
162+
move(buffer, ID.ID15H, 2);
163+
137164
end;
138165

139166
//Возвращает сколько байт прочитали

0 commit comments

Comments
 (0)