Hi E,hi,
Post a sample of the Function call + args
and the Function itself.
I will edit it.
E
Hi E,hi C,
I don't really want the full program, just a clip of a typical function.
E
Hi E,hi,
You where asking about CS select in Functions calls, procedures.
Just post a clip of a Function and its Calling args.
E
EDIT: If [ chip_sel = altmtr_cs ] is a ligitimate statement, then I could write a PROCEDURE to select [ chip_sel = altmtr_cs or chip_sel = cmpss_cs or chip_sel = 4431_cs ] and select each as the sequence procedes, and use chip_sel as one of the AGRs. Does this seem ok?
Hi E,hi C,
Your understanding of the Function is way off track.
Note: these HEX values are for explaining the Function, use the actual HEX addr
periph_wr( 0x74 As Byte, 0x5f As Byte, altmtr_cs As Byte) ' you must the actual addr for altmtr_cs
Function periph_wr(arg1 As Byte, arg2 As Byte, arg3 As Byte) As Byte ' nothing returned
altmtr_cs = 0
chip_sel = 0
WaitUs 1
SSPBUF =arg1 ' write addr
While Not SSPSTAT.BF
Wend
WaitUs 1
SSPBUF = arg2 'wr_byte
While Not SSPSTAT.BF
Wend
altmtr_cs = 1
End Function
Hi E,hi,
Give a sample of the actual value of a CS, say for the compass,, which pin of the PIC is the CD output.
E
For this example post the addr of the compass
Hi E,hi,
I will look it over later.
I am running some tests on this Function command, the results I get are not consistent.?
E
Hi E,hi,
I am just dealing with basic code.
Usually a Function Returns a data value to the calling routine and a Proc does not Return any data.
In OSH it appears to be the wrong way around!
A Func does not return but a Proc does, yet the coding is shown as
Code line:
Function writeit(arg1 As Byte, arg2 As Byte, arg3 As Byte) As Word which indicates a WORD is returned.
Code line:
Proc proctest(arg1 As Byte, arg2 As Byte) ' no reference is given for the returned value!
Run this simple demo program to show this problem, I am not surprised you are having difficulty in getting the code right.
E
Hi J,You don't need a separate variable chip_sel.
Chip select can be done outside of the functions.
Also the values of the arguments can be written directly to the function.
For example:
wr_adr = 0x60 'WRITE 0xE0 %01100000 RESET ADDR [Is this needed?]
wr_byte = 0xb6 '%10110110 resets BMP280 = 0x00
chip_sel = altmtr_cs
Call periph_wr(wr_adr, wr_byte)
rd_adr = 0xd0 'address of ID =0x58 =88
rd_Byte = 0 'Dummy BYTE
data = periph_rd(rd_adr)
--->
altmtr_cs=0
Call periph_wr(0x60,0xb6)
Waitms 50
data = periph_rd(0xe0)
altmtr_cs=1
Hserout "READ RST 0 ", #data, Cr
etc....
loop: ''' NOTE this a READ function
Select perf1
read_any_perf(addr0, addr1) 'say comp addr
deselect perf1
'do whatever
Select perf2
read_any_perf(addr0, addr1) 'say baro addr
deselect perf2
'do whatever
Select perf3
read_any_perf(addr0, addr1) 'say some other perf
deselect perf3
'do whatever
End
'note this a Read Function
Function Read_any_perf(arg1 As Byte, arg2 As Byte) As Byte
'say read the SPI data for example
End Function
Function square(arg1 As Word) As Word
b = arg1 * arg1
square = b
Hserout "Inside Square Function b = ", #b, CrLf
End Function
by Aaron Carman
by Jake Hertz
by Duane Benson
by Jake Hertz