Пример #1
0
void Components_Init(void)
{
    /*! DMA_controller Auto initialization start */
    EDMA_DRV_Init(&DMA_controller_State,&DMA_controller_InitConfig0);
    /*! DMA_controller Auto initialization end */


    /*! OLED_SPI Auto initialization start */
    DSPI_DRV_EdmaMasterInit(FSL_OLED_SPI, &OLED_SPI_MasterState, &OLED_SPI_MasterConfig, &OLED_SPI_dmaTcd);
    DSPI_DRV_EdmaMasterConfigureBus(FSL_OLED_SPI, &OLED_SPI_BusConfig, &OLED_SPI_calculatedBaudRate);
    /*! OLED_SPI Auto initialization end */

    /*! FLASH_SPI Auto initialization start */
    DSPI_DRV_EdmaMasterInit(FSL_FLASH_SPI, &FLASH_SPI_MasterState, &FLASH_SPI_MasterConfig, &FLASH_SPI_dmaTcd);
    DSPI_DRV_EdmaMasterConfigureBus(FSL_FLASH_SPI, &FLASH_SPI_BusConfig, &FLASH_SPI_calculatedBaudRate);
    /*! FLASH_SPI Auto initialization end */

    /*! GPIO Auto initialization start */
    GPIO_DRV_Init(NULL,NULL);
    /*! GPIO Auto initialization end */

    /*! KW40_UART Auto initialization start */
    UART_DRV_Init(FSL_KW40_UART,&KW40_UART_State,&KW40_UART_InitConfig0);
    /*! KW40_UART Auto initialization end */
    /*! DEBUG_UART Auto initialization start */
    UART_DRV_Init(FSL_DEBUG_UART,&DEBUG_UART_State,&DEBUG_UART_InitConfig0);
    /*! DEBUG_UART Auto initialization end */
    /*! FS_I2C Auto initialization start */
    I2C_DRV_MasterInit(FSL_FS_I2C, &FS_I2C_MasterState);
    I2C_DRV_MasterSetBaudRate(FSL_FS_I2C, &FS_I2C_MasterConfig);
    /*! FS_I2C Auto initialization end */

    /*! NFS_I2C Auto initialization start */
    I2C_DRV_MasterInit(FSL_NFS_I2C, &NFS_I2C_MasterState);
    I2C_DRV_MasterSetBaudRate(FSL_NFS_I2C, &NFS_I2C_MasterConfig);
    /*! NFS_I2C Auto initialization end */

    /*! PWR_Manager Auto initialization start */
//  POWER_SYS_Init(powerConfigsArr, 2U, NULL , 0U);
    INT_SYS_EnableIRQ(LLWU_IRQn);
    /*! PWR_Manager Auto initialization end */
    /*! CLOCK Auto initialization start */
    RTC_DRV_Init(FSL_CLOCK);
    /*! CLOCK Auto initialization end */

    /*! BATTERY_ADC Auto initialization start */
    ADC16_DRV_Init(FSL_BATTERY_ADC, &BATTERY_ADC_InitConfig);
    ADC16_DRV_ConfigConvChn(FSL_BATTERY_ADC, 0U, &BATTERY_ADC_ChnConfig);
    /*! BATTERY_ADC Auto initialization end */

    /*! sensor_timer Auto initialization start */
    LPTMR_DRV_Init(FSL_SENSOR_TIMER,&sensor_timer_State,&sensor_timer_cfg);
    /*! sensor_timer Auto initialization end */

}
Пример #2
0
void I2cMcuInit(I2c_t *obj, PinNames scl, PinNames sda)
{
    if (obj->I2c->instance < 0 || obj->I2c->instance > I2C_INSTANCE_COUNT) return;

    GpioInit(&obj->Scl, scl, PIN_ALTERNATE_FCT, PIN_OPEN_DRAIN, PIN_PULL_UP, 0);
    GpioInit(&obj->Sda, sda, PIN_ALTERNATE_FCT, PIN_OPEN_DRAIN, PIN_PULL_UP, 0);

    I2C_DRV_MasterInit(obj->I2c->instance, &obj->I2c->state);
}
Пример #3
0
void Components_Init(void)
{
	I2C_DRV_MasterInit(FSL_FS_I2C, &FS_I2C_MasterState);
	I2C_DRV_MasterSetBaudRate(FSL_FS_I2C, &FS_I2C_MasterConfig);

	EDMA_DRV_Init( &DMA_controller_State, &DMA_controller_InitConfig0 );
	DSPI_DRV_EdmaMasterInit(FSL_OLED_SPI, &OLED_SPI_MasterState, &OLED_SPI_MasterConfig, &OLED_SPI_dmaTcd);
	DSPI_DRV_EdmaMasterConfigureBus(FSL_OLED_SPI, &OLED_SPI_BusConfig, &OLED_SPI_calculatedBaudRate);

	OLED_Init( &oledModule, &oledSettings );
}
Пример #4
0
void Components_Init(void)
{

  /*! LED Auto initialization start */
  GPIO_DRV_Init(LED_Config,LED_OutConfig0);
  /*! LED Auto initialization end */
  
  /*! i2c_compS Auto initialization start */
  OSA_InstallIntHandler(I2C0_IRQn, i2c_compS_IRQHandler);
  I2C_DRV_MasterInit(FSL_I2C_COMPS, &i2c_compS_MasterState);
  I2C_DRV_MasterSetBaudRate(FSL_I2C_COMPS, &i2c_gmeter);
  /*! i2c_compS Auto initialization end */
  
}
Пример #5
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;
}
Пример #6
0
/*!
 * @brief main function
 */
