I'm interested in using SPI on a mini to drive a HL1606 RGB LED strip.
I'd appreciate any advice and/or example code.
HL1606 RGB LED strip driver
Started by ninoq, Jan 20 2012 01:26 AM
2 replies to this topic
#1
Posted 20 January 2012 - 01:26 AM
#2
Posted 20 January 2012 - 05:32 PM
Hi ninoq,
I looked for you, first hit I had was:
http://tuney.blogspo...ing-system.html
Hope it helps!
"Fact that I'm a moderator doesn't make me an expert in things." Stefan, the eternal newb!
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
My .NETMF projects: .NETMF Toolbox / Gadgeteer Light / Some PCB designs
#3
Posted 21 January 2012 - 04:06 AM
Thanks Stefan.
As it turns out I gave up may be too easily on trying to use the NMF SPI class because I wasn't sure how to access it to find out why it wasn't working in my application.
Instead I tried bit banging and got it to work almost straightaway - see code below.
What are the pros and cons of bit banging as opposed to using the NMF SPI class?
Is there a guide on how to access and customise the NMF firmware?
ninoq
//****************************************************************************************************************
private static void LEDStripper1(byte controlON, byte controlOFF, uint LEDIndxFirst, uint LEDIndxLast)
{
//Turns on LEDS in strip from LED[LEDIndxStart] to LED[LEDIndxEnd] incl.
//NB. assumes argument validity checked in calling routine and that all LEDS are off
//Warning: may not work with all strips - you may need to consult strip's data sheet and experiment.
//Arguments:
//controlON - control byte to turn on LED - refer to the LED strip's data sheet;
//controlOFF - control byte to turn off LED - refer to the LED strip's data sheet;
//LEDIndxFirst - index of first LED to be turned on; and
//LEDIndxLast - index of last LED to be turned on.
//GPIO pins:
//"mosi" - configured for output with intial state low - sends bits to strip;
//"spck"- configured for output with intial state low - clock pin; and
//"ss" - configured for output with intial state high - latch pin.
byte control;
//send "on/off" control bytes
for (uint j = LEDIndxLast; j > 0; j--)
{
if (j >= LEDIndxFirst)
control = controlON;
else
control = controlOFF;
ss.Write(false); //set latch low
//send control byte bits - MSB first
for (int i = 0; i < 8; i++)
{
mosi.Write((byte)(control & 0x80) == 0x80);//masks out and sends bit 7
spck.Write(true);//set clock pin high
spck.Write(false);//set clock pin low
control = (byte)((int)control << 1);//left shift 1 bit
Thread.Sleep(1);
}
}
ss.Write(true);//write data to strip
}
//******************************************************************************************************************
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users