예제 #1
0
void I2cMcuDeInit(I2c_t *obj)
{
    I2C_DRV_MasterDeinit(obj->I2c->instance);

    GpioInit(&obj->Scl, obj->Scl.pin, PIN_ANALOGIC, PIN_PUSH_PULL, PIN_NO_PULL, 0);
    GpioInit(&obj->Sda, obj->Sda.pin, PIN_ANALOGIC, PIN_PUSH_PULL, PIN_NO_PULL, 0);
}
예제 #2
0
//void UART1_IRQHandler(void)
//{
//	UART_DRV_IRQHandler(1);
//}
int main(void)
{


	//Simple UART1

	//	 // Init hardware
	//	uart_state_t uartState1; // user provides memory for the driver state structure
	//	uart_user_config_t uartConfig1;
	//
	//	hardware_init();
	//	configure_uart_pins(0);
	//
	//
	//	 OSA_Init();
	//
	//
	//	uartConfig1.baudRate = 9600;
	//	uartConfig1.bitCountPerChar = kUart8BitsPerChar;
	//	uartConfig1.parityMode = kUartParityDisabled;
	//	uartConfig1.stopBitCount = kUartOneStopBit;
	//
	//PRINTF("Just to init Uart\r");
	//	UART_DRV_Init(1,  &uartState1, &uartConfig1);
	//	PRINTF("Uart initilized\n\r");
	//
	//	while(1){
	//		PRINTF("About to send data\n\r");
	//UART_DRV_SendDataBlocking(1, AT, sizeof(AT),16000u); // function
	////	UART_DRV_ReceiveDataBlocking(1, &TXBUFF, 2,16000); // function
	////	 PRINTF("\n\rWho am i register value is: %01X", TXBUFF[0]);
	//
	//	//PRINTF()
	//	PRINTF("Tried to sent some\n");
	//
	//	}

	//Accu init
    i2c_master_state_t master;
    i2c_device_t device =
    {
      .address = 0x1DU,
      .baudRate_kbps = 400   // 400 Kbps
    };
    hardware_init();
    UART2_config(9600);
    enable_UART2_receive_interrupt();
    i2cinitreg();

    // Initialize OSA
    OSA_Init();

    // Initialize i2c master
    I2C_DRV_MasterInit(I2C_INSTANCE_0, &master);
    PRINTF("\r\n=INIT\r\n");
    I2C_DRV_MasterReceiveDataBlocking(I2C_INSTANCE_0, &device,WHO_AM_I, 1, rxBuff, 1, 1000);
           //Prints out values in recived register
           PRINTF("\n\rWho am i register value is: %01X", rxBuff[0]);

    configureAccuAndMag(device);

    PRINTF("\r\n==================== I2C MASTER BLOCKING ===================\r\n");
    PRINTF("\r\n1. Master checks who am i register\
    \r\n2. Master configures accelerometer and magnetometer\
    \r\n3. Takes 200 samples, average them and displays results\r\n");
    PRINTF("\r\n============================================================\r\n\n");

    PRINTF("Press any key to start transfer:\r\n\n");
    GETCHAR();


     while(1){

    	 x = 0;
    	 y = 0;
    	 z = 0;
    	 for(count = 0; count < 200; count++){
    		 I2C_DRV_MasterReceiveDataBlocking(I2C_INSTANCE_0, &device,READ_DATA, 1, rxBuff, 13, 1000);

    		     	 x += (int16_t)(((rxBuff[1] << 8) | rxBuff[2]))>> 2;
    		     	 y += (int16_t)(((rxBuff[3] << 8) | rxBuff[4]))>> 2;
    		     	 z += (int16_t)(((rxBuff[5] << 8) | rxBuff[6]))>> 2;
    	 }
    	 x = x/200;
    	 y = y/200;
    	 getWhere(x,y);
     }

    PRINTF("\r\n==================== I2C MASTER FINISH =================== \r\n");

    // Deinit i2c
    I2C_DRV_MasterDeinit(0);

    return 0;
}

///////////////////////////////////////////////////////////////////////////////
// Pin configure
///////////////////////////////////////////////////////////////////////////////
void i2cinitreg(){
    PORTE_PCR24 |= (0x05u)<<8 | 0x03u;
    PORTE_PCR25 |= (0x05u)<<8 | 0x03u;
}