您当前的位置:首页 > IT编程 > C++
| C语言 | Java | VB | VC | python | Android | TensorFlow | C++ | oracle | 学术与代码 | cnn卷积神经网络 | gnn | 图像修复 | Keras | 数据集 | Neo4j | 自然语言处理 | 深度学习 | 医学CAD | 医学影像 | 超参数 | pointnet | pytorch | 异常检测 | Transformers | 情感分类 | 知识图谱 |

自学教程:C++ spiRec函数代码示例

51自学网 2021-06-03 08:09:19
  C++
这篇教程C++ spiRec函数代码示例写得很实用,希望能帮到您。

本文整理汇总了C++中spiRec函数的典型用法代码示例。如果您正苦于以下问题:C++ spiRec函数的具体用法?C++ spiRec怎么用?C++ spiRec使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了spiRec函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: spiSend

//------------------------------------------------------------------------------// send one block of data for write block or write multiple blocksuint8_t Sd2Card::writeData(uint8_t token, const uint8_t* src) {  spiSend(token);  for (uint16_t i = 0; i < 512; i++) {    spiSend(src[i]);  }  spiSend(0xff);  // dummy crc  spiSend(0xff);  // dummy crc  status_ = spiRec();  if ((status_ & DATA_RES_MASK) != DATA_RES_ACCEPTED) {    error(SD_CARD_ERROR_WRITE);    chipSelectHigh();    return false;  }  return true;}
开发者ID:elkintomen,项目名称:chipKIT32-MAX,代码行数:20,


示例2: millis

/** Wait for start block token */uint8_t Sd2Card::waitStartBlock(void) {  uint16_t t0 = millis();  while ((status_ = spiRec()) == 0XFF) {    if (((uint16_t)millis() - t0) > SD_READ_TIMEOUT) {      error(SD_CARD_ERROR_READ_TIMEOUT);      goto fail;    }  }  if (status_ != DATA_START_BLOCK) {    error(SD_CARD_ERROR_READ);    goto fail;  }  return true; fail:  chipSelectHigh();  return false;}
开发者ID:elkintomen,项目名称:chipKIT32-MAX,代码行数:19,


示例3: while

