SPI on 14M2

GrahamGo

Senior Member
I am trying to use the 14M2 with SPI. I read that I have to substitute some code. Question. Is the standard HSpiout MSB of LSB first? I would like to know if there are any compiler directives available so that I can retain the same name and format as the X2 ie. HspiOut ( xx ). ie. - How does the compiler handle / put this value? ( xx )

If not, then does this mean I have to use both a different name and layout? ie. at the bottom here I have made an attempt. Am I even close?

Sorry to post yet another question. But I have a deadline in three days. A simple enough project but I didnt quite expect the uphill battle of grasping some details. But apart from my initial startup problems, this is a fantastic concept, and I can see myself sticking with it.


;---------------------------------------------------------

For X2 series

HSpiOut ( $7F )

;---------------------------------------------------------

For M2 series - substitute


‘***** Sample symbol definitions *****
symbol sclk = 5 ; clock (output pin)
symbol sdata = 7 ; data (output pin for shiftout)
symbol serdata = input7 ; data (input pin for shiftin, note input7)
symbol counter = b7 ; variable used during loop
symbol mask = w4 ; bit masking variable
symbol var_in = w5 ; data variable used durig shiftin
symbol var_out = w6 ; data variable used during shiftout
symbol bits = 8 ; number of bits
symbol MSBvalue = 128 ; MSBvalue =128 for 8 bits, 512 for 10 bits, 2048 for 12 bits)

‘ ***** Shiftout MSB first *****
shiftout_MSBFirst:
for counter = 1 to bits ‘ number of bits
mask = var_out & MSBValue ‘ mask MSB
high sdata ‘ data high
if mask = 0 then skipMSB
low sdata ‘ data low
skipMSB: pulsout sclk,1 ‘ pulse clock for 10us
var_out = var_out * 2 ‘ shift variable left for MSB
next counter
return
;----------------------------------------------------------

My best guess.

MyHSpiOut:
var_out = $7F : gosub shiftout_MSBFirst
return
 
Last edited:

SAborn

Senior Member
symbol sclk = 5 ; clock (output pin)
symbol sdata = 7 ; data (output pin for shiftout)
symbol serdata = input7 ; data (input pin for shiftin, note input7)
With the M2 range you should use the correct pin labels and not just 5 as on the 14m2 it would be B.5 and as for "7" there is no 7 from what i remember, check the data sheet for pinout numbering for the 14m2 (print it off) just picking numbers wont work, and there is no use looking at functions for the X2 range when working with the M2 range.

Its like reading a motorbike manual when working on a car, not a lot of use.

Use the right infromation for the chip you have or change chips to suit your needs.
 

GrahamGo

Senior Member
Yes I have got the basic shiftout_MSBFirst etc connected and used some different pins. I have used compilers before where you could say "substitute this procedure definition" with "this one" (I don't remember the technical expression - sort of like a macro). But I have no idea how to handle the brackets and values ie. the ( xx ) above. That's why I made the best guess above.

I will get there, but you know how it usually goes. Someone pips in - do it this way its simple......
 

SAborn

Senior Member
I must admit i too found the examples in the manuals rather poor from a beginners point of view and lacked a lot of detail (ok while you have someone to ask who understands)
Although every time it is brought up, there is always more who find the examples very clear than those who speak up from a beginner point of view, i must admit the manuals are clear once you understand the instruction, but up to that point the examples are lacking many finer details.

To me a manual, you should be able to look up MSB and get an answer and not need to filter through a list of instructions to find a little line quoting what you need to know.

Westys away at the moment or he would quote the phrase and line in the manual you need, but the rest of us dont always know the manual back to front and front to back with every line in memory as well as we should.
 
Top