本文整理汇总了C++中spiSend函数的典型用法代码示例。如果您正苦于以下问题:C++ spiSend函数的具体用法?C++ spiSend怎么用?C++ spiSend使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了spiSend函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: chipSelectLow
//------------------------------------------------------------------------------
// send command and return error code. Return zero for OK
uint8_t Sd2Card::cardCommand(uint8_t cmd, uint32_t arg) {
// select card
chipSelectLow();
// wait up to 300 ms if busy
waitNotBusy(300);
// send command
spiSend(cmd | 0x40);
// send argument
for (int8_t s = 24; s >= 0; s -= 8) spiSend(arg >> s);
// 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);
// skip stuff byte for stop read
if (cmd == CMD12) spiRec();
// wait for response
for (uint8_t i = 0; ((status_ = spiRec()) & 0X80) && i != 0XFF; i++) { /* Intentionally left empty */ }
return status_;
}
示例2: mmcSequentialWrite
/**
* @brief Writes a block within a sequential write operation.
*
* @param[in] mmcp pointer to the @p MMCDriver object
* @param[out] buffer pointer to the write buffer
*
* @return The operation status.
* @retval HAL_SUCCESS the operation succeeded.
* @retval HAL_FAILED the operation failed.
*
* @api
*/
bool mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) {
static const uint8_t start[] = {0xFF, 0xFC};
uint8_t b[1];
osalDbgCheck((mmcp != NULL) && (buffer != NULL));
if (mmcp->state != BLK_WRITING) {
return HAL_FAILED;
}
spiSend(mmcp->config->spip, sizeof(start), start); /* Data prologue. */
spiSend(mmcp->config->spip, MMCSD_BLOCK_SIZE, buffer);/* Data. */
spiIgnore(mmcp->config->spip, 2); /* CRC ignored. */
spiReceive(mmcp->config->spip, 1, b);
if ((b[0] & 0x1FU) == 0x05U) {
wait(mmcp);
return HAL_SUCCESS;
}
/* Error.*/
spiUnselect(mmcp->config->spip);
spiStop(mmcp->config->spip);
mmcp->state = BLK_READY;
return HAL_FAILED;
}
示例3: dma_setup_transfer
//------------------------------------------------------------------------------
// send one block of data for write block or write multiple blocks
uint8_t Sd2Card::writeData(uint8_t token, const uint8_t* src) {
#ifdef SPI_DMA
dma_setup_transfer(DMA1, DMA_CH3, &SPI1->regs->DR, DMA_SIZE_8BITS, (uint8_t *)src, DMA_SIZE_8BITS, (DMA_MINC_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, 512);
dmaActive = true;
dma_enable(DMA1, DMA_CH3);
while(dmaActive) delayMicroseconds(1);
dma_disable(DMA1, DMA_CH3);
#else // SPI_DMA
spiSend(token);
for (uint16_t i = 0; i < 512; i++) {
spiSend(src[i]);
}
#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();
Serial.println("Error: Write");
Serial.println("Error: Sd2Card::writeData()");
return false;
}
return true;
}
示例4: readEnd
//------------------------------------------------------------------------------
// send command to card
uint8_t SdReader::cardCommand(uint8_t cmd, uint32_t arg)
{
uint8_t r1;
// end read if in partialBlockRead mode
readEnd();
// select card
spiSSLow();
// wait up to 300 ms if busy
waitNotBusy(300);
// send command
spiSend(cmd | 0x40);
// send argument
for (int8_t s = 24; s >= 0; s -= 8) spiSend(arg >> s);
// 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 retry = 0; ((r1 = spiRec()) & 0X80) && retry != 0XFF; retry++);
return r1;
}
示例5: while
//------------------------------------------------------------------------------
// send one block of data for write block or write multiple blocks
uint8_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]);
}
#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();
return false;
}
return true;
}
示例6: mmcSequentialWrite
/**
* @brief Writes a block within a sequential write operation.
*
* @param[in] mmcp pointer to the @p MMCDriver object
* @param[out] buffer pointer to the write buffer
* @return The operation status.
* @retval FALSE the operation succeeded.
* @retval TRUE the operation failed.
*
* @api
*/
bool_t mmcSequentialWrite(MMCDriver *mmcp, const uint8_t *buffer) {
static const uint8_t start[] = {0xFF, 0xFC};
uint8_t b[1];
chDbgCheck((mmcp != NULL) && (buffer != NULL), "mmcSequentialWrite");
chSysLock();
if (mmcp->state != MMC_WRITING) {
chSysUnlock();
return TRUE;
}
chSysUnlock();
spiSend(mmcp->spip, sizeof(start), start); /* Data prologue. */
spiSend(mmcp->spip, MMC_SECTOR_SIZE, buffer); /* Data. */
spiIgnore(mmcp->spip, 2); /* CRC ignored. */
spiReceive(mmcp->spip, 1, b);
if ((b[0] & 0x1F) == 0x05) {
wait(mmcp);
return FALSE;
}
/* Error.*/
spiUnselect(mmcp->spip);
chSysLock();
if (mmcp->state == MMC_WRITING)
mmcp->state = MMC_READY;
chSysUnlock();
return TRUE;
}
示例7: readEnd
//------------------------------------------------------------------------------
// send command and return error code. Return zero for OK
uint8_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);
// send argument
for (int8_t s = 24; s >= 0; s -= 8) spiSend(arg >> s);
// 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 (unsigned int i = 0; ((status_ = spiRec()) & 0X80) && i != 0xFFF; i++);
return status_;
}
示例8: cmd_write
static void cmd_write(BaseSequentialStream *chp, int argc, char *argv[]) {
(void)argc;
(void)argv;
acquire_bus();
write_index(0x00);
chprintf(chp,"Device ID %x\r\n",read_data());
release_bus();
//chprintf(chp,"GRAM %x\r\n",gdispReadReg(0x22));
/*gdispClear(White);
chThdSleepMilliseconds(3000);
gdispClear(Red);
chThdSleepMilliseconds(3000);
gdispClear(Blue);
chThdSleepMilliseconds(3000);
gdispClear(Green);*/
#if 0
uint8_t c = 0xAA;
uint8_t d = 0x55;
spiAcquireBus(&SPID1); /* Acquire ownership of the bus. */
spiStart(&SPID1, &spicfg); /* Setup transfer parameters. */
spiSelect(&SPID1); /* Slave Select assertion. */
spiSend(&SPID1, 1, &c);
spiSend(&SPID1, 1, &d);
spiUnselect(&SPID1); /* Slave Select de-assertion. */
spiReleaseBus(&SPID1); /* Ownership release. */
#endif
}
示例9: u8g_com_HAL_DUE_shared_hw_spi_fn
uint8_t u8g_com_HAL_DUE_shared_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) {
switch(msg) {
case U8G_COM_MSG_STOP:
break;
case U8G_COM_MSG_INIT:
u8g_SetPILevel_DUE_hw_spi(u8g, U8G_PI_CS, 1);
u8g_SetPILevel_DUE_hw_spi(u8g, U8G_PI_A0, 1);
u8g_SetPIOutput_DUE_hw_spi(u8g, U8G_PI_CS);
u8g_SetPIOutput_DUE_hw_spi(u8g, U8G_PI_A0);
u8g_Delay(5);
spiBegin();
#ifndef SPI_SPEED
#define SPI_SPEED SPI_FULL_SPEED // use same SPI speed as SD card
#endif
spiInit(2);
break;
case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */
u8g_SetPILevel_DUE_hw_spi(u8g, U8G_PI_A0, arg_val);
break;
case U8G_COM_MSG_CHIP_SELECT:
u8g_SetPILevel_DUE_hw_spi(u8g, U8G_PI_CS, (arg_val ? 0 : 1));
break;
case U8G_COM_MSG_RESET:
break;
case U8G_COM_MSG_WRITE_BYTE:
spiSend((uint8_t)arg_val);
break;
case U8G_COM_MSG_WRITE_SEQ: {
uint8_t *ptr = (uint8_t*) arg_ptr;
while (arg_val > 0) {
spiSend(*ptr++);
arg_val--;
}
}
break;
case U8G_COM_MSG_WRITE_SEQ_P: {
uint8_t *ptr = (uint8_t*) arg_ptr;
while (arg_val > 0) {
spiSend(*ptr++);
arg_val--;
}
}
break;
}
return 1;
}
示例10: spiSendBlock
void spiSendBlock(uint8_t token, const uint8_t* buf) {
spiSend (token);
for (uint16_t i = 0; i < 512; i += 2) {
spiSend (buf[i]);
spiSend (buf[i+1]);
}
}
示例11: SPI_Write
void SPI_Write(unsigned int addr,unsigned char data)
{
enablewiz(); // Activate the CS pin
spiSend(WIZNET_WRITE_OPCODE); // Send Wiznet W5100 Write OpCode
spiSend(addr >>8); // Send Wiznet W5100 Address High Byte
spiSend(addr & 0x00FF); // Send Wiznet W5100 Address Low Byte
spiSend(data); // Send the data byte
disablewiz(); // make CS pin not active
}
示例12: _writeBuffer
void _writeBuffer(uint16_t len, uint8_t *data)
{
uint8_t tx[] = { WRITE_BUF_MEM };
spiSelect(_spip);
spiSend(_spip, 1, tx);
spiSend(_spip, len, data);
spiUnselect(_spip);
}
示例13: l3gd20SPIWriteRegister
/**
* @brief Writes a value into a generic register using SPI.
* @pre The SPI interface must be initialized and the driver started.
*
* @param[in] spip pointer to the SPI interface
* @param[in] reg starting register address
* @param[in] n number of adjacent registers to write
* @param[in] b pointer to a buffer of values.
*/
static void l3gd20SPIWriteRegister(SPIDriver *spip, uint8_t reg, size_t n,
uint8_t* b) {
uint8_t cmd;
(n == 1) ? (cmd = reg) : (cmd = reg | L3GD20_MS);
spiSelect(spip);
spiSend(spip, 1, &cmd);
spiSend(spip, n, b);
spiUnselect(spip);
}
示例14: adxl362_write_register
void adxl362_write_register (uint16_t address, uint8_t data) {
uint8_t command = 0x0A;
spiStart(&SPID1, &adxl362_cfg); /* Setup transfer parameters. */
spiSelect(&SPID1); /* Slave Select assertion. */
spiSend(&SPID1, 1, &command); /* Write Command */
spiSend(&SPID1, 1, &address); /* Address */
spiSend(&SPID1, 1, &data); /* Data */
spiUnselect(&SPID1); /* Slave Select de-assertion. */
}
示例15: gyro_write_register
void gyro_write_register (uint8_t address, uint8_t data) {
address = address & (~0x80); /* Clear the write bit (bit 7) */
spiAcquireBus(&SPID1); /* Acquire ownership of the bus. */
spiStart(&SPID1, &gyro_cfg); /* Setup transfer parameters. */
spiSelect(&SPID1); /* Slave Select assertion. */
spiSend(&SPID1, 1, &address); /* Send the address byte */
spiSend(&SPID1, 1, &data);
spiUnselect(&SPID1); /* Slave Select de-assertion. */
spiReleaseBus(&SPID1); /* Ownership release. */
}