Example #1
0
void TIM3_IRQHandler (void)
{
    TIM_ClearITPendingBit (TIM3 , TIM_IT_Update );
    
    dataX = mySPI_GetData(OutX);
    dataY = mySPI_GetData(OutY);
    dataZ = mySPI_GetData(OutZ);
    
    out[0] = '\0';
    strcpy(out,"X=");
    tmp[0] = '\0';
    itoa(tmp, 'd', dataX);
    strcat(out, tmp);
    strcat(out, ",Y=");
    tmp[0] = '\0';
    itoa(tmp, 'd', dataY);
    strcat(out, tmp);
    strcat(out, ",Z=");
    tmp[0] = '\0';
    itoa(tmp, 'd', dataZ); 
    strcat(out, tmp);
    strcat(out, "\r\n");
    uart_write(myUSART, out, strlen(out));
}
Example #2
0
/////////////////////////////////////////////
// http://www.lxtronic.com/index.php/basic-spi-simple-read-write
/////////////////////////////////////////////
void spiTestMems () 
{

	csInit ();
	spiInit(SPI1);

	int8_t data;

	mySPI_SendData(0x20, 0xC0); //LIS302D Config

	while(1)
 	{
		data = mySPI_GetData(0x29);
	}

}
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