Exemplo n.º 1
0
/*Requires Delay after call*/
uint8 MagReadByte(uint8 registerAddress, uint8 *readPtr)
{
	/* Pointer to the register address */
    //uint8 *writePtr = &registerAddress;/* changed writeptr to &registerAddress*/
	uint8 i2c_status = I2C_MasterClearStatus();
	//LCD_ClearDisplay();
	LCD_Position(1,7);
	LCD_PrintInt8(i2c_status);
	
	I2C_MasterClearReadBuf();
	I2C_MasterClearWriteBuf();
	
    /* Start the I2C transmission for a read */
    uint8 status = I2C_MasterWriteBuf(SLAVE_ADDRESS, &registerAddress, 1, I2C_MODE_NO_STOP);
    /*wait for the tranmission to finish */
    while (I2C_MasterStatus() && !I2C_MSTAT_WR_CMPLT){}
    /* Needed because of some bug in the psoc I2C tramission */
    CyDelay(1);
	/* read a byte using I2C */
	//return I2C_MasterReadBuf(SLAVE_ADDRESS, readPtr, 1, I2C_MODE_REPEAT_START);
	
	//or TO ENSURE READ IS COMPLETE BEFORE ADDITIONAL CODE EXECUTED
	status |= I2C_MasterReadBuf(SLAVE_ADDRESS,readPtr , 1, I2C_MODE_REPEAT_START);
	while (I2C_MasterStatus() && !I2C_MSTAT_RD_CMPLT){}
    CyDelay(1); //Needed because of some bug in the psoc I2C tramission
	return status;
}
Exemplo n.º 2
0
void matrix_illuminate ( uint8 row , uint8 col , uint8 color ) {
    uint8 off = 0x00, on = 0x01;
    if (SERIAL) {
        uint8 rows = 0b00000001 << row;
        uint8 reds = 0b00000001;
        uint8 grns = 0b00000001;
        uint8 blus = 0b00000001;
        switch (color) {
            case OFF:     reds   = off;
                          grns   = off;
                          blus   = off; break;
            case RED:     reds <<= col;
                          grns   = off;
                          blus   = off; break;
            case GREEN:   reds   = off;
                          grns <<= col;
                          blus   = off; break;
            case YELLOW:  reds <<= col;
                          grns <<= col;
                          blus   = off; break;
            case BLUE:    reds   = off;
                          grns   = off;
                          blus <<= col; break;
            case MAGENTA: reds <<= col;
                          grns   = off;
                          blus <<= col; break;
            case CYAN:    reds   = off;
                          grns <<= col;
                          blus <<= col; break;
            case WHITE:   reds <<= col;
                          grns <<= col;
                          blus <<= col; break;
            
            default: LCD_UpdateStatus("serial error");
                     LCD_UpdateMessage("color mismatch");
                     LCD_Position(1,14);
                     LCD_PrintInt8(color);
                     while (true);
        }
        
        rows = ~rows;
        reds = ~reds;
        grns = ~grns;
        blus = ~blus;
        
        Colors_Write(off);
        int i;
        for (i=0; i < 8 ;++i) {
            Row_Write(  (rows & (0b10000000 >> i)) ? on : off);
            Red_Write(  (reds & (0b10000000 >> i)) ? on : off);
            Green_Write((grns & (0b10000000 >> i)) ? on : off);
            Blue_Write( (blus & (0b10000000 >> i)) ? on : off);
            
            //generate a rising edge
            Shifter_Write(on);
            Shifter_Write(off);
        }
        Colors_Write(on);
    }
    else {
Exemplo n.º 3
0
// Show shift register contents and flags
void show(void) {
    uint8       i;
    
    LCD_Position(0, 0);
    for (i = 0; i < 8; i++) {
        LCD_PrintInt8(v[i]);
    }
    LCD_Position(1, 0);
    if (SR1_Read() & 1) {
        LCD_PrintString("FULL ");
    } else {
        LCD_PrintString("     ");
    }
    if (SR1_Read() & 2) {
        LCD_PrintString("EMPTY ");
    } else {
        LCD_PrintString("      ");
    }
}
Exemplo n.º 4
0
/**
 * @brief Write multiple bytes of data to the MAG3110 in sequential memory
 * @details User supplies the register that the write will start on. User also supplues a buffer of data to write
 *          to the MAG3110 and the size of the buffer as well.
 *
 * @param firstRegister Register the sequential write will start on
 * @param bufferPtr Pointer that points to the buffer of data to write
 * @param size umber of elements that are in the buffer
 * @return Error status of the function
 */
uint8 MagWriteMultipleBytes(uint8 firstRegister, uint8 *bufferPtr, uint8 size)
{
    /* 	Create a new buffer that has that has the firstRegistsre as first element and the other elements as the data pointed to 
		in bufferPtr */
	uint8 i2c_status = I2C_MasterClearStatus();
	//LCD_ClearDisplay();
	LCD_Position(1,7);
	LCD_PrintInt8(i2c_status);
	I2C_MasterClearReadBuf();
	I2C_MasterClearWriteBuf();
	
    /* Pinter to the write buffer that will be written */
    

    /* Set the first element of the buffer equal to the first register we will write to */
    //*(Global_WritePtr) = firstRegister;
    /* Tranfers the data from the buffer that was passed to the function to the buffer that is to be written */
	//uint8 i = 1;
    //for(i=1;i<=size;i++)
	//{
	//	*(Global_WritePtr+i) = bufferPtr[i-1];
    //}
	
	/* Set the first element of the buffer equal to the first register we will write to */
	uint8 j;
	for(j = size;j>0;j--)
	{
		bufferPtr[j] = bufferPtr[j-1];
	}
	bufferPtr[0] = firstRegister;

    /* Write multiple bytes to the MAG3110 */
    uint8 status = I2C_MasterWriteBuf(SLAVE_ADDRESS, bufferPtr, (size+1), I2C_MODE_COMPLETE_XFER);
    while (I2C_MasterStatus() && !I2C_MSTAT_WR_CMPLT){}
    /* Needed because of some bug in the psoc I2C tramission */
    CyDelay(1);
	//functioncomplete_flag = 1;/*set Flag for write completion*/
	return status;
}
Exemplo n.º 5
0
/* 
 * @brief Write a byte to the MAG3110
 * @details Takes a register address that we are going to write to and a byte of datat that we will write to the register
 *
 * @param registerAddress Address of the register on the MAG3110
 * @param data Byte that will be written to the MAG3110
 *
 * @return Error status of the function
 */
uint8 MagWriteByte(uint8 registerAddress, uint8 value)
{
    //functioncomplete_flag = 0;/*set Flag for function Incomplete*/
	I2C_MasterClearReadBuf();
	I2C_MasterClearWriteBuf();
	uint8 i2c_status = I2C_MasterClearStatus();
	//LCD_ClearDisplay();
	LCD_Position(1,7);
	LCD_PrintInt8(i2c_status);
	
	/* Buffer that holds the data to be written */
    uint8 writeBuffer[2] = {registerAddress, value};
    /* Pointer to the buffer that will be written */
    uint8 *writePtr = writeBuffer;
    /* Write to MAG3110 */
    uint8 status = I2C_MasterWriteBuf(SLAVE_ADDRESS, writePtr, 2, I2C_MODE_COMPLETE_XFER);
	/*Wait for transmission to finish*/
	while (I2C_MasterStatus() && !I2C_MSTAT_WR_CMPLT){}
    CyDelay(1);
	//functioncomplete_flag = 1;/*set Flag for function complete*/
	return status;
}
Exemplo n.º 6
0
/**
 * @brief Read multiple bytes from the MAG3110
 * @details User supplies the register that we are going to read from and the buffer that we are going to place the data 
 *          that we read from the MAG3110. REQUIRES DELAY AFTER CALL
 *      
 * @param registerAddress Address of the first register we are going to read
 * @param readPtr Pointer to the buffer that the data that we read will be placed  
 * @param size Number of bytes that we are going to read from the MAG3110
 * @return Error status of the function
 */
uint8 MagReadMultipleByte(uint8 registerAddress, uint8 *readPtr,uint8 size)
{
	uint8 i2c_status = I2C_MasterClearStatus();
	LCD_Position(1,7);
	LCD_PrintInt8(i2c_status);
	I2C_MasterClearReadBuf();
	I2C_MasterClearWriteBuf();
	
    /* We start by writng the slave address and the register we are going to start the rea from*/
    uint8 status = I2C_MasterWriteBuf(SLAVE_ADDRESS, &registerAddress, 1, I2C_MODE_NO_STOP);
    /*wait for the tranmission to finish */
    while (I2C_MasterStatus() && !I2C_MSTAT_RD_CMPLT){}
    /* Needed because of some bug in the psoc I2C tramission */
    CyDelay(1);
    
	
	/* read data from the MAG I2C */
	//return I2C_MasterReadBuf(SLAVE_ADDRESS,readPtr , size, I2C_MODE_REPEAT_START);
	//or TO ENSURE READ IS COMPLETE BEFORE ADDITIONAL CODE EXECUTED
	status |= I2C_MasterReadBuf(SLAVE_ADDRESS,readPtr , size, I2C_MODE_REPEAT_START);
	while (I2C_MasterStatus() && !I2C_MSTAT_RD_CMPLT){}
    CyDelay(1); //Needed because of some bug in the psoc I2C tramission
	return status;
}
Exemplo n.º 7
0
void main(void){
    unsigned char op = 0xFF; 
    //0xFF is the SPI command for Soft Reset.
       
    //Initialize SPIM Module on the PSoC.
    spiInit(); 
       
    //Start the LCD component.
    LCD_Start();
    LCD_PrintString("SPI Init'd.");
    CyDelay(700);
    LCD_ClearDisplay();
       
    //Send that Soft Reset Command.
    SPI_SEL(0);
        spiTxBuffer(&op,1);
    SPI_SEL(1);
       
    //Wait for the ENC chip to come back.
    CyDelay(1);
    
    LCD_PrintString("ENC Reset.");
    CyDelay(700);
    LCD_ClearDisplay();
       
    /**************************************
    We will now try to turn on the LEDs
    on the Magjack.
    Steps:
    1.Write to the PHLCON register,and turn on the LEDs.
        1.1 Since its a PHY register,Write the address of the PHLCON register to
            into the MIREGADR register.(Which is why we select Bank 2 first
            by writing to ECON1.)
        1.2 Write the lower 8 bits of data to write into the
            MIWRL register.
        1.3 Write the upper 8 bits of data to write into the
            MIWRH register. Writing to this register auto-
            matically begins the MII transaction, so it must
            be written to after MIWRL.
    2.Check the LEDs to see if they light up :-P
    3.Say so on the LCD.
    ************************************************/
       
    //Write Control Register Command for ECON1
    // 010 11111 = 0x5F
    op = 0x5F; 
    SPI_SEL(0);
        spiTxBuffer(&op,1);
            
       //Write 0x02 as we want to select bank 2.            
        op = 0x02; 
        spiTxBuffer(&op,1);
    SPI_SEL(1);
       
    //Write Control Register Command for MIREGADR Register.
    // 010 10100 = 0x54
    op = 0x54;
    SPI_SEL(0);
        spiTxBuffer(&op,1);

        //Select PHLCON Register.
        op = 0x14; 
        spiTxBuffer(&op,1);
    SPI_SEL(1);
       
    //Write Control Register Command for MIWRL Register.
    // 010 10110 = 0x56
    op = 0x56; 
    SPI_SEL(0);
    spiTxBuffer(&op,1);
       
    //Turn on LEDB.
    op = 0x80; 
    spiTxBuffer(&op,1);
    SPI_SEL(1);
    
    LCD_PrintString("LEDB ON.");
    CyDelay(700);
    LCD_ClearDisplay();
    
    //Write Control Register Command for MIWRL Register.
    // 010 10111 = 0x57
    op = 0x57; //Write to MIWRH Reg
    SPI_SEL(0);
    spiTxBuffer(&op,1);
       
    //Turn on LEDA.
    op = 0x38; 
    spiTxBuffer(&op,1);
    SPI_SEL(1);

    LCD_PrintString("LEDA ON.");
    CyDelay(700);
    LCD_ClearDisplay();

    /**************************************
    We will now try to read the Silicon Revision.
    Steps:
    1.Read from EREVID Register
        1.1 Write to ECON 1 to Select Bank 3
        1.2 Read the EREVID Register.
        (Mine gave 0x04)
    **************************************/
        op = 0x5F; //Write to ECON1 Reg
        SPI_SEL(0);
            spiTxBuffer(&op,1);
        op = 0x03; //Write 3 as we want to select bank 3.
            spiTxBuffer(&op,1);
        SPI_SEL(1);
        
        op = 0x12; //Read EREVID Register
        SPI_SEL(0);
            spiTxBuffer(&op,1);
            spiRxBuffer(&op,1);
        SPI_SEL(1);
        
        LCD_PrintString("Silicon Revision");
        LCD_Position(1,0);
        LCD_PrintInt8(op);
    for(;;);
}
Exemplo n.º 8
0
int main()
{    
	CyGlobalIntEnable; /* Uncomment this line to enable global interrupts. */
	XBee_UART_Start();
	I2C_Start();
	LCD_Start();
	
	//	INITIALIZE VALUES
	Command_Received = 0;
	MAG_DataRdy_Flag = 0;
	ReadyForCommand_Flag = 1;
	IncomingData_Flag = 0;
	StatusError_Flag = 0;
	//WaitForDataRead_Flag = 0;
	Command_Buffer = 0;
	
	// INITIALIZE ISRs
	InitXBee_Isr();
	//InitINT1_Isr(); // IF INT1 TRIGGERS WHEN NOT IN ACTIVE MODE, MOVE INITIATION CODE FOR SETTING ACTIVE.
	//INT1_isr_Start();
	
	XBee_UART_ClearRxBuffer();
	XBee_UART_ClearTxBuffer();
	CyDelay(2000);
	LCD_ClearDisplay();
	LCD_Position(0,0);
	LCD_PrintString("MAG DRIVER:");
	LCD_Position(1,0);
	LCD_PrintString("[ERR]");
	LCD_Position(1,7);
	LCD_PrintString("[I2C]");

	uint8 status = 0;
	status = SetCtrlReg1Default();
	status |= SetCtrlReg2Default();
	if(status !=0)
	{
		LCD_ClearDisplay();
		LCD_Position(0,0);
		LCD_PrintInt8(status);
		status = 0;
	}
	uint8 pin_status = 0;
	    
    for(;;)
    {
		pin_status = INT1_Pin_Read();
		pin_status |= MAG_DataRdy_Flag;
		if(pin_status)
		{
			MAG_DataRdy_Flag = pin_status;
			if(ReadyForCommand_Flag!=0)
			{
				Command_Received = CMD_I_RM_MAGDATA;
				ReadyForCommand_Flag = 0;
			}	
		}

		if(Command_Received != 0)
		{
			LCD_ClearDisplay();
			//XBee_UART_ClearTxBuffer();
			//XBee_UART_ClearRxBuffer();			
			switch (Command_Received){
				case CMD_I_RM_MAGDATA: // CMD_I_RM_MAGDATA = 34
				{
					status = ReadMagData(Global_ReadPtr);
					if(status == 0)
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);
						//LED_out_Write(0);
						CyDelay(500);
						XBee_UART_PutArray(Global_ReadPtr,ARRAY_SIZE_MAG_DATA);
						CyDelay(1000);					
						//WaitForDataRead_Flag = 0;
						MAG_DataRdy_Flag = 0;
						if(Command_Buffer!=0)
						{
							Command_Received = Command_Buffer;
							Command_Buffer = 0;
							//ReadyForCommand_Flag = 0; //Dont toggle flag
						}
						else
						{
							Command_Received = 0;
							ReadyForCommand_Flag = 1;
							LED_out_Write(0);
						}
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;						
					}
				}
				break;
				
				case CMD_I_WM_OFFSET_ALL:// CMD_I_WM_OFFSET_ALL = 1
				{
					if(IncomingData_Flag == 0) // IF THE OFFSET DATA TO WRITE HAS BEEN RECEIVED...
					{
						status = WriteOffsetCorrection(DataInPtr_Global);
						if(status == 0)
						{
							CyDelay(500);
							XBee_UART_PutChar(Command_Received); //Sends confirmation TWICE. Once after receiving CMD, and again after finishing WRITE
							LED_out_Write(0);
							Command_Received = 0;
							IncomingData_Flag = 0;
							ReadyForCommand_Flag = 1;
						}					
						else 
						{
							// will result is a halt of CMD processing and leaves LED lit (visual error signal)
							LCD_Position(1,0);
							LCD_PrintString("E:STA");
							CyDelay(1000);		
							StatusError_Flag = 1;
						}
					}
				}
				break;
				
				case CMD_I_RS_CTRL1://CMD_I_RS_CTRL1=35
				{
					status = ReadCtrlReg1(Global_ReadPtr);
					if(status == 0)
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);
						LED_out_Write(0);
						CyDelay(500);
						XBee_UART_PutChar(Global_ReadBuffer[0]); // Send Read Value
						Command_Received = 0;
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1;
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}				
				}
				break;
				
				case CMD_I_RS_CTRL2://CMD_I_RS_CTRL2 = 36
				{
					status = ReadCtrlReg2(Global_ReadPtr);
					if(status == 0)
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);
						LED_out_Write(0);
						CyDelay(500);
						XBee_UART_PutChar(Global_ReadBuffer[0]); // Send Read Value
						Command_Received = 0;
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1;
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}	
				}
				break;
				
				case CMD_I_RS_DRSTATUS://CMD_I_RS_DRSTATUS = 37
				{
					status = ReadDrStatus(Global_ReadPtr);
					if(status == 0)
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);
						LED_out_Write(0);
						CyDelay(500);
						XBee_UART_PutChar(Global_ReadBuffer[0]); // Send Read Value
						Command_Received = 0;
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1;
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}	
				}
				break;
				
				case CMD_I_RS_SYSMOD:// CMD_I_RS_SYSMOD = 38
				{
					status = ReadSysMod(Global_ReadPtr);
					if(status == 0)
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);
						LED_out_Write(0);
						CyDelay(500);
						XBee_UART_PutChar(Global_ReadBuffer[0]);
						Command_Received = 0;
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1;
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}
				}
				break;
				
				case CMD_I_RS_DIETEMP: // CMD_I_RS_DIETEMP = 39
				{
					status = ReadDieTemp(Global_ReadPtr);
					if(status == 0)
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);
						LED_out_Write(0);
						CyDelay(500);
						XBee_UART_PutChar(Global_ReadBuffer[0]);
						Command_Received = 0;
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1;
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}
				}
				break;
				
				case CMD_I_RS_WHOAMI: // CMD_I_RS_WHOAMI = 40
				{
					status = ReadWhoAmI(Global_ReadPtr);
					if(status == 0)
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);
						LED_out_Write(0);
						CyDelay(500);
						XBee_UART_PutChar(Global_ReadBuffer[0]);
						Command_Received = 0;
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1;
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}
				}
				break;
				
				case CMD_I_WS_CTRL1_DEFAULT: // CMD_I_WS_CTRL1_DEFAULT = 41
				{
					status = SetCtrlReg1Default();
					if(status == 0) //if the write was a success
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation
						LED_out_Write(0); //Turns off LED
						Command_Received = 0; //Clears the Command
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1; // Sets state as READY for next command
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}
				}
				break;
				
				case CMD_I_WS_CTRL1_MODSTANDBY: // CMD_I_WS_CTRL1_MODSTANDBY = 42
				{
					status = SetStandbyMode();
					if(status == 0) //if the write was a success
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation
						LED_out_Write(0); //Turns off LED
						Command_Received = 0; //Clears the Command
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1; // Sets state as READY for next command
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}
				}
				break;
				
				case CMD_I_WS_CTRL1_MODSINGLE: // CMD_I_WS_CTRL1_MODSINGLE = 43
				{
					status = SetSingleMeasurmentMode();
					if(status == 0) //if the write was a success
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation
						LED_out_Write(0); //Turns off LED
						Command_Received = 0; //Clears the Command
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1; // Sets state as READY for next command
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}
				}
				break;
				
				//IF INT1 CONTINUES TO TRIGGER WHEN NOT IT ACTIVE MODE, DEACTIVATE/ACTIVATE ISR WHEN CHANGING MODES				
				case CMD_I_WS_CTRL1_MODACTIVE: // CMD_I_WS_CTRL1_MODACTIVE = 44
				{
					status = SetContinuousMode();
					if(status == 0) //if the write was a success
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation
						LED_out_Write(0); //Turns off LED
						Command_Received = 0; //Clears the Command
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1; // Sets state as READY for next command
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}
				}
				break;
				
				case CMD_I_WS_CTRL1_MODTRIGGER: // CMD_I_WS_CTRL1_MODTRIGGER = 45
				{
					status = SetTriggerMeasurmentMode();
					if(status == 0) //if the write was a success
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation
						LED_out_Write(0); //Turns off LED
						Command_Received = 0; //Clears the Command
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1; // Sets state as READY for next command
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}
				}
				break;
				
				case CMD_I_WS_CTRL1_ENFAST: // CMD_I_WS_CTRL1_ENFAST = 46
				{
					status = SetFastReadOn();
					if(status == 0) //if the write was a success
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation
						LED_out_Write(0); //Turns off LED
						Command_Received = 0; //Clears the Command
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1; // Sets state as READY for next command
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}
				}
				break;
				
				case CMD_I_WS_CTRL1_NENFAST: //CMD_I_WS_CTRL1_NENFAST = 47
				{
					status = SetFastReadOff();
					if(status == 0) //if the write was a success
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation
						LED_out_Write(0); //Turns off LED
						Command_Received = 0; //Clears the Command
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1; // Sets state as READY for next command
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}
				}
				break;
				
				case CMD_I_WS_CTRL2_DEFAULT: //CMD_I_WS_CTRL2_DEFAULT = 48
				{
					status = SetCtrlReg2Default();
					if(status == 0) //if the write was a success
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation
						LED_out_Write(0); //Turns off LED
						Command_Received = 0; //Clears the Command
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1; // Sets state as READY for next command
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}
				}
				break;
				
				case CMD_I_WS_CTRL2_ENAUTORESET: // CMD_I_WS_CTRL2_ENAUTORESET = 49
				{
					status = SetAutoResetOn();
					if(status == 0) //if the write was a success
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation
						LED_out_Write(0); //Turns off LED
						Command_Received = 0; //Clears the Command
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1; // Sets state as READY for next command
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}
				}
				break;
				
				case CMD_I_WS_CTRL2_NENAUTORESET: // CMD_I_WS_CTRL2_NENAUTORESET = 50
				{
					status = SetAutoResetOff();
					if(status == 0) //if the write was a success
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation
						LED_out_Write(0); //Turns off LED
						Command_Received = 0; //Clears the Command
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1; // Sets state as READY for next command
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}
				}
				break;
				
				case CMD_I_WS_CTRL2_ENUSEROFFSET: // CMD_I_WS_CTRL2_ENUSEROFFSET = 51
				{
					status = SetUserCorrectedData();
					if(status == 0) //if the write was a success
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation
						LED_out_Write(0); //Turns off LED
						Command_Received = 0; //Clears the Command
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1; // Sets state as READY for next command
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;						
					}
				}
				break;
				
				case CMD_I_WS_CTRL2_NENUSEROFFSET: // CMD_I_WS_CTRL2_NENUSEROFFSET = 52
				{
					status = SetRawData();
					if(status == 0) //if the write was a success
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation
						LED_out_Write(0); //Turns off LED
						Command_Received = 0; //Clears the Command
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1; // Sets state as READY for next command
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						StatusError_Flag = 1;
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;						
					}
				}
				break;				
				
				case CMD_I_WS_CTRL2_RESETMAG: // CMD_I_WS_CTRL2_RESETMAG = 53
				{
					status = ResetMag();
					if(status == 0) //if the write was a success
					{
						CyDelay(1000); //LET MAGNETOMETER RESET PROCEDURE FINISH
						XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation
						LED_out_Write(0); //Turns off LED
						Command_Received = 0; //Clears the Command
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1; // Sets state as READY for next command
					}					
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						//LCD_ClearDisplay();
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}
				}
				break;
				
				case CMD_I_RESET_ALL://54
				{
					// RESET I2C
					uint8 i2c_status = I2C_MasterClearStatus();
					//LCD_ClearDisplay();
					LCD_Position(1,7);
					LCD_PrintInt8(i2c_status);
					
					I2C_MasterClearReadBuf();
					I2C_MasterClearWriteBuf();
					
					// Reset MAG CTRL REGISTERS
					status = SetCtrlReg1Default();
					status |= SetCtrlReg2Default();
					if(status == 0) //if the write was a success
					{
						CyDelay(500);
						XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation
						LED_out_Write(0); //Turns off LED
						Command_Received = 0; //Clears the Command
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1; // Sets state as READY for next command
					}
					else 
					{
						// will result is a halt of CMD processing and leaves LED lit (visual error signal)
						//LCD_ClearDisplay();
						LCD_Position(1,0);
						LCD_PrintString("E:STA");
						CyDelay(1000);		
						StatusError_Flag = 1;
					}					
					
				}
				break;
				
				default: //handles Set Sampling/Data rate CMDs, and Out of range errors
				{
					if((Command_Received >= (STARTOFRANGE_SET_SAMPLING_AND_RATE))&&(Command_Received < (STARTOFRANGE_SET_SAMPLING_AND_RATE + RANGESIZE_SET_SAMPLING_AND_RATE)))
					{
						uint8 offset = Command_Received-STARTOFRANGE_SET_SAMPLING_AND_RATE;
						offset *=DELTAVALS_SET_SAMP_AND_RATE;
						status = SetOverSampleAndDataRate(offset);
						if(status == 0) //if the write was a success
						{
							CyDelay(500);
							XBee_UART_PutChar(Command_Received);//Returns command received from MATLAB as confirmation
							LED_out_Write(0); //Turns off LED
							Command_Received = 0; //Clears the Command
							IncomingData_Flag = 0;
							ReadyForCommand_Flag = 1; // Sets state as READY for next command
						}		
						else 
						{
							// will result is a halt of CMD processing and leaves LED lit (visual error signal)
							StatusError_Flag = 1;
							//LCD_ClearDisplay();
							LCD_Position(1,0);
							LCD_PrintString("E:STA");
							CyDelay(1000);
						}
					}
					else // ERROR: CMD VALUE OUT OF RANGE (executed if not a CMD to set sampling/data rate)
					{
						//CLEAR EVERYTHING
						XBee_UART_ClearTxBuffer();
						XBee_UART_ClearRxBuffer();
						I2C_MasterClearReadBuf();
						I2C_MasterClearWriteBuf();

						Command_Received = 0; //Clears the Command
						IncomingData_Flag = 0;
						ReadyForCommand_Flag = 1; // Sets state as READY for next command						
						XBee_UART_PutChar(CMD_O_CMDVALUEOUTOFRANGE); //Send error msg
						//LCD_ClearDisplay();
						LCD_Position(1,0);
						LCD_PrintString("E:RAN");
						CyDelay(1000);
						LED_out_Write(0); //Turns off LED
					}
				}			
			} //END OF SWITCH-CASE
		}//end of IF statement encasing switch-case
		
		/*else // if(Command_Received == 0)
		{
			if((MAG_DataRdy_Flag==1) && (WaitForDataRead_Flag==0))
			{
				//May change CMD_O_MAGDATARDY to simply be the same as CMD_I_RM_MAGDATA.
				//XBee_UART_ClearTxBuffer();
				//LCD_ClearDisplay();
				LCD_Position(1,0);
				LCD_PrintString("DRDY2");
				XBee_UART_PutChar(CMD_O_MAGDATARDY);// CMD_O_MAGDATARDY = 55
				WaitForDataRead_Flag = 1; //Prevents constant resending of notification to MATLAB
				INT1_isr_Disable();
			}
		}*/
	}//END OF FOR LOOP	
		
}//END OF MAIN