int main(void)
{
    uint8_t i;
    uint8_t index, indexChar, value;
    uint8_t cmdBuff[1] = {0xFF};
    uint8_t sendBuff[1] = {0xFF};       // save data sent to i2c slave
    uint8_t receiveBuff[1] = {0xFF};    // save data received from i2c slave

    i2c_master_state_t master;
    i2c_status_t returnValue;

    i2c_device_t slave =
    {
        .address = 0x3A,
        .baudRate_kbps = 100
    };

    hardware_init();

    dbg_uart_init();

    // Configure I2C pins
    configure_i2c_pins(BOARD_I2C_COMM_INSTANCE);

    OSA_Init();

    GPIO_DRV_Init(0, ledPins);

    // Init I2C module
    I2C_DRV_MasterInit(BOARD_I2C_COMM_INSTANCE, &master);

    printf("\r\n====== I2C Master ======\r\n\r\n");

    OSA_TimeDelay(500);
    LED_toggle_master();
    OSA_TimeDelay(500);
    LED_toggle_master();
    OSA_TimeDelay(500);
    LED_toggle_master();
    OSA_TimeDelay(500);
    LED_toggle_master();

    while (1)
    {
        printf("\r\nI2C Master reads values from I2C Slave sub address:\r\n");
        printf("\r\n------------------------------------");
        printf("\r\nSlave Sub Address   |    Character         ");
        printf("\r\n------------------------------------");
        for (i=Subaddress_Index_0; i<Invalid_Subaddress_Index; i++)
        {
            cmdBuff[0] = i;
            returnValue = I2C_DRV_MasterReceiveDataBlocking(
                                                       BOARD_I2C_COMM_INSTANCE,
                                                       &slave,
                                                       cmdBuff,
                                                       1,
                                                       receiveBuff,
                                                       sizeof(receiveBuff),
                                                       500);
            if (returnValue == kStatus_I2C_Success)
            {
                printf("\r\n[%d]                      %c", i, receiveBuff[0]);
            }
            else
            {
                printf("\r\nI2C communication failed, error code: %d", returnValue);
            }

        }
        printf("\r\n------------------------------------");
        printf("\r\n");

        printf("\r\nPlease input Slave sub address and the new character.");

        do
        {
            printf("\r\nSlave Sub Address: ");
            indexChar = getchar();
            putchar(indexChar);

            printf("\r\nInput New Character: ");
            value = getchar();
            putchar(value);

            printf("\n");

            index = (uint8_t)(indexChar - '0');

            if (index >= Invalid_Subaddress_Index)
            {
                printf("\r\nInvalid Sub Address.");
            }
        } while (index >= Invalid_Subaddress_Index);

        cmdBuff[0]  = index;
        sendBuff[0] = value;

        returnValue = I2C_DRV_MasterSendDataBlocking(
                                                    BOARD_I2C_COMM_INSTANCE,
                                                    &slave,
                                                    cmdBuff,
                                                    1,
                                                    sendBuff,
                                                    sizeof(sendBuff),
                                                    500);
        if (returnValue != kStatus_I2C_Success)
        {
            printf("\r\nI2C communication failed, error code: %d", returnValue);
        }
    }
}