/** Skip remaining data in a block when in partial block read mode. */void Sd2Card::readEnd(void) {  if (inBlock_) {      // skip data and crc#ifdef OPTIMIZE_HARDWARE_SPI    // optimize skip for hardware    SPDR = 0XFF;    while (offset_++ < 513) {      while (!(SPSR & (1 << SPIF)));      SPDR = 0XFF;    }    // wait for last crc byte    while (!(SPSR & (1 << SPIF)));#else  // OPTIMIZE_HARDWARE_SPI    while (offset_++ < 514) spiRec();#endif  // OPTIMIZE_HARDWARE_SPI    chipSelectHigh();    inBlock_ = 0;  }}
开发者ID:cuav,项目名称:MAAT,代码行数:20,


示例4: while

/** Wait for start block token */int Sd2Card::waitStartBlock(void) {	//unsigned t0 = millis();	unsigned count = 30000;	while ((status_ = spiRec()) == 0XFF) {		if (count-- == 0) {			error(SD_CARD_ERROR_READ_TIMEOUT);			goto fail;		}	}  if (status_ != DATA_START_BLOCK) {    error(SD_CARD_ERROR_READ);    goto fail;  }  return true; fail:  chipSelectHigh();  return false;}
开发者ID:GadgetFactory,项目名称:DesignLab_Examples,代码行数:21,


示例5: dma_setup_transfer

/** Skip remaining data in a block when in partial block read mode. */void Sd2Card::readEnd(void) {  if (inBlock_) {      // skip data and crc#ifdef SPI_DMA        dma_setup_transfer(DMA1, DMA_CH3, &SPI1->regs->DR, DMA_SIZE_8BITS, ack, DMA_SIZE_8BITS,                           (/*DMA_MINC_MODE | DMA_CIRC_MODE |*/ DMA_FROM_MEM | DMA_TRNS_CMPLT | DMA_TRNS_ERR));        dma_attach_interrupt(DMA1, DMA_CH3, DMAEvent);        dma_set_priority(DMA1, DMA_CH3, DMA_PRIORITY_VERY_HIGH);        dma_set_num_transfers(DMA1, DMA_CH3, SPI_BUFF_SIZE + 1 - offset_);        dmaActive = true;        dma_enable(DMA1, DMA_CH3);        while(dmaActive)delayMicroseconds(1);        dma_disable(DMA1, DMA_CH3);#else  // SPI_DMA    while (offset_++ < 514) spiRec();#endif  // SPI_DMA    chipSelectHigh();    inBlock_ = 0;  }}
开发者ID:floriancargoet,项目名称:choosatron-core-firmware,代码行数:23,


示例6: error

/** * Writes a 512 byte block to an SD card. * * /param[in] blockNumber Logical block to be written. * /param[in] src Pointer to the location of the data to be written. * /return The value one, true, is returned for success and * the value zero, false, is returned for failure. */uint8_t Sd2Card::writeBlock(uint32_t blockNumber, const uint8_t* src) {#if SD_PROTECT_BLOCK_ZERO  // don't allow write to first block  if (blockNumber == 0) {    error(SD_CARD_ERROR_WRITE_BLOCK_ZERO);    Serial.println("Error: Write block zero");    goto fail;  }#endif  // SD_PROTECT_BLOCK_ZERO  // use address if not SDHC card  if (type() != SD_CARD_TYPE_SDHC) blockNumber <<= 9;  if (cardCommand(CMD24, blockNumber)) {	Serial.println("Error: CMD42");	error(SD_CARD_ERROR_CMD24);	goto fail;  }  if (!writeData(DATA_START_BLOCK, src)) goto fail;  // wait for flash programming to complete  if (!waitNotBusy(SD_WRITE_TIMEOUT)) {    error(SD_CARD_ERROR_WRITE_TIMEOUT);    Serial.println("Error: Write timeout");    goto fail;  }  // response is r2 so get and check two bytes for nonzero  if (cardCommand(CMD13, 0) || spiRec()) {    error(SD_CARD_ERROR_WRITE_PROGRAMMING);    Serial.println("Error: Write programming");    goto fail;  }  chipSelectHigh();  return true; fail:  chipSelectHigh();  Serial.println("Error: Sd2Card::writeBlock");  return false;}
开发者ID:cohabo,项目名称:my_src,代码行数:47,


示例7: while

//------------------------------------------------------------------------------// send one block of data for write block or write multiple blocksuint8_t Sd2Card::writeData(uint8_t token, const uint8_t* src) {#ifdef OPTIMIZE_HARDWARE_SPI    /*      // send data - optimized loop      SPDR = token;      // send two byte per iteration      for (uint16_t i = 0; i < 512; i += 2) {        while (!(SPSR & (1 << SPIF)));        SPDR = src[i];        while (!(SPSR & (1 << SPIF)));        SPDR = src[i+1];      }      // wait for last data byte      while (!(SPSR & (1 << SPIF)));    */#else  // OPTIMIZE_HARDWARE_SPI    spiSend(token);    for (uint16_t i = 0; i < 512; i++)    {        spiSend(src[i]);    }    //spiSend(src, 512);#endif  // OPTIMIZE_HARDWARE_SPI    spiSend(0xff);  // dummy crc    spiSend(0xff);  // dummy crc    status_ = spiRec();    if ((status_ & DATA_RES_MASK) != DATA_RES_ACCEPTED)    {        error(SD_CARD_ERROR_WRITE);        chipSelectHigh();        SerialDebug.println("Error: Write");        SerialDebug.println("Error: Sd2Card::writeData()");        return false;    }    return true;}
开发者ID:jdkarpin,项目名称:AeroQuad,代码行数:41,


示例8: defined

/** Skip remaining data in a block when in partial block read mode. */void Sd2Card::readEnd(void) {  if (inBlock_) {      // skip data and crc#if defined(USE_TEENSY3_SPI)    if (offset_ < 514) {      spiRecIgnore(514 - offset_);      offset_ = 514;    }#elif defined(OPTIMIZE_HARDWARE_SPI)    // optimize skip for hardware    SPDR = 0XFF;    while (offset_++ < 513) {      while (!(SPSR & (1 << SPIF)));      SPDR = 0XFF;    }    // wait for last crc byte    while (!(SPSR & (1 << SPIF)));#else  // OPTIMIZE_HARDWARE_SPI    while (offset_++ < 514) spiRec();#endif  // OPTIMIZE_HARDWARE_SPI    chipSelectHigh();    inBlock_ = 0;  }}
开发者ID:brianc118,项目名称:Team-PI-Lib,代码行数:25,


示例9: readEnd

//------------------------------------------------------------------------------// send command and return error code.  Return zero for OKuint8_t Sd2Card::cardCommand(uint8_t cmd, uint32_t arg) {  // end read if in partialBlockRead mode  readEnd();  // select card  chipSelectLow();  // wait up to 300 ms if busy  waitNotBusy(300);  // send command  spiSend(cmd | 0x40);#ifdef ESP8266  // send argument  SPI.write32(arg, true);#else  // send argument  for (int8_t s = 24; s >= 0; s -= 8) spiSend(arg >> s);#endif  // send CRC  uint8_t crc = 0xFF;  if (cmd == CMD0) crc = 0x95;  // correct crc for CMD0 with arg 0  if (cmd == CMD8) crc = 0x87;  // correct crc for CMD8 with arg 0X1AA  spiSend(crc);  // wait for response  for (uint8_t i = 0; ((status_ = spiRec()) & 0x80) && i != 0xFF; i++)    ;  #ifdef ESP8266  optimistic_yield(10000);  #endif  return status_;}
开发者ID:9mrcookie9,项目名称:Arduino,代码行数:38,


示例10: error

/**    Read part of a 512 byte block from an SD card.    /param[in] block Logical block to be read.    /param[in] offset Number of bytes to skip at start of block    /param[out] dst Pointer to the location that will receive the data.    /param[in] count Number of bytes to read    /return The value one, true, is returned for success and    the value zero, false, is returned for failure.*/uint8_t Sd2Card::readData(uint32_t block, uint16_t offset, uint16_t count, uint8_t* dst){//    uint16_t n;    if (count == 0)    {        return true;    }    if ((count + offset) > 512)    {        goto fail;    }    if (!inBlock_ || block != block_ || offset < offset_)    {        block_ = block;        // use address if not SDHC card        if (type() != SD_CARD_TYPE_SDHC)        {            block <<= 9;        }        if (cardCommand(CMD17, block))        {            error(SD_CARD_ERROR_CMD17);            goto fail;        }        if (!waitStartBlock())        {            goto fail;        }        offset_ = 0;        inBlock_ = 1;    }#ifdef OPTIMIZE_HARDWARE_SPI    // start first spi transfer    SPDR = 0XFF;    // skip data before offset    for (; offset_ < offset; offset_++)    {        while (!(SPSR & (1 << SPIF)));        SPDR = 0XFF;    }    // transfer data    n = count - 1;    for (uint16_t i = 0; i < n; i++)    {        while (!(SPSR & (1 << SPIF)));        dst[i] = SPDR;        SPDR = 0XFF;    }    // wait for last byte    while (!(SPSR & (1 << SPIF)));    dst[n] = SPDR;#else  // OPTIMIZE_HARDWARE_SPI    // skip data before offset    for (; offset_ < offset; offset_++)    {        spiRec();    }    // transfer data    for (uint16_t i = 0; i < count; i++)    {        dst[i] = spiRec();    }#endif  // OPTIMIZE_HARDWARE_SPI    offset_ += count;    if (!partialBlockRead_ || offset_ >= 512)    {        // read rest of data, checksum and set chip select high        readEnd();    }    return true;fail:    chipSelectHigh();    return false;}
开发者ID:rei-vilo,项目名称:SD_TM4C,代码行数:90,


示例11: pinMode

/** * Initialize an SD flash memory card. * * /param[in] sckRateID SPI clock rate selector. See setSckRate(). * /param[in] chipSelectPin SD chip select pin number. * * /return The value one, true, is returned for success and * the value zero, false, is returned for failure.  The reason for failure * can be determined by calling errorCode() and errorData(). */uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {  errorCode_ = inBlock_ = partialBlockRead_ = type_ = 0;  // 16-bit init start time allows over a minute  uint16_t t0 = (uint16_t)millis();  uint32_t arg;  SPI2CON = 0;  DDPCONbits.JTAGEN = 0;  AD1PCFG = 0xFFFF;  chipSelectPin_ = chipSelectPin;  pinMode(chipSelectPin_, OUTPUT);  PORTSetPinsDigitalOut(prtSCK, bnSCK);  PORTSetPinsDigitalOut(prtSDO, bnSDO);  PORTSetPinsDigitalIn(prtSDI, bnSDI);    // set pin modes  chipSelectHigh();  // must supply min of 74 clock cycles with CS high.  for (uint8_t i = 0; i < 10; i++) spiSend(0XFF);  chipSelectLow();  // command to go idle in SPI mode  while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {      error(SD_CARD_ERROR_CMD0);      goto fail;    }  }  // check SD version  if ((cardCommand(CMD8, 0x1AA) & R1_ILLEGAL_COMMAND)) {    type(SD_CARD_TYPE_SD1);  } else {    // only need last byte of r7 response    for (uint8_t i = 0; i < 4; i++) status_ = spiRec();    if (status_ != 0XAA) {      error(SD_CARD_ERROR_CMD8);      goto fail;    }    type(SD_CARD_TYPE_SD2);  }  // initialize card and send host supports SDHC if SD2  arg = type() == SD_CARD_TYPE_SD2 ? 0X40000000 : 0;  while ((status_ = cardAcmd(ACMD41, arg)) != R1_READY_STATE) {    // check for timeout    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {      error(SD_CARD_ERROR_ACMD41);      goto fail;    }  }  // if SD2 read OCR register to check for SDHC card  if (type() == SD_CARD_TYPE_SD2) {    if (cardCommand(CMD58, 0)) {      error(SD_CARD_ERROR_CMD58);      goto fail;    }    if ((spiRec() & 0XC0) == 0XC0) type(SD_CARD_TYPE_SDHC);    // discard rest of ocr - contains allowed voltage range    for (uint8_t i = 0; i < 3; i++) spiRec();  }  chipSelectHigh();#ifndef SOFTWARE_SPI  return setSckRate(sckRateID);#else  // SOFTWARE_SPI  return true;#endif  // SOFTWARE_SPI fail:  chipSelectHigh();  return false;}
开发者ID:JacobChrist,项目名称:chipKIT32-MAX,代码行数:90,


示例12: setSckRate

//.........这里部分代码省略.........    //#endif // SOFTWARE_SPI    // Hardware card detection    if (cardDetectionPin_ >= 0)    {        //        debugln("hardware card detection %i should be %i", digitalRead(cardDetectionPin_), level);        if (digitalRead(cardDetectionPin_) != level_)        {            // Serial.println("*** hardware failure");            error(SD_CARD_ERROR_CMD0);            // I don't like goto but this is how it is implemented            goto fail;        }    }    // Software card detection    // must supply min of 74 clock cycles with CS high.    for (uint8_t i = 0; i < 10; i++)    {        spiSend(0xff);    }    chipSelectLow();    // Serial.print("software card detection ");    // command to go idle in SPI mode    while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE)    {        if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT)        {            error(SD_CARD_ERROR_CMD0);            // Serial.println("*** software failure");            goto fail;        }    }    // check SD version    if ((cardCommand(CMD8, 0x1AA) & R1_ILLEGAL_COMMAND))    {        type(SD_CARD_TYPE_SD1);    }    else    {        // only need last byte of r7 response        for (uint8_t i = 0; i < 4; i++)        {            status_ = spiRec();        }        if (status_ != 0xaa)        {            error(SD_CARD_ERROR_CMD8);            goto fail;        }        type(SD_CARD_TYPE_SD2);    }    // initialize card and send host supports SDHC if SD2    arg = type() == SD_CARD_TYPE_SD2 ? 0x40000000 : 0;    while ((status_ = cardAcmd(ACMD41, arg)) != R1_READY_STATE)    {        // check for timeout        if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT)        {            error(SD_CARD_ERROR_ACMD41);            goto fail;        }    }    // if SD2 read OCR register to check for SDHC card    if (type() == SD_CARD_TYPE_SD2)    {        if (cardCommand(CMD58, 0))        {            error(SD_CARD_ERROR_CMD58);            goto fail;        }        if ((spiRec() & 0xc0) == 0xc0)        {            type(SD_CARD_TYPE_SDHC);        }        // discard rest of ocr - contains allowed voltage range        for (uint8_t i = 0; i < 3; i++)        {            spiRec();        }    }    chipSelectHigh();#ifndef SOFTWARE_SPI    return setSckRate(sckRateID);#else  // SOFTWARE_SPI    return true;#endif  // SOFTWARE_SPIfail:    chipSelectHigh();    return false;}
开发者ID:rei-vilo,项目名称:SD_TM4C,代码行数:101,


示例13: pinMode

/** * Initialize an SD flash memory card. * * /param[in] sckRateID SPI clock rate selector. See setSckRate(). * /param[in] chipSelectPin SD chip select pin number. * * /return The value one, true, is returned for success and * the value zero, false, is returned for failure.  The reason for failure * can be determined by calling errorCode() and errorData(). */uint8_t Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {  errorCode_ = inBlock_ = partialBlockRead_ = type_ = 0;  chipSelectPin_ = chipSelectPin;  // 16-bit init start time allows over a minute  uint16_t t0 = (uint16_t)millis();  uint32_t arg;  // set pin modes  pinMode(chipSelectPin_, OUTPUT);  digitalWrite(chipSelectPin_, HIGH);#ifndef USE_SPI_LIB  pinMode(SPI_MISO_PIN, INPUT);  pinMode(SPI_MOSI_PIN, OUTPUT);  pinMode(SPI_SCK_PIN, OUTPUT);#endif#ifndef SOFTWARE_SPI#ifndef USE_SPI_LIB  // SS must be in output mode even it is not chip select  pinMode(SS_PIN, OUTPUT);  digitalWrite(SS_PIN, HIGH); // disable any SPI device using hardware SS pin  // Enable SPI, Master, clock rate f_osc/128  SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR1) | (1 << SPR0);  // clear double speed  SPSR &= ~(1 << SPI2X);#else // USE_SPI_LIB  SPI.begin();  settings = SPISettings(250000, MSBFIRST, SPI_MODE0);#endif // USE_SPI_LIB#endif // SOFTWARE_SPI  // must supply min of 74 clock cycles with CS high.#ifdef USE_SPI_LIB  SPI.beginTransaction(settings);#endif  for (uint8_t i = 0; i < 10; i++) spiSend(0XFF);#ifdef USE_SPI_LIB  SPI.endTransaction();#endif  chipSelectLow();  // command to go idle in SPI mode  while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {    if (((uint16_t)(millis() - t0)) > SD_INIT_TIMEOUT) {      error(SD_CARD_ERROR_CMD0);      goto fail;    }  }  // check SD version  if ((cardCommand(CMD8, 0x1AA) & R1_ILLEGAL_COMMAND)) {    type(SD_CARD_TYPE_SD1);  } else {    // only need last byte of r7 response    for (uint8_t i = 0; i < 4; i++) status_ = spiRec();    if (status_ != 0XAA) {      error(SD_CARD_ERROR_CMD8);      goto fail;    }    type(SD_CARD_TYPE_SD2);  }  // initialize card and send host supports SDHC if SD2  arg = type() == SD_CARD_TYPE_SD2 ? 0X40000000 : 0;  while ((status_ = cardAcmd(ACMD41, arg)) != R1_READY_STATE) {    // check for timeout    if (((uint16_t)(millis() - t0)) > SD_INIT_TIMEOUT) {      error(SD_CARD_ERROR_ACMD41);      goto fail;    }  }  // if SD2 read OCR register to check for SDHC card  if (type() == SD_CARD_TYPE_SD2) {    if (cardCommand(CMD58, 0)) {      error(SD_CARD_ERROR_CMD58);      goto fail;    }    if ((spiRec() & 0XC0) == 0XC0) type(SD_CARD_TYPE_SDHC);    // discard rest of ocr - contains allowed voltage range    for (uint8_t i = 0; i < 3; i++) spiRec();  }  chipSelectHigh();#ifndef SOFTWARE_SPI  return setSckRate(sckRateID);#else  // SOFTWARE_SPI  return true;#endif  // SOFTWARE_SPI fail://.........这里部分代码省略.........
开发者ID:jucs,项目名称:temperature,代码行数:101,


示例14: pinMode

/** * Initialize a SD flash memory card. * * /param[in] slow If /a slow is false (zero) the SPI bus will * be initialize at a speed of 8 Mhz.  If /a slow is true (nonzero) * the SPI bus will be initialize a speed of 4 Mhz. This may be helpful * for some SD cards with Version 1.0 of the Adafruit Wave Shield. * * /return The value one, true, is returned for success and * the value zero, false, is returned for failure.  * */  uint8_t SdReader::init(uint8_t slow) {  uint8_t ocr[4];  uint8_t r;    pinMode(SS, OUTPUT);  digitalWrite(SS, HIGH);  pinMode(MOSI, OUTPUT);  pinMode(MISO_PIN, INPUT);  pinMode(SCK, OUTPUT);  #if SPI_INIT_SLOW  // Enable SPI, Master, clock rate f_osc/128  SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR1) | (1 << SPR0);#else  // SPI_INIT_SLOW  // Enable SPI, Master, clock rate f_osc/64  SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR1);#endif  // SPI_INIT_SLOW    // must supply min of 74 clock cycles with CS high.  for (uint8_t i = 0; i < 10; i++) spiSend(0XFF);    // next two lines prevent re-init hang by cards that were in partial read  spiSSLow();  for (uint16_t i = 0; i <= 512; i++) spiRec();    // command to go idle in SPI mode  for (uint8_t retry = 0; ; retry++) {    if ((r = cardCommand(CMD0, 0)) ==  R1_IDLE_STATE) break;    if (retry == 10) {      error(SD_CARD_ERROR_CMD0, r);      return false;    }  }  // check SD version  r = cardCommand(CMD8, 0x1AA);  if (r == R1_IDLE_STATE) {    for(uint8_t i = 0; i < 4; i++) {      r = spiRec();    }    if (r != 0XAA) {      error(SD_CARD_ERROR_CMD8_ECHO, r);      return false;    }    type(SD_CARD_TYPE_SD2);  }  else if (r & R1_ILLEGAL_COMMAND) {    type(SD_CARD_TYPE_SD1);  }  else {    error(SD_CARD_ERROR_CMD8, r);  }  // initialize card and send host supports SDHC if SD2  for (uint16_t t0 = millis();;) {    cardCommand(CMD55, 0);    r = cardCommand(ACMD41, type() == SD_CARD_TYPE_SD2 ? 0X40000000 : 0);    if (r == R1_READY_STATE) break;        // timeout after 2 seconds    if (((uint16_t)millis() - t0) > 2000) {      error(SD_CARD_ERROR_ACMD41);      return false;    }  }  // if SD2 read OCR register to check for SDHC card  if (type() == SD_CARD_TYPE_SD2) {    if(cardCommand(CMD58, 0)) {      error(SD_CARD_ERROR_CMD58);      return false;    }    if ((spiRec() & 0XC0) == 0XC0) type(SD_CARD_TYPE_SDHC);        // discard rest of ocr    for (uint8_t i = 0; i < 3; i++) spiRec();  }  // use max SPI frequency unless slow is true  SPCR &= ~((1 << SPR1) | (1 << SPR0)); // f_OSC/4    if (!slow) SPSR |= (1 << SPI2X); // Doubled Clock Frequency: f_OSC/2  spiSSHigh();  return true;}
开发者ID:GrandK,项目名称:cheerful-bot,代码行数:94,


示例15: pinMode

/** * Initialize an SD flash memory card. * * /return The value one, true, is returned for success and * the value zero, false, is returned for failure.  The reason for failure * can be determined by calling errorCode() and errorData(). */uint8_t Sd2Card::init() {  errorCode_ = inBlock_ = partialBlockRead_ = type_ = 0;  chipSelectPin_ = SD_CHIP_SELECT_PIN;  // 16-bit init start time allows over a minute  uint16_t t0 = (uint16_t)millis();  uint32_t arg;  // set pin modes  pinMode(chipSelectPin_, OUTPUT);  chipSelectHigh();  pinMode(SPI_MISO_PIN, INPUT);  pinMode(SPI_MOSI_PIN, OUTPUT);  pinMode(SPI_SCK_PIN, OUTPUT);  // must supply min of 74 clock cycles with CS high.  for (uint8_t i = 0; i < 10; i++) spiSend(0XFF);  chipSelectLow();  // command to go idle in SPI mode  while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {      error(SD_CARD_ERROR_CMD0);      goto fail;    }  }  // check SD version  if ((cardCommand(CMD8, 0x1AA) & R1_ILLEGAL_COMMAND)) {    type(SD_CARD_TYPE_SD1);  } else {    // only need last byte of r7 response    for (uint8_t i = 0; i < 4; i++) status_ = spiRec();    if (status_ != 0XAA) {      error(SD_CARD_ERROR_CMD8);      goto fail;    }    type(SD_CARD_TYPE_SD2);  }  // initialize card and send host supports SDHC if SD2  arg = type() == SD_CARD_TYPE_SD2 ? 0X40000000 : 0;  while ((status_ = cardAcmd(ACMD41, arg)) != R1_READY_STATE) {    // check for timeout    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {      error(SD_CARD_ERROR_ACMD41);      goto fail;    }  }  // if SD2 read OCR register to check for SDHC card  if (type() == SD_CARD_TYPE_SD2) {    if (cardCommand(CMD58, 0)) {      error(SD_CARD_ERROR_CMD58);      goto fail;    }    if ((spiRec() & 0XC0) == 0XC0) type(SD_CARD_TYPE_SDHC);    // discard rest of ocr - contains allowed voltage range    for (uint8_t i = 0; i < 3; i++) spiRec();  }  chipSelectHigh();  return true; fail:  chipSelectHigh();  return false;}
开发者ID:abiaozsh,项目名称:MyCode,代码行数:74,


示例16: error

/** * Read part of a 512 byte block from an SD card. * * /param[in] block Logical block to be read. * /param[in] offset Number of bytes to skip at start of block * /param[out] dst Pointer to the location that will receive the data. * /param[in] count Number of bytes to read * /return The value one, true, is returned for success and * the value zero, false, is returned for failure. */uint8_t Sd2Card::readData(uint32_t block,        uint16_t offset, uint16_t count, uint8_t* dst) {  //uint16_t n;  if (count == 0) return true;  if ((count + offset) > 512) {    goto fail;  }  if (!inBlock_ || block != block_ || offset < offset_) {    block_ = block;    // use address if not SDHC card    if (type()!= SD_CARD_TYPE_SDHC) block <<= 9;    if (cardCommand(CMD17, block)) {      error(SD_CARD_ERROR_CMD17);	  Serial.println("Error: CMD17");      goto fail;    }    if (!waitStartBlock()) {      goto fail;    }    offset_ = 0;    inBlock_ = 1;  }#ifdef SPI_DMA    // skip data before offset    if(offset_ < offset){        dma_setup_transfer(DMA1,				DMA_CH3,				&SPI1->regs->DR,				DMA_SIZE_8BITS,				ack,				DMA_SIZE_8BITS,                           (/*DMA_MINC_MODE | DMA_CIRC_MODE  |*/ DMA_FROM_MEM | DMA_TRNS_CMPLT | DMA_TRNS_ERR));        dma_attach_interrupt(DMA1, DMA_CH3, DMAEvent);        dma_set_priority(DMA1, DMA_CH3, DMA_PRIORITY_VERY_HIGH);        dma_set_num_transfers(DMA1, DMA_CH3, offset - offset_);        dmaActive = true;        dma_enable(DMA1, DMA_CH3);        while(dmaActive) delayMicroseconds(1);        dma_disable(DMA1, DMA_CH3);    }    offset_ = offset;    // transfer data    dma_setup_transfer(DMA1, DMA_CH2, &SPI1->regs->DR, DMA_SIZE_8BITS, dst, DMA_SIZE_8BITS,                       (DMA_MINC_MODE | DMA_TRNS_CMPLT | DMA_TRNS_ERR));    dma_attach_interrupt(DMA1, DMA_CH2, DMAEvent);    dma_setup_transfer(DMA1, DMA_CH3, &SPI1->regs->DR, DMA_SIZE_8BITS, ack, DMA_SIZE_8BITS,                       (/*DMA_MINC_MODE | DMA_CIRC_MODE |*/ DMA_FROM_MEM));    dma_set_priority(DMA1, DMA_CH2, DMA_PRIORITY_VERY_HIGH);    dma_set_priority(DMA1, DMA_CH3, DMA_PRIORITY_VERY_HIGH);    dma_set_num_transfers(DMA1, DMA_CH2, count);    dma_set_num_transfers(DMA1, DMA_CH3, count);    dmaActive = true;    dma_enable(DMA1, DMA_CH3);    dma_enable(DMA1, DMA_CH2);    while(dmaActive) delayMicroseconds(1);    dma_disable(DMA1, DMA_CH3);    dma_disable(DMA1, DMA_CH2);    offset_ += count;    if (!partialBlockRead_ || offset_ >= SPI_BUFF_SIZE) {        readEnd();    }#else  // skip data before offset  for (;offset_ < offset; offset_++) {    spiRec();  }  // transfer data  for (uint16_t i = 0; i < count; i++) {    dst[i] = spiRec();  }  offset_ += count;  if (!partialBlockRead_ || offset_ >= 512) {    // read rest of data, checksum and set chip select high    readEnd();  }#endif  return true; fail:  chipSelectHigh();  Serial.println("Error: Sd2Card::readData()");//.........这里部分代码省略.........
开发者ID:floriancargoet,项目名称:choosatron-core-firmware,代码行数:101,


示例17: chipSelectHigh

uint8_t Sd2Card::init(HardwareSPI &SPIn) {  errorCode_ = inBlock_ = partialBlockRead_ = type_ = 0;  //chipSelectPin_ = chipSelectPin;  // 16-bit init start time allows over a minute  uint16_t t0 = (uint16_t)millis();  uint32_t arg;//  SPIn = s;  // set pin modes/*  pinMode(chipSelectPin_, OUTPUT);  chipSelectHigh();  pinMode(SPI_MISO_PIN, INPUT);  pinMode(SPI_MOSI_PIN, OUTPUT);  pinMode(SPI_SCK_PIN, OUTPUT);*/  // SS must be in output mode even it is not chip select//  pinMode(SS_PIN, OUTPUT);  // Enable SPI, Master, clock rate f_osc/128//  SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR1) | (1 << SPR0);  // clear double speed//  SPSR &= ~(1 << SPI2X);  // must supply min of 74 clock cycles with CS high.    chipSelectHigh();    for (uint8_t i = 0; i < 10; i++) spiSend(0XFF);  chipSelectLow();  // command to go idle in SPI mode  while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {		Serial.println("Error: CMD0");		error(SD_CARD_ERROR_CMD0);		goto fail;    }  }  // check SD version  if ((cardCommand(CMD8, 0x1AA) & R1_ILLEGAL_COMMAND)) {    type(SD_CARD_TYPE_SD1);  } else {    // only need last byte of r7 response    for (uint8_t i = 0; i < 4; i++) status_ = spiRec();    if (status_ != 0XAA) {      error(SD_CARD_ERROR_CMD8);	  Serial.println("Error: CMD8");	  goto fail;    }    type(SD_CARD_TYPE_SD2);  }  // initialize card and send host supports SDHC if SD2  arg = (type() == SD_CARD_TYPE_SD2) ? 0X40000000 : 0;  while ((status_ = cardAcmd(ACMD41, arg)) != R1_READY_STATE) {    // check for timeout    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {		Serial.println("Error: ACMD41");		error(SD_CARD_ERROR_ACMD41);		goto fail;    }  }  // if SD2 read OCR register to check for SDHC card  if (type() == SD_CARD_TYPE_SD2) {    if (cardCommand(CMD58, 0)) {		Serial.println("Error: CMD58");		error(SD_CARD_ERROR_CMD58);		goto fail;    }    if ((spiRec() & 0XC0) == 0XC0) type(SD_CARD_TYPE_SDHC);    // discard rest of ocr - contains allowed voltage range    for (uint8_t i = 0; i < 3; i++) spiRec();  }  chipSelectHigh();//  return setSckRate(sckRateID);  return true; fail:  chipSelectHigh();  Serial.println("Error: Sd2Card::init()");  return false;}
开发者ID:cohabo,项目名称:my_src,代码行数:85,


示例18: pinMode

/** * Initialize an SD flash memory card. * * /param[in] sckRateID SPI clock rate selector. See setSckRate(). * /param[in] chipSelectPin SD chip select pin number. * * /return The value one, true, is returned for success and * the value zero, false, is returned for failure.  The reason for failure * can be determined by calling errorCode() and errorData(). */bool Sd2Card::init(uint8_t sckRateID, uint8_t chipSelectPin) {  errorCode_ = type_ = 0;  chipSelectPin_ = chipSelectPin;  // 16-bit init start time allows over a minute  uint16_t t0 = (uint16_t)millis();  uint32_t arg;  // set pin modes  pinMode(chipSelectPin_, OUTPUT);  chipSelectHigh();  pinMode(SPI_MISO_PIN, INPUT);  pinMode(SPI_MOSI_PIN, OUTPUT);  pinMode(SPI_SCK_PIN, OUTPUT);  // SS must be in output mode even it is not chip select  pinMode(SS_PIN, OUTPUT);  // set SS high - may be chip select for another SPI device#if SET_SPI_SS_HIGH  digitalWrite(SS_PIN, HIGH);#endif  // SET_SPI_SS_HIGH  spiInit();  // set SCK rate for initialization commands  setSckRate(SPI_SD_INIT_RATE);  // must supply min of 74 clock cycles with CS high.  for (uint8_t i = 0; i < 10; i++) spiSend(0XFF);  // command to go idle in SPI mode  while ((status_ = cardCommand(CMD0, 0)) != R1_IDLE_STATE) {    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {      error(SD_CARD_ERROR_CMD0);      goto fail;    }  }  // check SD version  if ((cardCommand(CMD8, 0x1AA) & R1_ILLEGAL_COMMAND)) {    type(SD_CARD_TYPE_SD1);  } else {    // only need last byte of r7 response    for (uint8_t i = 0; i < 4; i++) status_ = spiRec();    if (status_ != 0XAA) {      error(SD_CARD_ERROR_CMD8);      goto fail;    }    type(SD_CARD_TYPE_SD2);  }  // initialize card and send host supports SDHC if SD2  arg = type() == SD_CARD_TYPE_SD2 ? 0X40000000 : 0;  while ((status_ = cardAcmd(ACMD41, arg)) != R1_READY_STATE) {    // check for timeout    if (((uint16_t)millis() - t0) > SD_INIT_TIMEOUT) {      error(SD_CARD_ERROR_ACMD41);      goto fail;    }  }  // if SD2 read OCR register to check for SDHC card  if (type() == SD_CARD_TYPE_SD2) {    if (cardCommand(CMD58, 0)) {      error(SD_CARD_ERROR_CMD58);      goto fail;    }    if ((spiRec() & 0XC0) == 0XC0) type(SD_CARD_TYPE_SDHC);    // discard rest of ocr - contains allowed voltage range    for (uint8_t i = 0; i < 3; i++) spiRec();  }  chipSelectHigh();  return setSckRate(sckRateID); fail:  chipSelectHigh();  return false;}
开发者ID:Kazuyoko,项目名称:MarlinKimbra4due,代码行数:84,


示例19: spiRead

void spiRead(uint8_t* buf, uint16_t nbyte) {	while (nbyte--)		*buf++ = spiRec();}
开发者ID:Kazuyoko,项目名称:MarlinKimbra4due,代码行数:6,


示例20: spiSSOutputMode

/** * Initialize a SD flash memory card. * * /param[in] slow Set SPI Frequency F_CPU/4 if true else F_CPU/2. * * /return The value one, true, is returned for success and * the value zero, false, is returned for failure.  */  uint8_t Sd2Card::init(uint8_t slow){  uint8_t r;  errorCode_ = inBlock_ = partialBlockRead_ = type_ = 0;  // set pin modes  spiSSOutputMode();  spiSSHigh();  spiMISOInputMode();  spiMOSIOutputMode();  spiSCKOutputMode();  #ifndef SOFTWARE_SPI  //Enable SPI, Master, clock rate f_osc/128  SPCR = (1 << SPE) | (1 << MSTR) | (1 << SPR1) | (1 << SPR0);#endif //SOFTWARE_SPI  //must supply min of 74 clock cycles with CS high.  for (uint8_t i = 0; i < 10; i++) spiSend(0XFF);    // next two lines prevent re-init hang by cards that were in partial read  spiSSLow();  for (uint16_t i = 0; i <= 512; i++) spiRec();    // command to go idle in SPI mode  for (uint8_t retry = 0; ; retry++) {    if ((r = cardCommand(CMD0, 0)) ==  R1_IDLE_STATE) break;    if (retry == 10) {      error(SD_CARD_ERROR_CMD0, r);      return false;    }  }  // check SD version  if ((cardCommand(CMD8, 0x1AA) & R1_ILLEGAL_COMMAND)) {    type(SD_CARD_TYPE_SD1);  }  else {    // only need last byte of r7 response    for(uint8_t i = 0; i < 4; i++) r = spiRec();    if (r != 0XAA) {      error(SD_CARD_ERROR_CMD8, r);      return false;    }    type(SD_CARD_TYPE_SD2);  }  // initialize card and send host supports SDHC if SD2  for (uint16_t t0 = millis();;) {    r = cardAcmd(ACMD41, type() == SD_CARD_TYPE_SD2 ? 0X40000000 : 0);    if (r == R1_READY_STATE) break;    // timeout after 2 seconds    if (((uint16_t)millis() - t0) > 2000) {      error(SD_CARD_ERROR_ACMD41);      return false;    }  }  // if SD2 read OCR register to check for SDHC card  if (type() == SD_CARD_TYPE_SD2) {    if(cardCommand(CMD58, 0)) {      error(SD_CARD_ERROR_CMD58);      return false;    }    if ((spiRec() & 0XC0) == 0XC0) type(SD_CARD_TYPE_SDHC);    // discard rest of ocr     for (uint8_t i = 0; i < 3; i++) spiRec();  }#ifndef SOFTWARE_SPI  // set SPI frequency to f_OSC/4  SPCR &= ~((1 << SPR1) | (1 << SPR0));  // if !slow set SPI frequency to f_OSC/2  if (!slow) SPSR |= (1 << SPI2X); #endif // SOFTWARE_SPI  spiSSHigh();  return true;}
开发者ID:natetarrh,项目名称:rfid,代码行数:83,



注:本文中的spiRec函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


C++ spiReleaseBus函数代码示例
C++ sphere函数代码示例
万事OK自学网:51自学网_软件自学网_CAD自学网自学excel、自学PS、自学CAD、自学C语言、自学css3实例,是一个通过网络自主学习工作技能的自学平台,网友喜欢的软件自学网站。