flat assembler
Message board for the users of flat assembler.
Index
> Projects and Ideas > [resolved] software SPI master/ |
Author |
|
edfed 29 Jul 2012, 22:29
can you be more precise on the context (hardware config) of the run. cause here, the code (if PC compatible) just seems to use the io port 2 that is not really a port used as a receiver (port 002 = DMA Channel 1 address register), then, all you can get from this port is what you gave to it.
here, it seems that the initial value of port2 have the LSB still set (test 80h), and then, you send (at least) 80h to this port (or al,80h), and you get 80h from this port (in al,2). |
|||
29 Jul 2012, 22:29 |
|
delta67 30 Jul 2012, 07:25
edfed wrote: can you be more precise on the context (hardware config) of the run. cause here, the code (if PC compatible) just seems to use the io port 2 that is not really a port used as a receiver (port 002 = DMA Channel 1 address register), then, all you can get from this port is what you gave to it. Sorry, I should be more precise!! This code is for an 8088 SBC, wich have an 8255 on 00-03h. PORTC is configured like this: C0-C3 inputs, C4-C7 outputs. The SD is connected to this port (C) MISO ---> C0 CLK ---> C4 CS ---> C5 MOSI ----> C7 Thank u edfed |
|||
30 Jul 2012, 07:25 |
|
delta67 30 Jul 2012, 08:22
PROBLEM FIXED
I should shift AH befor reading MISO !!! initialy AH = FFh, If MISO is high when I increment AH then the result AH =00 But if I do "SHL AH, 1" befor reading MISO then If MISO is high incrementing AH sets BIT0 of AH. thus the wright code : Code: ;===================== ; subroutine to write one byte ;=========================== RD_SPI: mov ah,0xFF WR_SPI: ; byte to send is in AH mov bl,08h ; 8bits to send next: in al, 0x02 ; read portC test ah,0x80 ; MSBit 1 or 0?? jz A ; if MSBit =0 jmp to A or al, 0x80 ; MSBit =1 then Set C7 (MOSI) jmp B A: and al, 0x7F ; Clear C7 (MOSI) B: out 0x02,al ; write Mosi (must be on portC C7) shl ah,1 ; left shift 1 bit = Next bit to send ; we go read MISO befor sending pulse on CLCK !!! in al,0x02 ; MISO is connected on C0 TEST AL, 01H ; test C0: 0000 0001 jz MISO_L ; if MISO = 0 jump inc ah ; else MISO high then set D0 of AH : AH0=1 MISO_L: mov al,0x09 ; CLK is connected to C4: byte to send on command port ; to set C4 high is "0000 100 1" = 09 out 0x03,al ; set CLK HIGH dec al ; we decrement AL then AL = "0000 100 0" --> C4=0 out 0x03,al ; turn CLK LOW dec bl ; next bit jnz next ; if not last bit we continue sending bits ret ; return, read byte is in AH |
|||
30 Jul 2012, 08:22 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.