I am trying to set up control of several channels (currently aiming for 3 channels) of APA102 LEDs. The target Picaxe is 14M2. APA102 uses SPI and there are bit-banging macros and routines provided with PE6 (File/Open Samples/Basic/APA102/40X2/Example 6). They use these declarations:
I change C.3 to C.0 and C.5 to B.0 for the 14M2. (Incidentally, PIN_SCK isn't used anywhere.)
The subroutine that matters looks like this (corrected and a bit streamlined from the PE6 example):
I was hoping that a structure like this (only 1 channel shown here to keep it short) might work to allow the routine to be used across different channels :
But my reading suggests that the PIN_SDO part won't work as I want, although it compiles and runs in the simulator. I haven't tested it in hardware.
Will modifying each line of the subroutine like this do what I want?
I was hoping to save program space by using the original routine with variable pins but this method (if valid) would expand the code somewhat. I there a shorter way?
Code:
; Define the hardware pins
Symbol SCK = C.3 : Symbol PIN_SCK = pinC.3
Symbol SDO = C.5 : Symbol PIN_SDO = pinC.5
The subroutine that matters looks like this (corrected and a bit streamlined from the PE6 example):
Code:
Sendb0:
; This routine will output a byte of data from variable
; 'b0' over SPI using bit-banging
PIN_SDO = bit7 : pulsout SCK, 1
PIN_SDO = bit6 : pulsout SCK, 1
PIN_SDO = bit5 : pulsout SCK, 1
PIN_SDO = bit4 : pulsout SCK, 1
PIN_SDO = bit3 : pulsout SCK, 1
PIN_SDO = bit2 : pulsout SCK, 1
PIN_SDO = bit1 : pulsout SCK, 1
PIN_SDO = bit0 : pulsout SCK, 1
return
I was hoping that a structure like this (only 1 channel shown here to keep it short) might work to allow the routine to be used across different channels :
Code:
; Define the hardware pins for channel 1
Symbol SCK1 = C.0 : Symbol PIN_SCK1 = pinC.0
Symbol SDO1 = B.5 : Symbol PIN_SDO1 = pinB.5
symbol PIN_SCK = b8
symbol PIN_SDO = b7
symbol SCK = b6
symbol SDO = b5
...
;Send b0 to Channel 1
PIN_SCK = PIN_SCK1
PIN_SDO = PIN_SDO1
SCK = SCK1
SDO = SDO1
Gosub Sendb0
...
But my reading suggests that the PIN_SDO part won't work as I want, although it compiles and runs in the simulator. I haven't tested it in hardware.
Will modifying each line of the subroutine like this do what I want?
Code:
IF bit7=1 THEN
high SDO
ELSE
low SDO
ENDIF
pulsout SCK, 1
I was hoping to save program space by using the original routine with variable pins but this method (if valid) would expand the code somewhat. I there a shorter way?
