Oliver Broad
/
MIC5821
Control of MIC5821 octal driver using a SPI port (port1) and I/O pin (p21)
main.cpp@0:986765bd4f9e, 2012-07-08 (annotated)
- Committer:
- oliverb
- Date:
- Sun Jul 08 18:51:51 2012 +0000
- Revision:
- 0:986765bd4f9e
Tested
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
oliverb | 0:986765bd4f9e | 1 | #include "mbed.h" |
oliverb | 0:986765bd4f9e | 2 | // Use SPI port to write an 8 bit pattern to MIC5821 open collector driver device. |
oliverb | 0:986765bd4f9e | 3 | // MBED led1 lights if pattern read back from MIC5821 matches pattern written |
oliverb | 0:986765bd4f9e | 4 | // Ordinarily the device would be write-only but loopback may be usefull in testing. |
oliverb | 0:986765bd4f9e | 5 | // Cascade output is NOT tristate. Strobe is NOT a CS/SS signal, needs a pulse. |
oliverb | 0:986765bd4f9e | 6 | // |
oliverb | 0:986765bd4f9e | 7 | // Note that the MIC has a speed limit, 3.3MHz at 5v, mine works OK at 1MHz at 3.3v |
oliverb | 0:986765bd4f9e | 8 | // Also input has CMOS thresholds so it may not recognise MBED logic HI when powered |
oliverb | 0:986765bd4f9e | 9 | // from 5v so power it from Vout. |
oliverb | 0:986765bd4f9e | 10 | // |
oliverb | 0:986765bd4f9e | 11 | // Data is clocked in on rising edges so SPI 0,0 or SPI 1,1. |
oliverb | 0:986765bd4f9e | 12 | |
oliverb | 0:986765bd4f9e | 13 | SPI spi(p5, p6, p7); // mosi, miso, sclk |
oliverb | 0:986765bd4f9e | 14 | |
oliverb | 0:986765bd4f9e | 15 | DigitalOut strobe(p21); |
oliverb | 0:986765bd4f9e | 16 | DigitalOut led(LED1); |
oliverb | 0:986765bd4f9e | 17 | |
oliverb | 0:986765bd4f9e | 18 | int main() { |
oliverb | 0:986765bd4f9e | 19 | spi.format(8,0); |
oliverb | 0:986765bd4f9e | 20 | spi.frequency(1000000); |
oliverb | 0:986765bd4f9e | 21 | char leds,prev; |
oliverb | 0:986765bd4f9e | 22 | leds=0; |
oliverb | 0:986765bd4f9e | 23 | while(1) { |
oliverb | 0:986765bd4f9e | 24 | prev=spi.write(leds)+1; |
oliverb | 0:986765bd4f9e | 25 | led=(prev == leds); |
oliverb | 0:986765bd4f9e | 26 | leds++; |
oliverb | 0:986765bd4f9e | 27 | strobe=1; |
oliverb | 0:986765bd4f9e | 28 | wait_us(1); |
oliverb | 0:986765bd4f9e | 29 | strobe=0; |
oliverb | 0:986765bd4f9e | 30 | wait(0.5); |
oliverb | 0:986765bd4f9e | 31 | } |
oliverb | 0:986765bd4f9e | 32 | } |