예제 #1
0
파일: main.c 프로젝트: danghuutoan/template
int main(void)
{
    uint8_t tmp;

    InitFifo();
    USART_Config();
    LED_Init();
//    I2C_Configuration();
    Systick_Init();
    mySPI_Init();
    //spi();
    //Delay(1000);
    printf("init SPI test \n\r");
  SPI_send(0x23, 0xc9);                         // resetting the accelerometer internal circuit
  SPI_send(0x20, 0x67);                         // 100Hz data update rate, block data update disable, x/y/z enabled 
  SPI_send(0x24, 0x20);                         // Anti aliasing filter bandwidth 800Hz, 16G (very sensitive), no self-test, 4-wire interface
  SPI_send(0x10, 0x00);                         // Output(X) = Measurement(X) - OFFSET(X) * 32;
  SPI_send(0x11, 0x00);                         // Output(Y) = Measurement(Y) - OFFSET(Y) * 32;
  SPI_send(0x12, 0x00);                         // Output(Z) = Measurement(Z) - OFFSET(Z) * 32;
  while (1)
  {

      //tmp = SPI_read(0x28);
      //printf("x : %x \n\r",tmp);
        tmp = SPI_read(0x29);
      printf("x : %x \n\r",tmp);
      Delay(1000);
  }
}
예제 #2
0
파일: main.c 프로젝트: ahmedjafri/EE478
int main(void) {
	init();

        currentWriteBuffer = mp3_data;
        currentReadBuffer = mp3_data2;
        
        mySPI_Init();                           //Init SPI for comm with Pi
        
        //initialize SPI rx buffer counter
        rxIndex = 0;
        
        
        /* Enable the Rx buffer not empty interrupt */
        SPI_I2S_ITConfig(SPI1, SPI_I2S_IT_RXNE, ENABLE);
        
        /* send initial pulse for RPi to send data*/
        GPIO_ToggleBits(GPIOD,  GPIO_Pin_11);
        //sending end of pulse
        if (SPI_I2S_GetITStatus(SPI1, SPI_I2S_IT_RXNE) != SET)
        {
          GPIO_ToggleBits(GPIOD,  GPIO_Pin_11);
        }
        
        //wait until data buffer loaded first time (change?)
        while (!dataRxComplete) 
        {
            dataRxComplete = dataRxComplete;
        }
        
        //rxIndex = 0;                    //reset rxIndex (do in interrupt?)
        dataRxComplete = 0;
        
        flipBuffers();
        
	hMP3Decoder = MP3InitDecoder();
                
        //Send need more data GPIO signal
        
	InitializeAudio(Audio44100HzSettings);
	SetAudioVolume(0xCF);
        PlayAudioWithCallback(AudioCallback, 0);
        
        
	while(1) { 
          
//                while(!dataRxComplete) 
//                {
//                     dataRxComplete = dataRxComplete;        
//                }
//                dataRxComplete = 0;
//                
//                //flip buffers
//                char *tempBuffer = currentReadBuffer;
//                currentReadBuffer = currentWriteBuffer;
//                currentWriteBuffer = tempBuffer;
//                
//                
//                GPIO_ToggleBits(GPIOD,  GPIO_Pin_11);
//                GPIO_ToggleBits(GPIOD,  GPIO_Pin_11);
              
	}
}
예제 #3
0
int main(void) {
///////// Initial Portion /////////////////////////
		init_USART1(460800); // initialize USART1 @ 9600 baud
		SystemCoreClockUpdate();                      /* Get Core Clock Frequency   */
		if (SysTick_Config(SystemCoreClock / 1000000)) { /* SysTick 1 micro sec interrupts  */
			while (1);                                  /* Capture error              */
		}
		USART_puts(USART1, "START !"); // just send a message to indicate that it works
		USART_puts(USART1, " \r \n");			// new line
		//Init GPIO for Leds on board and button input
		init_GPIO();
	
		//Init SPI1
		mySPI_Init();
		
		//Delay for all periferals to be ready
		Delay(1000000);							//Delay 1s for cap to be charged
	//	mySPI_SendByte(0x11);  //SDATAC
		//mySPI_Send3Byte(0x20,0x00,0x00);
		
		//Issue Reset Pulse for ADS1299
		GPIO_ResetBits(GPIOD, GPIO_Pin_2);
		Delay(5); 																			//Delay couples of clock cycles for ADS to read the signal
		GPIO_SetBits(GPIOD, GPIO_Pin_2);								// Complete reset Pulse
		Delay(18);																			//Delay at least 18 clock cycles
		
		//Send stop command for ADS1299
		/*Put CS line down
		send out command (stop command) SDATAC = 0x11,
		delay 1 micro seccond;
		put CS line up again*/
		mySPI_SendByte(0x11);  //SDATAC
		Delay(10000);
		//¾WREG CONFIG3 E0h
		// mySPI_SendData(0x43); //Configure register
		mySPI_Send3Byte(0x43,0x00,0xE1);								//config3 ENABLE internal reference
		mySPI_Send3Byte(0x41,0x00,0xD6);								// Config1 noi daisy chain; output data rate 250sps(F/4096)			
		mySPI_Send3Byte(0x42,0x00,0xC0);								//Config 2: test source externa, keep all as default
		
		//Write to 8 channel open the shorted
		mySPI_Send3Byte(0x45,0x00,0x00);								//collecting data for channel 1-4
		mySPI_Send3Byte(0x46,0x00,0x00);	
		mySPI_Send3Byte(0x47,0x00,0x00);	
		mySPI_Send3Byte(0x48,0x00,0x00);	
				

	
	
	mySPI_Send3Byte(0x20,0x00,0x00);
		
		switch (getIDval & 0x1F ) { //least significant bits reports channels
          case  0x10: //16
            gMaxChan = 4; //ads1294
            break;
          case 0x11: //17
            gMaxChan = 6; //ads1296
            break; 
          case 0x12: //18
            gMaxChan = 8; //ads1298
            break;
          case 0x1E: //30
            gMaxChan = 8; //ads1299
						USART_puts(USART1, "ADS1299 Hooray!");	
					break;
          default: 
            gMaxChan = 0;
		}
		
		
		readRegister(18,0);												// Read all register from address 0
	
	
		//Start conversation. Set start pin to 1 
		GPIO_SetBits(GPIOD, GPIO_Pin_0);
		
			// Asking for data to send continueously 
		mySPI_SendByte(0x10);  //SDATAC begin to read data
		
	/////////////////- Loop - ////////////////////////////////////
 while (1){
    uint8_t i =0;
     // You can do whatever you want in here
		/*
		USART_puts(USART1, "Init 2 complete! Hello World! \r \n"); // just send a message to indicate that it works
				
		//GPIO_ToggleBits(GPIOD, GPIO_Pin_15 | GPIO_Pin_14 | GPIO_Pin_13| GPIO_Pin_12 );
		GPIO_ToggleBits(GPIOD, GPIO_Pin_12 ); //Test Leds on board
		Delay(200);
		GPIO_ToggleBits(GPIOD, GPIO_Pin_13 ); //Test Leds on board
		Delay(200);
		GPIO_ToggleBits(GPIOD, GPIO_Pin_14 ); //Test Leds on board
		Delay(1000);
     */
	//	GPIO_ToggleBits(GPIOD, GPIO_Pin_12 ); //Test Leds on board

	 
	 if(!(GPIO_ReadInputData(GPIOD) &  GPIO_Pin_1)){            //Read state of D1 (DRDY signal). Start new process if it is 0
		for( i=0; i<9; i++){
		char strADS[50];	
		 getdata = mySPI_GetData(0x00);
		 		// regAddress = (0x20 | i);
				// getDataSPI = mySPI_Send3Byte((0x20 | i),0x00,0x00);								//Increase to required address from the base address;
			if( i==2){																																	//Read 1 register at a time
		 if (getdata > 0x007FFFFF) //Convert minus data
		 {
			getdata = 0xFFFFFF - getdata;
			getdata = getdata/19373;
		//snprintf(strADS, 50, "Channel %d		Val: %X \r \n", i, getdata);		//convert int to string
		 snprintf(strADS, 50, "E0,%d\n",getdata);		//convert int to string
		 USART_puts(USART1, strADS);					//pirnt the address in string format
		 }
			else{ 
		getdata = getdata/19373;
		//snprintf(strADS, 50, "Channel %d		Val: %X \r \n", i, getdata);		//convert int to string
		 snprintf(strADS, 50, "E0,%d\n",getdata);		//convert int to string
		USART_puts(USART1, strADS);					//pirnt the address in string format
			}
			}
			
		}
		//Delay(50000);
  } //if
	
	
}// while (1)
	 
//////////////////////////////////////////////////////////	
} //main