SLED-C4 converting BASIC to SPIN
pgbpsu
Posts: 460
I'm trying to use an SLED-C4 from Reynolds Electronics to display temperature. I've got my temp code working, but I can't get the display to respond. This 4 digit, 7-segment display is very simple. It only has 5 pins and I'm only using 4 of those. It takes serial data as input. Despite my best efforts I'm not getting the display to do anything. It turns on and all the segments are lit: 8888. I can't change any of them.
I'm giving it +5V power from the demo board. I'm running my serial line into an ST M74HCT04B1 (www.st.com/stonline/books/pdf/docs/2099.pdf) which I'm simply using to lift my serial data from 3.3 to 5V. This is an inverter chip but by running my serial line into this chip, feeding that output back into the inverter, I end up with my serial data stretched to 5V. I'm pretty sure my trouble isn't with this part of the circuit. When I scope the serial line coming from the Prop and the serial line just before going into the SLED they are identical save the voltage.
So I'm left to believe that the trouble is with my code. Since this is a serial device it can't be that difficult. The datasheet for the display (www.rentron.com/SLED/SLED-C4.pdf) has example code for BASIC. Sure doesn't look that difficult, but I was hoping someone who knows BASIC and SPIN could tell me what the differences are between the example code:
And my code:
I realize that I'm not displaying an increasing number like the BASIC code does. I'll be happy to get 1234 out of this thing! I'm also not clearing the display when done. As a check of what I'm outputting from the Prop I've setup PropTerminal. I've attached a picture of that output.
I've setup the SLED with PIN 3 (BAUD) tied to GND which should set the baud rate to 19,200. I'm not monitoring the AUX pin but I don't see how that can be required by this simple test of the display. When powering up the unit I get "8888" and it never changes. I should add that the datasheet specifies:
According to my scope I'm idling high. Any suggestions.
Thanks in advance,
pgb
I'm giving it +5V power from the demo board. I'm running my serial line into an ST M74HCT04B1 (www.st.com/stonline/books/pdf/docs/2099.pdf) which I'm simply using to lift my serial data from 3.3 to 5V. This is an inverter chip but by running my serial line into this chip, feeding that output back into the inverter, I end up with my serial data stretched to 5V. I'm pretty sure my trouble isn't with this part of the circuit. When I scope the serial line coming from the Prop and the serial line just before going into the SLED they are identical save the voltage.
So I'm left to believe that the trouble is with my code. Since this is a serial device it can't be that difficult. The datasheet for the display (www.rentron.com/SLED/SLED-C4.pdf) has example code for BASIC. Sure doesn't look that difficult, but I was hoping someone who knows BASIC and SPIN could tell me what the differences are between the example code:
Below is a BASIC example. CountIt: ' 4-digit counter from 0 to 1000 using "D"ecimal mode FOR Counter = 0 TO 1000 ' left digit right digit DEBUG "D", Counter DIG 3, Counter DIG 2, Counter DIG 1, Counter DIG 0 PAUSE 20 NEXT Counter PAUSE 500 DEBUG "C","~" ' Clear display D mode offers the least amount of flexibility, but simplifies host side firmware for simple counter applications as shown above, where custom characters or animations are not necessary. Note that D mode expects to receive decimal digits 0 through 9. Any value greater than 9 decimal will clear the display digit position it is in. In the above example, D mode will not provide automatic leading zero blanking. The display will show a count of 0000 through to 1000.
And my code:
{ ******************************************** Test of SLED-4 Display ******************************************** Simple test of the SLED-4 7-segment display from Reynolds Electronics www.rentron.com PGB 28 Aug 2008 } CON _clkmode = xtal1 + pll16x _xinfreq = 5_000_000 '*************************************** ' Pin Assignments '*************************************** SLED = 2 ' Serial line to SLED OBJ term : "PC_Interface" debug : "FullDuplexSerial" 'Send data to serial display VAR long cx, cy, ch long mx,my,mxo,myo PUB Main term.start(31,30) 'start the PropTerminal interface debug.Start(1,SLED,%0000,19200) '(rx,tx,mode,baud) Add SLED port pauseMsec(3000) ' wait repeat 1000 debug.hex($44,2) debug.dec(1) debug.dec(2) debug.dec(3) debug.dec(4) term.hex($44,2) term.dec(1) term.dec(2) term.dec(3) term.dec(4) pauseMsec(300) ' wait 1 second before next reading PRI pauseMSec(DelayMS) '' Pause execution in milliseconds. '' Duration = number of milliseconds to delay waitcnt(clkfreq / 1000 * DelayMS + cnt) ' Wait for DelayMS cycles
I realize that I'm not displaying an increasing number like the BASIC code does. I'll be happy to get 1234 out of this thing! I'm also not clearing the display when done. As a check of what I'm outputting from the Prop I've setup PropTerminal. I've attached a picture of that output.
I've setup the SLED with PIN 3 (BAUD) tied to GND which should set the baud rate to 19,200. I'm not monitoring the AUX pin but I don't see how that can be required by this simple test of the display. When powering up the unit I get "8888" and it never changes. I should add that the datasheet specifies:
SLED said...
Display Operation
A single I/O-pin on the host controller is all that’s required to control the SLED-C4 display. Serial data should be
sent from the host controller to the SLED-C4 display in standard non-inverted N, 8, 1 format, LSB first. During
idle or non-transmit periods, the host controller serial output pin should idle at Vcc or logic 1.
According to my scope I'm idling high. Any suggestions.
Thanks in advance,
pgb
tiff
27K
Comments
That's not something I'd considered. I added this just before I start looping over the write "1234" loop:
But it hasn't made any difference. Still "8888" at what appears to be max brightness. Any other suggestions....
Thanks,
pgb
debug.Start(1,SLED,%0000,19200)
to
debug.Start(1,SLED,%0011,19200)
which will invert the tx and rx
The 7404 is an inverter but I'm putting the output from the prop into the inverter, taking that output and putting it back into the inverter, taking that output and sending
that into the SLED. I tried what you suggested and it didn't work. Although this makes sense. Because of the way my circuit is laid out- going through the inverter 2x- the idle
state is now low, which is not what the SLED wants. I could remove one stage of the inverting process and use the change you suggested.
I'm pretty sure the form of the serial input to the SLED (+5V, idle high) is correct. I'm not sure what bits precede and follow a debug.tx($AA) so I'm not sure I'm getting the
correct bit pattern out of the prop. It looks like the FullDuplexSerial object shifts things to the right
which would be LSBit first correct?
Thanks,
pgb
Looking at the Sled spec it seems to say you need to send "~" to have the device execute the last command. I can see you do that in the basic code but not in the spin code.
You could try adding debug.tx("~" after output the 1,2,3,4.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
try this:
and define the counter variable in the var section.
the hex and dec methods of PC_Interface and FulDuplexSerial sends a String representation of the number,
but you need single characters for the 4 digits of the counter value.
I interpret the description so, that the display needs the values 0..9 ("decimal digits 0 through 9"), but it can also be that
it needs the ASCII values 0..9, then add $30 to it, like in the term code above.
Andy
Thanks for your posts. I won't be able to try this out until I get back to the lab on Monday, but I'm quite sure that the code I posted doesn't do anything to the display. It simply displays 8888 as it has done since turning it on. I'll try what you and Ariba have described.
I hope my problem is that I'm not sending the correct representation of the numbers I want. That will be the easiest to solve. I should have thought of this, but when I read decimal "0...9" I assumed ascii but sending %0000_0001 - %0000_1001 is well worth a try.
Thank you both very much.
Peter
Your code worked perfectly. Thanks! I now know how to deal with the rest of the commands. It was a problem of using debug.hex. I should have thought of this,
but for some reason it didn't occur to me.
Thanks to everyone who posted.
Peter