MAX6675 Assembly code
I am trying to interface with a MAX6675 Thermocouple chip and having some issues. The spin code works fine, but when I try to translate it over to assembly it won't work... (I would normally just keep it in spin, but there is some other tasks I would like to do in assy during the pause between samples). I spent way too much time beating my head against the wall, and I am assuming it is some stupid mistake I made. Thanks in advance for you help.
CON
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
TC1_OUT = 14
TC2_OUT = 15
TC_CS = 16
TC_SCK = 17
OBJ
Debug : "FullDuplexSerial"
VAR
Long cog
Long Pins
Long Temperature
Long Stack[noparse][[/noparse]300]
PUB Main
Debug.start(31, 30, 0, 57600)
Start(TC1_OUT, TC2_OUT, TC_CS, TC_SCK)
'cognew(Thermocouple, @Stack)
'waitcnt(clkfreq + cnt)
repeat
'Debug.dec(Temperature >> 3)
'Debug.tx(".")
'Debug.dec(((Temperature >> 1) & %11)*25)
Debug.bin(Temperature[noparse][[/noparse]0], 16)
Debug.tx(13)
waitcnt(clkfreq/2 + cnt)
PUB Thermocouple | a, conv
outA[noparse][[/noparse]TC_CS] := 1
outA[noparse][[/noparse]TC_SCK] := 1
dirA[noparse][[/noparse]TC1_OUT]~
dirA[noparse][[/noparse]TC_CS]~~
dirA[noparse][[/noparse]TC_SCK]~~
repeat
outA[noparse][[/noparse]TC_CS] := 0
conv := 0
repeat a FROM 13 To 0
outA[noparse][[/noparse]TC_SCK] := 0
conv += inA[noparse][[/noparse]TC1_OUT] << a
outA[noparse][[/noparse]TC_SCK] := 1
'Don't care about remaining two bits
outA[noparse][[/noparse]TC_CS] := 1
Temperature[noparse][[/noparse]0] := conv
waitcnt(clkfreq/2 + cnt)
PUB Start(T1_OUT, T2_OUT, T_CS, T_SCK)
Pins[noparse][[/noparse]0] := T1_OUT
Pins := T2_OUT
Pins := T_CS
Pins := T_SCK
cog := cognew(@entry, @Temperature) + 1
DAT
org
entry mov tmp1, par 'get Temperature 1 result pointer
mov tmp3, tmp1
or outa, CS_mask 'set CS to high
or outa, SCK_mask 'set SCK to high
andn dira, T1_mask 'set T1 to inputs
or dira, CS_mask 'set CS and SCK to outputs
or dira, SCK_mask
mov wait, cnt
add wait, hundredclk
mov t1scratchpad, #0
mov bitpos, #14
conversion andn outa, CS_mask 'set CS to low
waitcnt wait, hundredclk
mov bitpos, #16
:loop andn outa, SCK_mask 'set SCK to low
waitcnt wait, hundredclk
test T1_mask, ina wc 'grab bit for T1
rcl t1scratchpad, #1
or outa, SCK_mask 'set SCK to high
waitcnt wait, hundredclk
djnz bitpos, #:loop
wrlong t1scratchpad, tmp3
waitcnt wait, hundredclk
or outa, CS_mask 'set CS to high
waitcnt wait, startconv
jmp #conversion
startconv long 20_000_000 'quarter second to start conversion
hundredclk long 10000
T1_mask long |< 14
T2_mask long |< 15
CS_mask long |< 16
SCK_mask long |< 17
tmp1 res 1 'main pointer
tmp2 res 1 'temp pointer
tmp3 res 1 'pointer for temperature 1 result
tmp4 res 1 'pointer for temperature 2 result
t1scratchpad res 1
bitpos res 1
wait res 1
fit

Comments
Needs to be after the conversion label so it is reset before being filled up with your 16 bits, otherwise you end up with 32 bits of random stuff.
I also could not see the error so I just set bit 14 high and looked at what it returned, it was FFFFFFFF which suggested the problem.
Graham
DAT org entry mov tmp1, par 'get Temperature 1 result pointer mov tmp3, tmp1 or outa, CS_mask 'set CS to high or outa, SCK_mask 'set SCK to high or dira, CS_mask 'set CS and SCK to outputs or dira, SCK_mask mov overallwait, cnt add overallwait, fifthsec conversion mov wait, cnt add wait, hundredclk mov t1scratchpad, #0 andn outa, CS_mask 'set CS to low waitcnt wait, hundredclk mov bitpos, #14 :loop andn outa, SCK_mask 'set SCK to low waitcnt wait, hundredclk test T1_mask, ina wc 'grab bit for T1 rcl t1scratchpad, #1 or outa, SCK_mask 'set SCK to high waitcnt wait, hundredclk djnz bitpos, #:loop wrlong t1scratchpad, tmp3 or outa, CS_mask 'set CS to high waitcnt overallwait, fifthsec jmp #conversion fifthsec long 20_000_000 'quarter second to start conversion hundredclk long 100 T1_mask long |< 14 T2_mask long |< 15 CS_mask long |< 16 SCK_mask long |< 17 tmp1 res 1 'main pointer tmp2 res 1 'pointer for temperature 1 result tmp3 res 1 'pointer for temperature 2 result tmp4 res 1 'pointer for RPM1 result tmp5 res 1 'pointer for RPM1 result t1scratchpad res 1 bitpos res 1 wait res 1 overallwait res 1 fit