Hi Gary,
I had a look at your code and have some news. First a hint: use the <<code>> <</code>>
construct to keep code readable on this page (check the editing tips).
This is what your LED_setup code looks like, original and with my proposed changes:
void LED_setup() {
//new
cs = 1; // deselect the device
LED_disp.format(16,0); // mode 0: Clk Low when inactive, Data valid on leading edge of Clk
LED_disp.frequency(100000); // spi freq 100kbit/s
#if(1)
//orig
AS1107(feature,0x03); // external clk, active reset
AS1107(shutdown,0x01); // normal mode, reset feature reg
AS1107(disptest,0x00); // normal mode
AS1107(decodemode,0xff); // decode mode for all digits
AS1107(intensity,0x0f); // max intensity
AS1107(scanlimit,0x07); // digit 0-7
AS1107(feature,0x09); // external clk, enable spi (no effect on 1107)
#else
//new
AS1107(feature,0x02); // activate reset, internal clk, code-B, no blink
AS1107(feature,0x00); // disable reset ?
AS1107(shutdown,0x01); // normal mode, reset feature reg
AS1107(disptest,0x00); // normal mode
AS1107(decodemode,0xff); // decode mode for all digits
AS1107(intensity,0x0f); // max intensity
AS1107(scanlimit,0x07); // digit 0-7
#endif
// blank all digits
for (int e=1; e<=8; e++) {
AS1107(e,0x0f);
}
}
Some comments:
You should set CS=1 as early as possible. mbed will set the level to 0 as soon as you define the pin as DigitalOut. I have added that as first instruction.
SPI init mode is OK. It should be 0. Clk Low when inactive, Data valid on leading edge of Clk
SPI clock is OK. 100kbit/s
Then we get to your original init code. You set bit0=1 in the feature reg. That means using external clk (in fact SPI clk). I would use the internal clock and set bit0=0.
It is not that clear from the datasheet how reset works. I would set the bit and then reset it. So write 0x02 and then 0x00 to the feature reg.
The remaining registers (shutdown, disptest,decodemode,intensity,scanlimit look good to me.
Blanking digits also looks OK.
You can switch to my init sequence by changing #if(1) to #if(0)
I have run your code and checked it on a logic analyser. See below
Higher res picture is here /media/uploads/wim/screenshot_spi.jpg
Timing and datacontent matches what we expect and looks good. There is an issue on the rising edge of CS. You inserted a 5us delay. The actual delay seems to be 0.5 us. That is due to the early return of the spi.write(). I think the actual transfer is not yet completed before the method returns. Anyhow, it still works. Detail in this pic:
Higher res picture is here /media/uploads/wim/screenshot_spi_cs.jpg
Try my code and see what happens.
There is one other possible explanation for the problems. I did a google search and there was a report that a compatible device from maxim enters a special testmode when the spi data, clk and CS pins are all '1' on power-on. That would happen with mbed also because all pins are inputs on poweron and float to '1'. The solution was to add a transistor switch that turns on the as1107 power under cpu control after you have initialised your spi pins to the correct levels.
Not a nice solution, lets hope you dont need it. Would be strange too since you reported that the 1107 might be working fine first and that the problem then happens when you reset mbed. At that time the 1107 would remain powered and should not enter a testmode.
Wim
Got it breadboarded and it works nicely most of the time. Everynow and again though, the display flakes out and will only display 1 digit or have 1 digit much brighter than the rest. If I reset the mbed once or twice it usually goes back to working well. I have found that it likes a sclk of 100,000. Anyone have any idea as to why I have this sort of intermittent failure. Is it interpin capacitance on the breadboard? Other ideas? I hate to move forward with the project not knowing exactly whats going on. Tnx all...