Committer:
nguyenmanhthao996tn
Date:
Sat Sep 30 09:13:06 2017 +0000
Revision:
0:31211abbf651
Worked version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nguyenmanhthao996tn 0:31211abbf651 1 #include "software_SPI.h"
nguyenmanhthao996tn 0:31211abbf651 2
nguyenmanhthao996tn 0:31211abbf651 3 software_SPI::software_SPI(PinName mosi, PinName sck)
nguyenmanhthao996tn 0:31211abbf651 4 {
nguyenmanhthao996tn 0:31211abbf651 5 this->mosi = new DigitalOut(mosi);
nguyenmanhthao996tn 0:31211abbf651 6 *(this->mosi) = 1;
nguyenmanhthao996tn 0:31211abbf651 7
nguyenmanhthao996tn 0:31211abbf651 8 this->sck = new DigitalOut(sck);
nguyenmanhthao996tn 0:31211abbf651 9 *(this->sck) = 0;
nguyenmanhthao996tn 0:31211abbf651 10 }
nguyenmanhthao996tn 0:31211abbf651 11
nguyenmanhthao996tn 0:31211abbf651 12 void software_SPI::sendData(char data)
nguyenmanhthao996tn 0:31211abbf651 13 {
nguyenmanhthao996tn 0:31211abbf651 14 char counter = 0;
nguyenmanhthao996tn 0:31211abbf651 15 for(; counter < 8; counter++) {
nguyenmanhthao996tn 0:31211abbf651 16 if (data & 0x80) {
nguyenmanhthao996tn 0:31211abbf651 17 *(this->mosi) = 1;
nguyenmanhthao996tn 0:31211abbf651 18 } else {
nguyenmanhthao996tn 0:31211abbf651 19 *(this->mosi) = 0;
nguyenmanhthao996tn 0:31211abbf651 20 }
nguyenmanhthao996tn 0:31211abbf651 21
nguyenmanhthao996tn 0:31211abbf651 22 data <<= 1;
nguyenmanhthao996tn 0:31211abbf651 23
nguyenmanhthao996tn 0:31211abbf651 24 wait_us(SOFTWARE_SPI_SCK_LOW_TIME_US);
nguyenmanhthao996tn 0:31211abbf651 25 *(this->sck) = 1;
nguyenmanhthao996tn 0:31211abbf651 26
nguyenmanhthao996tn 0:31211abbf651 27 wait_us(SOFTWARE_SPI_SCK_HIGH_TIME_US);
nguyenmanhthao996tn 0:31211abbf651 28 *(this->sck) = 0;
nguyenmanhthao996tn 0:31211abbf651 29 }
nguyenmanhthao996tn 0:31211abbf651 30 *(this->mosi) = 1;
nguyenmanhthao996tn 0:31211abbf651 31 }