bosko lekovic
/
IO_spi
IO spi
temp/IOgpiospi.cpp@7:4aa3dac73b66, 2021-03-21 (annotated)
- Committer:
- bosko001
- Date:
- Sun Mar 21 18:20:15 2021 +0100
- Revision:
- 7:4aa3dac73b66
novi pocetak
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bosko001 | 7:4aa3dac73b66 | 1 | #include "IOgpiospi.h" |
bosko001 | 7:4aa3dac73b66 | 2 | |
bosko001 | 7:4aa3dac73b66 | 3 | #include "Pinovi.h" |
bosko001 | 7:4aa3dac73b66 | 4 | /*************************************************************************************************************************************** */ |
bosko001 | 7:4aa3dac73b66 | 5 | // mosi = PTD6, miso = PTD7, clock = PTD5 |
bosko001 | 7:4aa3dac73b66 | 6 | |
bosko001 | 7:4aa3dac73b66 | 7 | |
bosko001 | 7:4aa3dac73b66 | 8 | |
bosko001 | 7:4aa3dac73b66 | 9 | C_gpioSpi::C_gpioSpi( /*PinName Mosi, PinName Miso, PinName spiClock*/) |
bosko001 | 7:4aa3dac73b66 | 10 | { |
bosko001 | 7:4aa3dac73b66 | 11 | p_MOSI = new DigitalIn( Mosi, PullUp); |
bosko001 | 7:4aa3dac73b66 | 12 | p_MISO = new DigitalOut( Miso, 1); |
bosko001 | 7:4aa3dac73b66 | 13 | p_SpiClock = new InterruptIn( SpiClock, PullUp); |
bosko001 | 7:4aa3dac73b66 | 14 | |
bosko001 | 7:4aa3dac73b66 | 15 | |
bosko001 | 7:4aa3dac73b66 | 16 | |
bosko001 | 7:4aa3dac73b66 | 17 | bitCount = 0; |
bosko001 | 7:4aa3dac73b66 | 18 | p_SpiClock->fall( [this](){ spiClockCount_fun(); } ); |
bosko001 | 7:4aa3dac73b66 | 19 | } |
bosko001 | 7:4aa3dac73b66 | 20 | |
bosko001 | 7:4aa3dac73b66 | 21 | void C_gpioSpi::spi_monitor( void ) |
bosko001 | 7:4aa3dac73b66 | 22 | { |
bosko001 | 7:4aa3dac73b66 | 23 | static char old_bit=0; |
bosko001 | 7:4aa3dac73b66 | 24 | if( old_bit && bitCount && (old_bit == bitCount) ) { bitCount=0;} |
bosko001 | 7:4aa3dac73b66 | 25 | old_bit = bitCount; |
bosko001 | 7:4aa3dac73b66 | 26 | |
bosko001 | 7:4aa3dac73b66 | 27 | } |
bosko001 | 7:4aa3dac73b66 | 28 | |
bosko001 | 7:4aa3dac73b66 | 29 | void C_gpioSpi::spiClockCount_fun(void) |
bosko001 | 7:4aa3dac73b66 | 30 | { |
bosko001 | 7:4aa3dac73b66 | 31 | |
bosko001 | 7:4aa3dac73b66 | 32 | bitCount++; |
bosko001 | 7:4aa3dac73b66 | 33 | |
bosko001 | 7:4aa3dac73b66 | 34 | readData <<= 1; |
bosko001 | 7:4aa3dac73b66 | 35 | if( p_MOSI->read() ) readData |= 1; |
bosko001 | 7:4aa3dac73b66 | 36 | else readData &= (~1); |
bosko001 | 7:4aa3dac73b66 | 37 | |
bosko001 | 7:4aa3dac73b66 | 38 | if( writeData & 0x80 ) p_MISO->write(1); |
bosko001 | 7:4aa3dac73b66 | 39 | else p_MISO->write(0); |
bosko001 | 7:4aa3dac73b66 | 40 | writeData <<= 1; |
bosko001 | 7:4aa3dac73b66 | 41 | |
bosko001 | 7:4aa3dac73b66 | 42 | if(bitCount>=8) |
bosko001 | 7:4aa3dac73b66 | 43 | { |
bosko001 | 7:4aa3dac73b66 | 44 | bitCount = 0; |
bosko001 | 7:4aa3dac73b66 | 45 | // if(transfer_fun) transfer_fun( &writeData, readData ); |
bosko001 | 7:4aa3dac73b66 | 46 | |
bosko001 | 7:4aa3dac73b66 | 47 | |
bosko001 | 7:4aa3dac73b66 | 48 | |
bosko001 | 7:4aa3dac73b66 | 49 | spiByteTransfer( &writeData, readData); |
bosko001 | 7:4aa3dac73b66 | 50 | |
bosko001 | 7:4aa3dac73b66 | 51 | } |
bosko001 | 7:4aa3dac73b66 | 52 | |
bosko001 | 7:4aa3dac73b66 | 53 | } |
bosko001 | 7:4aa3dac73b66 | 54 | |
bosko001 | 7:4aa3dac73b66 | 55 | |
bosko001 | 7:4aa3dac73b66 | 56 |