本文整理汇总了C++中CS_HIGH函数的典型用法代码示例。如果您正苦于以下问题:C++ CS_HIGH函数的具体用法?C++ CS_HIGH怎么用?C++ CS_HIGH使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CS_HIGH函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SD_WriteOneSector
BYTE SD_WriteOneSector(DWORD sector,BYTE* buf){//写一个扇区(buf为512字节),成功返回0
BYTE rtn;
WORD i,cnt=0;
SPI_SetSpeedHigh();//设定SPI到高速模式
rtn=SD_SendCommand(24,sector<<9);//读命令
if(rtn!=0x00)
return rtn;
CS_LOW();
SPI_ByteRW(0xFF);
SPI_ByteRW(0xFF);
SPI_ByteRW(0xFF);
SPI_ByteRW(0xFE);//发开始符
for(i=0;i<512;i++){//送512字节数据
SPI_ByteRW(*(buf++));
}
SPI_ByteRW(0xFF);//dummy crc
SPI_ByteRW(0xFF);
rtn=SPI_ByteRW(0xFF);
if((rtn & 0x1F)!=0x05){//等待是否成功
CS_HIGH();
return rtn;
}
//等待操作完
while(!SPI_ByteRW(0xFF)){
if((cnt++)==0xFFFF){
CS_HIGH();
return 1;//超时退出
}
}
CS_HIGH();
SPI_ByteRW(0xFF);//额外8个时钟周期
return 0;
}
示例2: mmc_GoIdle
unsigned char mmc_GoIdle()
{
unsigned char response=0x01;
CS_LOW();
//Send Command 0 to put MMC in SPI mode
mmcSendCmd(MMC_GO_IDLE_STATE,0,0x95);
//Now wait for READY RESPONSE
if((mmc_error = mmcGetResponse())!=0x01)
{
CS_HIGH();
return MMC_INIT_ERROR;
}
while(response==0x01)
{
CS_HIGH();
spiSendByte(0xff);
CS_LOW();
mmcSendCmd(MMC_SEND_OP_COND,0x00,0xff);
response=mmcGetResponse();
}
CS_HIGH();
spiSendByte(0xff);
return MMC_SUCCESS;
}
示例3: mmcReadRegister
// Reading the contents of the CSD and CID registers in SPI mode is a simple
// read-block transaction.
unsigned char mmcReadRegister (const char cmd_register, const unsigned char length, unsigned char *pBuffer)
{
unsigned char uc = 0;
unsigned char rvalue = MMC_TIMEOUT_ERROR;
if (mmcSetBlockLength (length) == MMC_SUCCESS)
{
CS_LOW ();
// CRC not used: 0xff as last byte
mmcSendCmd(cmd_register, 0x000000, 0xff);
// wait for response
// in the R1 format (0x00 is no errors)
if (mmcGetResponse() == 0x00)
{
if (mmcGetXXResponse(0xfe)== 0xfe)
for (uc = 0; uc < length; uc++)
pBuffer[uc] = spiSendByte(0xff); //mmc_buffer[uc] = spiSendByte(0xff);
// get CRC bytes (not really needed by us, but required by MMC)
spiSendByte(0xff);
spiSendByte(0xff);
rvalue = MMC_SUCCESS;
}
else
rvalue = MMC_RESPONSE_ERROR;
// CS = HIGH (off)
CS_HIGH ();
// Send 8 Clock pulses of delay.
spiSendByte(0xff);
}
CS_HIGH ();
return rvalue;
} // mmc_read_register
示例4: initMMC
// Initialize MMC card
unsigned char initMMC (void)
{
//raise SS and MOSI for 80 clock cycles
//SendByte(0xff) 10 times with SS high
//RAISE SS
int i;
// Port 5 Function Dir On/Off
// 5.1-Dout Out 0 - off 1 - On -> init in SPI_Init
// 5.2-Din Inp 0 - off 1 - On -> init in SPI_Init
// 5.3-Clk Out - -> init in SPI_Init
// 5.0-mmcCS Out 0 - Active 1 - none Active
/*
P5SEL |= 0x0E;
P5SEL &= ~0x11;
P5OUT |= 0x11;
P5DIR |= 0x1B;
*/
/*
PIN_SET(port5_attr.sel, 0x0e, PIN_HI);
PIN_CLEAR(port5_attr.sel, 0x01);
PIN_SET(port5_attr.dir, 0x0B, PIN_HI);
PIN_CLEAR(port5_attr.dir, 0x04);
port_set_attr(5, 0x0f, &port5_attr);
port_write(5, 0x01, PIN_HI);
*/
// PIN_SET(port5_attr.sel, 0x0e, PIN_HI);
#ifndef PORT_WRITE
mmcPower(MMC_ON);
MMC_PWR_PDIR |= MMC_CARD_PWR;
MMC_PWR_PSEL &= ~MMC_CARD_PWR;
// MMC_POUT |= MMC_CS;
CS_HIGH();
MMC_PDIR |= MMC_CS;
MMC_PSEL &= ~MMC_CS;
#else // !PORT_WRITE
PIN_SET (mmc_pwr_port_attr.dir, MMC_CARD_PWR, PIN_HI);
PIN_CLEAR(mmc_pwr_port_attr.sel, MMC_CARD_PWR);
port_set_attr(MMC_PWR_PORT, MMC_CARD_PWR, &mmc_pwr_port_attr);
mmcPower(MMC_ON);
PIN_CLEAR(mmc_port_attr.sel, MMC_CS);
PIN_SET (mmc_port_attr.dir, MMC_CS, PIN_HI);
port_set_attr(MMC_PORT, MMC_CS, &mmc_port_attr);
CS_HIGH();
//port_write(5, 0x01, PIN_HI);
#endif // !PORT_WRITE
// initSPI();
// SPI_init();
//initialization sequence on PowerUp
// CS_HIGH();
for(i=0;i<=9;i++)
spiSendByte(0xff);
mmc_error = MMC_SUCCESS;
return (mmc_GoIdle());
}
示例5: nrf_snd_pkt_crc_encr
char nrf_snd_pkt_crc_encr(int size, uint8_t * pkt, uint32_t const key[4]){
if(size > MAX_PKT)
size=MAX_PKT;
nrf_write_reg(R_CONFIG,
R_CONFIG_PWR_UP| // Power on
R_CONFIG_EN_CRC // CRC on, single byte
);
// nrf_write_long(C_W_TX_PAYLOAD,size,pkt);
uint16_t crc=crc16(pkt,size-2);
pkt[size-2]=(crc >>8) & 0xff;
pkt[size-1]=crc & 0xff;
if(key !=NULL)
xxtea_encode_words((uint32_t*)pkt,size/4,key);
CS_LOW();
xmit_spi(C_W_TX_PAYLOAD);
sspSend(0,pkt,size);
CS_HIGH();
CE_HIGH();
delayms(1); // Send it. (only needs >10ys, i think)
CE_LOW();
return nrf_cmd_status(C_NOP);
};
示例6: nrf_read_pkt_crc
void nrf_read_pkt_crc(int len, uint8_t* data, uint8_t* crc){
CS_LOW();
xmit_spi(C_R_RX_PAYLOAD);
sspReceive(0,data,len);
sspReceive(0,crc,2);
CS_HIGH();
};
示例7: sd_write
void sd_write(char __flash *str, unsigned long int bpos) {
CS_LOW();
spi_sendbyte(0xFF);
//converting bpos to 4 bytes and set write-start position
spi_sendbyte(0x58);
spi_sendbyte(((bpos & 0xFF000000)>>24));
spi_sendbyte(((bpos & 0x00FF0000)>>16));
spi_sendbyte(((bpos & 0x0000FF00)>>8));
spi_sendbyte(((bpos & 0x000000FF)));
spi_sendbyte(0x00); //CRC
while (spi_sendbyte(0xFF)!=0x0);
spi_sendbyte(0xFF);
spi_sendbyte(0xFE);
_spi_sendtext(str); //str len up to 512 bytes
spi_sendbyte(0x00); //1-st byte CRC
spi_sendbyte(0x00); //2-nd byte CRC
while (spi_sendbyte(0xFF)&0x5 != 0x5); //waiting for the command reception signal
while (spi_sendbyte(0xFF)!=0x00); //waiting for the command reception signal
test(2);
CS_HIGH();
}
示例8: SD_read
// TODO: This function will not exit gracefully if SD card does not do what it should
void SD_read(unsigned long sector, unsigned short offset, unsigned char * buffer,
unsigned short len) {
unsigned short i, pos = 0;
CS_LOW();
SPI_send(0x51); // sector * 512 = sector << 9
SPI_send(sector>>15); // sector*512 >> 24
SPI_send(sector>>7); // sector*512 >> 16
SPI_send(sector<<1); // sector*512 >> 8
SPI_send(0); // sector*512
SPI_send(0xFF);
for(i=0; i<10 && SPI_send(0xFF) != 0x00; i++) {} // wait for 0
for(i=0; i<10 && SPI_send(0xFF) != 0xFE; i++) {} // wait for data start
for(i=0; i<offset; i++) // "skip" bytes
SPI_send(0xFF);
for(i=0; i<len; i++) // read len bytes
buffer[i] = SPI_send(0xFF);
for(i+=offset; i<512; i++) // "skip" again
SPI_send(0xFF);
// skip checksum
SPI_send(0xFF);
SPI_send(0xFF);
CS_HIGH();
}
示例9: nrf_cmd_status
uint8_t nrf_cmd_status(uint8_t cmd)
{
CS_LOW();
sspSendReceive(&cmd, 1);
CS_HIGH();
return cmd;
};
示例10: nrf_read_pkt
void nrf_read_pkt(int len, uint8_t* data)
{
CS_LOW();
sspSendByte(C_R_RX_PAYLOAD);
sspReceive(data,len);
CS_HIGH();
};
示例11: max1168_read_adc
uint16_t max1168_read_adc(uint8_t reg, enum max1168_clk clk, enum max1168_mode mode)
{
#define CH2 0x20
uint16_t raw_data;
max1168_init();
if (mode == MODE_8BIT)
PORTB &= ~(1<<DSEL);
else
PORTB |= (1<<DSEL);
CS_LOW();
/* TODO: remove hardcoded channel */
max1168_xfer_byte(CH2 | clk);
if (mode == MODE_16BIT)
max1168_xfer_byte(SPI_DUMMY_BYTE);
if (clk == CLK_INTERNAL)
while ((PINB & (1<<EOC)));
raw_data = max1168_xfer_byte(SPI_DUMMY_BYTE) << 8;
raw_data |= max1168_xfer_byte(SPI_DUMMY_BYTE);
CS_HIGH();
return raw_data;
}
示例12: irq_callback
STATIC mp_obj_t irq_callback(mp_obj_t line)
{
DEBUG_printf("<< IRQ; state=%lu >>\n", sSpiInformation.ulSpiState);
switch (sSpiInformation.ulSpiState) {
case eSPI_STATE_POWERUP:
/* This means IRQ line was low call a callback of HCI Layer to inform on event */
DEBUG_printf(" - POWERUP\n");
sSpiInformation.ulSpiState = eSPI_STATE_INITIALIZED;
break;
case eSPI_STATE_IDLE:
DEBUG_printf(" - IDLE\n");
sSpiInformation.ulSpiState = eSPI_STATE_READ_IRQ;
/* IRQ line goes down - we are start reception */
CS_LOW();
// Wait for TX/RX Compete which will come as DMA interrupt
SpiReadHeader();
sSpiInformation.ulSpiState = eSPI_STATE_READ_EOT;
SSIContReadOperation();
break;
case eSPI_STATE_WRITE_IRQ:
DEBUG_printf(" - WRITE IRQ\n");
SpiWriteDataSynchronous(sSpiInformation.pTxPacket, sSpiInformation.usTxPacketLength);
sSpiInformation.ulSpiState = eSPI_STATE_IDLE;
CS_HIGH();
break;
}
return mp_const_none;
}
示例13: dataflash_random_read
DRESULT dataflash_random_read(BYTE *buff, DWORD offset, DWORD length) {
if (!length) return RES_PARERR;
if (status & STA_NOINIT) return RES_NOTRDY;
if (offset+length > MAX_PAGE*256) return RES_PARERR;
do {
wait_for_ready();
DWORD pageaddr = ((offset/256) << 9) | (offset%256);
DWORD remaining = 256 - offset%256;
if (remaining > length) {
remaining = length;
}
length -= remaining;
offset += remaining;
CS_LOW();
xmit_spi(OP_PAGEREAD);
xmit_spi((BYTE)(pageaddr >> 16));
xmit_spi((BYTE)(pageaddr >> 8));
xmit_spi((BYTE)pageaddr);
xmit_spi(0x00); // follow up with 4 don't care bytes
xmit_spi(0x00);
xmit_spi(0x00);
xmit_spi(0x00);
do {
rcvr_spi_m(buff++);
} while (--remaining);
CS_HIGH();
} while (length);
return length ? RES_ERROR : RES_OK;
}
示例14: fm25_hw_init
void fm25_hw_init()
{
int i = 0xFFFFF;
fm25_spi_cfg();
while(i--);
//spi_config();
CS_LOW();
spi_readwrite( FM25_WRDI );
CS_HIGH();
spi_flash_device.type = RT_Device_Class_Block;
spi_flash_device.init = fm25_init;
spi_flash_device.open = fm25_open;
spi_flash_device.close = fm25_close;
spi_flash_device.read = fm25_read;
spi_flash_device.write = fm25_write;
spi_flash_device.control = fm25_control;
/* no private */
spi_flash_device.user_data = RT_NULL;
rt_device_register(&spi_flash_device, "fram0",
RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE);
}
示例15: fm25_read
rt_size_t fm25_read(rt_device_t dev, rt_off_t offset, void * buf, rt_size_t size)
{
uint32_t index;
uint8_t *buffer = (uint8_t*) buf;
fram_lock();
//spi_config();
//rt_kprintf("READ: %d, size=%d\n", offset, size);
CS_LOW();
spi_readwrite( FM25_READ);
spi_readwrite( (offset >> 8)&0xFF );
spi_readwrite( offset & 0xFF );
for(index=0; index<size; index++)
{
*buffer++ = spi_readwrite(0xFF);
if( spi_timeout_cnt > 0 )
{
fram_unlock();
spi_timeout_cnt = 0;
rt_kprintf("Read time out\n");
return -1;
}
offset++;
}
CS_HIGH();
fram_unlock();
return size;
}