void MAX5513_Test(void){ unsigned char countx =0; unsigned char MAX5513_INPUT = 7; Analog_Init(1); ANALOG_ENABLE_PIN(MAX5513_INPUT); ANALOG_ENABLE_PIN(MAX5513_INPUT-1); printf("\nAnalog On PIN #%d", MAX5513_INPUT); printf("\nAnalog On PIN #%d", MAX5513_INPUT-1); SPI_INIT(400000); SPI_Toggle_MasterSS(0); // disable slave select from master MAX5513_ON_3_4V(); // max voltage MAX5513_INIT_DDR(); // Make Square // Make Triangle for(;;){ MAX5513_Set_Chan(0xFF,2); MAX5513_Set_Chan(countx++,1); // make forever triangle Timer_Delay_10us(1); MAX5513_Set_Chan(0x00,2); Timer_Delay_10us(1); } return; }
/*----------------------------------------------------------------------------** ** Function Name : ECG_SPI_INIT ** ** Description : - The function initializes the SPI peripheral for ** ** the the Tx and Rx as required for the ** ** ADS1258.The function uses:- ** ** ** ** - SPI CLK - 7 MHz ** ** - WordLength - 8 ** ** - csDelay - 0 (other delay not supported in C5505) ** ** Parameters : - None ** ** Return : ECG_Status - Output : return the status ECG_OK on ** ** successful Init ** **----------------------------------------------------------------------------*/ ECG_Status ECG_SPI_INIT() { ECG_Status Status; DDA_spiConfig spiConfig; Uint16 spiClkRate = 7000000; /* 7MHz Max possible for SPI, but not used- hardcoded */ /* the SPI_PRESCALE to 13 so as to achieve 7MHz */ Uint16 frameLen = 1; /* Frame Len 1 */ Uint16 wordLen = 8; /* Word len 8 */ Uint16 slaveNo = 0; /* SlaveNo 0 */ Uint16 dataDly = 0; /* delay 0 */ Uint16 csPol = 0; /* cspol 0 */ Uint16 clkPh = 0; /* clkphase 0 */ Uint16 clkPol = 0; /* clkpol 0 */ Status = SPI_FAILURE; /* Driver configuration initialization */ spiConfig.spiCtrlMode = SPI_MODE; /* SPI Mode */ spiConfig.spiMaster = SPI_MASTER; /* SPI Master */ spiConfig.opMode = SPI_POLLED; /* SPI polling mode */ spiConfig.instances = SPI_SINGLE_INST; /* Single instance */ spiConfig.syncMode = SPI_SYNC; /* Sync Mode */ /* Initialize the SPI with */ Status = SPI_INIT(spiConfig,spiClkRate,frameLen,wordLen,slaveNo,dataDly,csPol,clkPh,clkPol); return Status; }
/** * Tests SPI by echo what was read */ void SPI_TEST() { volatile unsigned char val = 0; SPI_INIT(); while(1) { val = SPI_SLAVE(val); } }
// Short Mosi and MISo // should yield the same result void TEST_SPI(void){ unsigned char Error =0; SPI_INIT(400000); SPI_Toggle_MasterSS(0); while(1){ SPI_Send_Char(0xA5); Error = SPI_Recieve_Char(0x00); printf(" %x ", Error); Error = 0x00; } }
//初始化VS10XX的IO口 void VS_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; //DREQ PC.7 RCC_APB2PeriphClockCmd(VS_DQ_RCC, ENABLE); //使能Px端口时钟 GPIO_InitStructure.GPIO_Pin = VS_DQ_PIN; //PC.7 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //输入 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(VS_DQ_GPIO, &GPIO_InitStructure); //RES PE.0 RCC_APB2PeriphClockCmd(VS_RST_RCC, ENABLE); //使能Px端口时钟 GPIO_InitStructure.GPIO_Pin = VS_RST_PIN; //PE6 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出 GPIO_Init(VS_RST_GPIO, &GPIO_InitStructure); //CS PB.12 RCC_APB2PeriphClockCmd(VS_XCS_RCC, ENABLE); //使能Px端口时钟 GPIO_InitStructure.GPIO_Pin = VS_XCS_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出 GPIO_Init(VS_XCS_GPIO, &GPIO_InitStructure); //XDCS PC.6 RCC_APB2PeriphClockCmd(VS_XDCS_RCC, ENABLE); //使能Px端口时钟 GPIO_InitStructure.GPIO_Pin = VS_XDCS_PIN; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽输出 GPIO_Init(VS_XDCS_GPIO, &GPIO_InitStructure); SPI_INIT(); VS_Sine_Test(); //USART_OUT(DEBUG_USART, "Ram Test:0X%04X\r\n", VS_Ram_Test()); //打印RAM测试结果 VS_HD_Reset(); VS_Soft_Reset(); VS_Restart_Play(); //重启播放 VS_Set_All(); //设置音量等信息 VS_Reset_DecodeTime(); //复位解码时间 VS_SPI_SpeedHigh(); //高速 VS_Set_Vol(250); }
unsigned char SD_INIT(void){ unsigned int count =0; char byte; char i; /// cant get the card to communicate properly // SPI_INIT(40000); // slower speed still problems SPI_Toggle_MasterSS(0); // use master ss // enable CS on SD // SD_INIT_DDR(); SD_CS_LOW(); Timer_Delay_1ms(5); /// wait 1ms // Set DI and CS high and apply 74 clocks SD_CS_HIGH(); /* Init the card in SPI mode by sending at least 72 clocks Data and CS lines must be set to 1*/ for(i = 0; i < 10; i++) SPI_Master_Transmit_Recieve(0xFF); /// send FF pull the data line high SD_CS_LOW(); printf("Successfully Sent Dummy Clocks \r"); /* Init the CS output */ printf("Turning on Chip \r"); Timer_Delay_10ms(100); // DELAY /* Send CMD0 GO_IDLE_STATE - Resets the card puts it in idle state if CS is pulled low and CMD0 is sent the card is put in spi mode*/ SPI_Master_Transmit_Bytes(SD_CMD0, MMC_CMD_SIZE); if (SDRead_Response_R1(0x01)) // MMC responds with a R1 response Idle State bit (0x01) { printf("CMD0 timeout Exiting!\r"); return 1; } //SPI mode, the CRC feature is disabled and the CRC printf("Successfully sent CMD0- device is in idle mode\r"); /* Send some dummy clocks after GO_IDLE_STATE */ SD_CS_HIGH(); SPI_Recieve_Char(0xFF); SD_CS_LOW() printf("send CMD1\r"); /* Send CMD1 SEND_OP_COND until response is 0 */ i = 0xFF; while((SDRead_Response_R1(0xFF) != 0) && (i > 0)) { SPI_Master_Transmit_Bytes(SD_CMD1, MMC_CMD_SIZE); i--; } if (i == 0){ printf("CMD1 timeout\r"); return 2; } /* Send some dummy clocks after GO_IDLE_STATE */ SD_CS_HIGH(); SPI_Recieve_Char(0xFF); SD_CS_LOW() SPI_Master_Transmit_Bytes(SD_CMD16, MMC_CMD_SIZE); if ((SDRead_Response_R1(0xFF)) == 1)printf("CMD16 timeout\r"); else printf("CMD16 Sent 512 bytes \r"); SD_CS_HIGH(); SPI_Recieve_Char(0x00); printf("mmc_init end\r"); return 0; }